-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previous rake task does not fix the data. If there are draft assets in the chain of replacements, it will not work.
- Loading branch information
1 parent
e2dfc17
commit 826384f
Showing
3 changed files
with
75 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
desc "Identify and update corresponding replacement asset variant" | ||
task :fix_asset_variant_replacement, %i[csv_path] => :environment do |_, args| | ||
csv_path = args[:csv_path] | ||
|
||
CSV.foreach(csv_path, headers: false) do |row| | ||
attachment_data_id = row[0] | ||
asset_manager_id = row[1] | ||
variant = row[2] | ||
|
||
attachment_data = AttachmentData.find(attachment_data_id) | ||
|
||
unless attachment_data.replaced? | ||
puts "Attachment Data ID: #{attachment_data.id}, Asset ID: #{asset_manager_id} - SKIPPED. No replacement found." | ||
next | ||
end | ||
|
||
if attachment_data.deleted? | ||
puts "Attachment Data ID: #{attachment_data.id}, Asset ID: #{asset_manager_id} - SKIPPED. Attachment data is deleted." | ||
next | ||
end | ||
|
||
replacement_id = attachment_data.replaced_by_id | ||
replacement_data = nil | ||
|
||
until replacement_id.nil? | ||
replacement_data = AttachmentData.find(replacement_id) | ||
replacement_id = replacement_data.replaced_by_id | ||
end | ||
|
||
begin | ||
replacement_id = replacement_data.assets.where(variant:).first.asset_manager_id | ||
AssetManager::AssetUpdater.call(asset_manager_id, { "replacement_id" => replacement_id }) | ||
|
||
puts "Attachment Data ID: #{attachment_data_id}, Asset ID: #{asset_manager_id}, Variant: #{variant}, Replacement ID: #{replacement_id} - OK" | ||
rescue StandardError => e | ||
puts "Attachment Data ID: #{attachment_data_id}, Asset ID #{asset_manager_id} - ERROR, message: #{e.message}" | ||
end | ||
end | ||
end |
21 changes: 0 additions & 21 deletions
21
lib/tasks/attachments/fix_missing_asset_replacement_links.rake
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters