From 63d5c7900d45807a3281f9f8ce4f03c8b570c10e Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Wed, 11 Jan 2017 16:20:04 -0800 Subject: [PATCH] enable bulk reverts, fixes to postarchive --- app/models/post_archive.rb | 19 ++++++++++++------- app/views/moderator/bulk_reverts/new.html.erb | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/models/post_archive.rb b/app/models/post_archive.rb index 0633d77af..bb1315670 100644 --- a/app/models/post_archive.rb +++ b/app/models/post_archive.rb @@ -6,18 +6,24 @@ class PostArchive < ActiveRecord::Base establish_connection "archive_#{Rails.env}".to_sym if enabled? self.table_name = "post_versions" - def self.calculate_version(post_id, updated_at) - 1 + PostVersion.where("post_id = ? and updated_at <= ?", post_id, updated_at).count + def self.calculate_version(post_id, updated_at, version_id) + if updated_at.to_i == Time.zone.parse("2007-03-14T19:38:12Z").to_i + # Old post versions which didn't have updated_at set correctly + 1 + PostVersion.where("post_id = ? and updated_at = ? and id < ?", post_id, updated_at, version_id).count + else + 1 + PostVersion.where("post_id = ? and updated_at < ?", post_id, updated_at).count + end end def self.export(version_id = 0) - PostVersion.where("id > version_id").find_each do |version| + PostVersion.where("id > ?", version_id).find_each do |version| previous = version.previous tags = version.tags.scan(/\S+/) if previous - added_tags = tags - previous.tags - removed_tags = previous.tags - tags + prev_tags = previous.tags.scan(/\S+/) + added_tags = tags - previous.tags.scan(/\S+/) + removed_tags = previous.tags.scan(/\S+/) - tags else added_tags = tags removed_tags = [] @@ -33,9 +39,8 @@ class PostArchive < ActiveRecord::Base removed_tags: removed_tags, updater_id: version.updater_id, updater_ip_addr: version.updater_ip_addr.to_s, - created_at: version.created_at, updated_at: version.updated_at, - version: calculate_version(version.post_id, version.updated_at), + version: calculate_version(version.post_id, version.updated_at, version.id), rating: version.rating, rating_changed: rating_changed, parent_id: version.parent_id, diff --git a/app/views/moderator/bulk_reverts/new.html.erb b/app/views/moderator/bulk_reverts/new.html.erb index 9caf16328..a968b6b6c 100644 --- a/app/views/moderator/bulk_reverts/new.html.erb +++ b/app/views/moderator/bulk_reverts/new.html.erb @@ -33,7 +33,7 @@ <%= submit_tag "Test" %> <% if params[:commit] == "Test" %> - <%#= submit_tag %> + <%= submit_tag %> <% end %> <% end %>