Skip to content

Commit

Permalink
add methods to delete/recreate subsets
Browse files Browse the repository at this point in the history
  • Loading branch information
bkiahstroud committed Apr 23, 2024
1 parent 2d09bca commit b5ff103
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/services/ams/missing_instantiations_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,41 @@ def audit_duplicate_xml_files
end
end

def destroy_assets(subset_path)
xml_files = Dir.glob(subset_path.join('*.xml'))
asset_ids = xml_files.map { |f| "cpb-aacip-#{File.basename(f).sub('.xml', '')}" }

begin
AMS::AssetDestroyer.new(asset_ids: asset_ids, user_email: 'wgbh_admin@wgbh-mla.org').destroy
rescue => e
logger.error "Error destroying Assets. See asset_destroyer.log (#{e.class} - #{e.message})"
end
end

def create_subset_importers
subset_paths = Dir.glob(Rails.root.join('tmp', 'imports', 'i16-subset*'))
desired_parser_field_attrs = %w[
record_element
import_type
visibility
rights_statement
override_rights_statement
file_style
import_file_path
]

subset_paths.each do |path|
base_imp = Bulkrax::Importer.find_by(name: 'AMS1Importer_0-10000')
imp = base_imp.dup

imp.name = File.basename(path)
imp.parser_fields = base_imp.parser_fields.slice(*desired_parser_field_attrs)
imp.parser_fields['import_file_path'] = path.to_s

imp.save!
end
end

private

def map_asset_id_to_inst_ids(xml_file)
Expand Down

0 comments on commit b5ff103

Please sign in to comment.