Skip to content
Browse files

Rename two section slugs rake task

Last minute request to change slug for two sections.
  • Loading branch information...
1 parent 29f1892 commit 336415a67c2d4ba18b7c34612ee01231d76cbfa7 Mazz Mosley committed
Showing with 30 additions and 0 deletions.
  1. +30 −0 lib/tasks/rename_slugs.rake
View
30 lib/tasks/rename_slugs.rake
@@ -0,0 +1,30 @@
+# This is a one time run script to change the slugs of two categories
+# and update all artefacts that have been tagged with those sections
+# TODO: Once this has been run, this script can be deleted
+
+namespace :migrate do
+ desc "Change slug for two categories"
+ task :rename_two_category_slug => :environment do
+ tag_mappings = [
+ ["business/corporation-tax-capital-allowance", "business/business-tax"],
+ ["driving/blue-badges-parking", "driving/blue-badge-parking"]
+ ]
+ tag_mappings.each do |old_tag_id, new_tag_id|
+ t = Tag.where(tag_id: "#{old_tag_id}").first
+ if t.nil?
+ raise "Wa? No frakkin' tag with tag_id #{old_tag_id}"
+ end
+ t.tag_id = new_tag_id
+ t.save!
+ artefacts = Artefact.any_in(tag_ids: [old_tag_id])
+ puts "#{artefacts.count} of artefacts tagged with #{old_tag_id}"
+ artefacts.each do |a|
+ puts "Artefact: #{a.slug} with tag_ids #{a.tag_ids}"
+ index = a.tag_ids.index(old_tag_id)
+ a.tag_ids[index] = new_tag_id
+ a.save!
+ puts "new tag_ids #{a.tag_ids}"
+ end
+ end
+ end
+end

0 comments on commit 336415a

Please sign in to comment.
Something went wrong with that request. Please try again.