enable bulk reverts, fixes to postarchive
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<%= submit_tag "Test" %>
|
||||
|
||||
<% if params[:commit] == "Test" %>
|
||||
<%#= submit_tag %>
|
||||
<%= submit_tag %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user