diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tasks/pages.rake | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/lib/tasks/pages.rake b/lib/tasks/pages.rake deleted file mode 100644 index ea0776b7..00000000 --- a/lib/tasks/pages.rake +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | namespace :pages do | ||
| 2 | desc "Backfill pages.slug and pages.parent_node_id from each page's " \ | ||
| 3 | "node. Historical accuracy is not attempted. Every revision gets " \ | ||
| 4 | "the node's current address, which is right for head and draft and " \ | ||
| 5 | "harmless for older revisions, and avoids nil checks everywhere. " \ | ||
| 6 | "Dry run unless WRITE=1." | ||
| 7 | task :backfill_address => :environment do | ||
| 8 | write = ENV["WRITE"] == "1" | ||
| 9 | puts "DRY RUN -- nothing written. Re-run with WRITE=1." unless write | ||
| 10 | |||
| 11 | touched = 0 | ||
| 12 | Node.find_each do |node| | ||
| 13 | scope = node.pages.where("slug IS DISTINCT FROM :s OR parent_node_id IS DISTINCT FROM :p", | ||
| 14 | :s => node.slug, :p => node.parent_id) | ||
| 15 | count = scope.count | ||
| 16 | next if count.zero? | ||
| 17 | |||
| 18 | scope.update_all(:slug => node.slug, :parent_node_id => node.parent_id) if write | ||
| 19 | touched += count | ||
| 20 | end | ||
| 21 | |||
| 22 | # Autosaves carry no node_id -- has_many :pages does not cover them. | ||
| 23 | Node.where.not(:autosave_id => nil).includes(:autosave).find_each do |node| | ||
| 24 | a = node.autosave | ||
| 25 | next if a.slug == node.slug && a.parent_node_id == node.parent_id | ||
| 26 | |||
| 27 | a.update_columns(:slug => node.slug, :parent_node_id => node.parent_id) if write | ||
| 28 | touched += 1 | ||
| 29 | end | ||
| 30 | |||
| 31 | puts "#{write ? "updated" : "would update"} #{touched} pages" | ||
| 32 | end | ||
| 33 | |||
| 34 | desc "Backfill pages.external_url from each page's node." | ||
| 35 | task :backfill_external_url => :environment do | ||
| 36 | write = ENV["WRITE"] == "1" | ||
| 37 | puts "DRY RUN -- nothing written. Re-run with WRITE=1." unless write | ||
| 38 | |||
| 39 | touched = 0 | ||
| 40 | Node.where.not(:external_url => [nil, ""]).find_each do |node| | ||
| 41 | scope = node.pages.where("external_url IS DISTINCT FROM :u", :u => node.external_url) | ||
| 42 | count = scope.count | ||
| 43 | next if count.zero? | ||
| 44 | |||
| 45 | scope.update_all(:external_url => node.external_url) if write | ||
| 46 | touched += count | ||
| 47 | end | ||
| 48 | |||
| 49 | # Autosaves carry no node_id, so has_many :pages does not cover them. | ||
| 50 | Node.where.not(:autosave_id => nil).where.not(:external_url => [nil, ""]) | ||
| 51 | .includes(:autosave).find_each do |node| | ||
| 52 | a = node.autosave | ||
| 53 | next if a.nil? || a.external_url == node.external_url | ||
| 54 | |||
| 55 | a.update_columns(:external_url => node.external_url) if write | ||
| 56 | touched += 1 | ||
| 57 | end | ||
| 58 | |||
| 59 | puts "#{write ? "updated" : "would update"} #{touched} pages" | ||
| 60 | end | ||
| 61 | end | ||
