Merge pull request #3055 from evazion/feat-post-replacement-controller
Add post replacements controller.
This commit is contained in:
@@ -1429,9 +1429,12 @@ class Post < ActiveRecord::Base
|
||||
ModAction.log("undeleted post ##{id}")
|
||||
end
|
||||
|
||||
def replace!(url)
|
||||
replacement = replacements.create(replacement_url: url)
|
||||
replacement.process!
|
||||
def replace!(params)
|
||||
transaction do
|
||||
replacement = replacements.create(params)
|
||||
replacement.process!
|
||||
replacement
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -61,4 +61,32 @@ class PostReplacement < ActiveRecord::Base
|
||||
post.distribute_files
|
||||
post.update_iqdb_async
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
def search(params = {})
|
||||
q = all
|
||||
|
||||
if params[:creator_id].present?
|
||||
q = q.where(creator_id: params[:creator_id].split(",").map(&:to_i))
|
||||
end
|
||||
|
||||
if params[:creator_name].present?
|
||||
q = q.where(creator_name: User.name_to_id(params[:creator_name]))
|
||||
end
|
||||
|
||||
if params[:id].present?
|
||||
q = q.where(id: params[:id].split(",").map(&:to_i))
|
||||
end
|
||||
|
||||
if params[:post_id].present?
|
||||
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
|
||||
end
|
||||
|
||||
q = q.order("created_at DESC")
|
||||
|
||||
q
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user