implement postarchive
This commit is contained in:
@@ -42,7 +42,6 @@ class Post < ActiveRecord::Base
|
||||
has_one :pixiv_ugoira_frame_data, :class_name => "PixivUgoiraFrameData", :dependent => :destroy
|
||||
has_many :flags, :class_name => "PostFlag", :dependent => :destroy
|
||||
has_many :appeals, :class_name => "PostAppeal", :dependent => :destroy
|
||||
has_many :versions, lambda {order("post_versions.updated_at ASC, post_versions.id ASC")}, :class_name => "PostVersion", :dependent => :destroy
|
||||
has_many :votes, :class_name => "PostVote", :dependent => :destroy
|
||||
has_many :notes, :dependent => :destroy
|
||||
has_many :comments, lambda {includes(:creator, :updater).order("comments.id")}, :dependent => :destroy
|
||||
@@ -1414,12 +1413,16 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module VersionMethods
|
||||
def versions
|
||||
if PostArchive.enabled?
|
||||
PostArchive.where(post_id: id).order("updated_at ASC, id asc")
|
||||
else
|
||||
raise "Archive service not configured"
|
||||
end
|
||||
end
|
||||
|
||||
def create_version(force = false)
|
||||
if new_record? || rating_changed? || source_changed? || parent_id_changed? || tag_string_changed? || force
|
||||
if merge_version?
|
||||
delete_previous_version
|
||||
end
|
||||
|
||||
create_new_version
|
||||
end
|
||||
end
|
||||
@@ -1431,19 +1434,7 @@ class Post < ActiveRecord::Base
|
||||
|
||||
def create_new_version
|
||||
User.where(id: CurrentUser.id).update_all("post_update_count = post_update_count + 1")
|
||||
CurrentUser.reload
|
||||
|
||||
versions.create(
|
||||
:rating => rating,
|
||||
:source => source,
|
||||
:tags => tag_string,
|
||||
:parent_id => parent_id
|
||||
)
|
||||
end
|
||||
|
||||
def delete_previous_version
|
||||
prev = versions.last
|
||||
prev.destroy
|
||||
PostArchive.queue(self) if PostArchive.enabled?
|
||||
end
|
||||
|
||||
def revert_to(target)
|
||||
|
||||
Reference in New Issue
Block a user