-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rake task for filling in content_id column
- Loading branch information
Showing
1 changed file
with
15 additions
and
0 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,15 @@ | ||
desc "Fill in content ids in list items after adding content_id database column." | ||
task fill_in_content_id_in_list_items: :environment do | ||
ListItem.find_each do |list_item| | ||
next if list_item.content_id.present? | ||
|
||
base_path = list_item.base_path | ||
list_item.content_id = list_item.list.tag.tagged_document_for_base_path(base_path)&.content_id | ||
|
||
unless list_item.content_id.present? && list_item.save | ||
puts "Could not set content_id of the following list item: #{list_item.id} #{list_item.base_path} #{list_item.title}" | ||
end | ||
rescue StandardError => e | ||
puts "Exception #{e} raised when trying to set content_id of the following list item: #{list_item}" | ||
end | ||
end |