Skip to content

Commit

Permalink
Rake task for filling in content_id column
Browse files Browse the repository at this point in the history
  • Loading branch information
unoduetre committed Jul 25, 2024
1 parent 6756815 commit 7e1a7dd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/tasks/fill_in_content_id_in_list_items.rake
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

0 comments on commit 7e1a7dd

Please sign in to comment.