fix #2239
This commit is contained in:
@@ -47,9 +47,11 @@ class PoolsController < ApplicationController
|
|||||||
# need to do this in order for synchronize! to work correctly
|
# need to do this in order for synchronize! to work correctly
|
||||||
@pool = Pool.find(params[:id])
|
@pool = Pool.find(params[:id])
|
||||||
@pool.attributes = params[:pool]
|
@pool.attributes = params[:pool]
|
||||||
@pool.synchronize!
|
@pool.synchronize
|
||||||
@pool.save
|
@pool.save
|
||||||
flash[:notice] = "Pool updated"
|
unless @pool.errors.any?
|
||||||
|
flash[:notice] = "Pool updated"
|
||||||
|
end
|
||||||
respond_with(@pool)
|
respond_with(@pool)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ module DelayedJobsHelper
|
|||||||
when "Class#decrement_post_counts"
|
when "Class#decrement_post_counts"
|
||||||
"<strong>decrement post counts</strong>"
|
"<strong>decrement post counts</strong>"
|
||||||
|
|
||||||
|
when "Pool#update_category_pseudo_tags_for_posts"
|
||||||
|
"<strong>update pool category pseudo tags for posts</strong>"
|
||||||
|
|
||||||
else
|
else
|
||||||
h(job.name)
|
h(job.name)
|
||||||
end
|
end
|
||||||
@@ -89,6 +92,9 @@ module DelayedJobsHelper
|
|||||||
when "Class#decrement_post_counts"
|
when "Class#decrement_post_counts"
|
||||||
h(job.payload_object.args.join(" "))
|
h(job.payload_object.args.join(" "))
|
||||||
|
|
||||||
|
when "Pool#update_category_pseudo_tags_for_posts"
|
||||||
|
%{<a href="/pools/#{job.payload_object.id}">#{h(job.payload_object.name)}</a>}
|
||||||
|
|
||||||
else
|
else
|
||||||
h(job.handler)
|
h(job.handler)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ class Pool < ActiveRecord::Base
|
|||||||
validates_uniqueness_of :name, :case_sensitive => false
|
validates_uniqueness_of :name, :case_sensitive => false
|
||||||
validates_format_of :name, :with => /\A[^,]+\Z/, :message => "cannot have commas"
|
validates_format_of :name, :with => /\A[^,]+\Z/, :message => "cannot have commas"
|
||||||
validates_inclusion_of :category, :in => %w(series collection)
|
validates_inclusion_of :category, :in => %w(series collection)
|
||||||
|
validate :updater_can_change_category
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
belongs_to :updater, :class_name => "User"
|
belongs_to :updater, :class_name => "User"
|
||||||
has_many :versions, lambda {order("pool_versions.id ASC")}, :class_name => "PoolVersion", :dependent => :destroy
|
has_many :versions, lambda {order("pool_versions.id ASC")}, :class_name => "PoolVersion", :dependent => :destroy
|
||||||
@@ -12,6 +13,7 @@ class Pool < ActiveRecord::Base
|
|||||||
before_validation :initialize_is_active, :on => :create
|
before_validation :initialize_is_active, :on => :create
|
||||||
before_validation :initialize_creator, :on => :create
|
before_validation :initialize_creator, :on => :create
|
||||||
before_validation :strip_name
|
before_validation :strip_name
|
||||||
|
after_save :update_category_pseudo_tags_for_posts_async
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
after_create :synchronize!
|
after_create :synchronize!
|
||||||
before_destroy :create_mod_action_for_destroy
|
before_destroy :create_mod_action_for_destroy
|
||||||
@@ -262,7 +264,7 @@ class Pool < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def synchronize!
|
def synchronize
|
||||||
added = post_id_array - post_id_array_was
|
added = post_id_array - post_id_array_was
|
||||||
removed = post_id_array_was - post_id_array
|
removed = post_id_array_was - post_id_array
|
||||||
|
|
||||||
@@ -279,6 +281,10 @@ class Pool < ActiveRecord::Base
|
|||||||
normalize_post_ids
|
normalize_post_ids
|
||||||
clear_post_id_array
|
clear_post_id_array
|
||||||
self.post_count = post_id_array.size
|
self.post_count = post_id_array.size
|
||||||
|
end
|
||||||
|
|
||||||
|
def synchronize!
|
||||||
|
synchronize
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -372,4 +378,31 @@ class Pool < ActiveRecord::Base
|
|||||||
"updated_at" => updated_at
|
"updated_at" => updated_at
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_category_pseudo_tags_for_posts_async
|
||||||
|
if category_changed?
|
||||||
|
delay(:queue => "default").update_category_pseudo_tags_for_posts
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_category_pseudo_tags_for_posts
|
||||||
|
Post.where("id in (?)", post_id_array).find_each do |post|
|
||||||
|
post.reload
|
||||||
|
post.set_pool_category_pseudo_tags
|
||||||
|
Post.where(:id => post.id).update_all(:pool_string => post.pool_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def category_changeable_by?(user)
|
||||||
|
user.is_builder? || (user.is_member? && post_count <= 100)
|
||||||
|
end
|
||||||
|
|
||||||
|
def updater_can_change_category
|
||||||
|
if category_changed? && !category_changeable_by?(CurrentUser.user)
|
||||||
|
errors[:base] << "You cannot change the category of pools with greater than 100 posts"
|
||||||
|
false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Post < ActiveRecord::Base
|
|||||||
before_save :normalize_tags
|
before_save :normalize_tags
|
||||||
before_save :update_tag_post_counts
|
before_save :update_tag_post_counts
|
||||||
before_save :set_tag_counts
|
before_save :set_tag_counts
|
||||||
|
before_save :set_pool_category_pseudo_tags
|
||||||
before_validation :strip_source
|
before_validation :strip_source
|
||||||
before_validation :initialize_uploader, :on => :create
|
before_validation :initialize_uploader, :on => :create
|
||||||
before_validation :parse_pixiv_id
|
before_validation :parse_pixiv_id
|
||||||
@@ -835,6 +836,7 @@ class Post < ActiveRecord::Base
|
|||||||
return if belongs_to_pool?(pool)
|
return if belongs_to_pool?(pool)
|
||||||
return if pool.is_deleted? && !force
|
return if pool.is_deleted? && !force
|
||||||
self.pool_string = "#{pool_string} pool:#{pool.id}".strip
|
self.pool_string = "#{pool_string} pool:#{pool.id}".strip
|
||||||
|
set_pool_category_pseudo_tags
|
||||||
update_column(:pool_string, pool_string) unless new_record?
|
update_column(:pool_string, pool_string) unless new_record?
|
||||||
pool.add!(self)
|
pool.add!(self)
|
||||||
end
|
end
|
||||||
@@ -843,6 +845,7 @@ class Post < ActiveRecord::Base
|
|||||||
return unless belongs_to_pool?(pool)
|
return unless belongs_to_pool?(pool)
|
||||||
return if pool.is_deleted? && !force
|
return if pool.is_deleted? && !force
|
||||||
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip
|
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip
|
||||||
|
set_pool_category_pseudo_tags
|
||||||
update_column(:pool_string, pool_string) unless new_record?
|
update_column(:pool_string, pool_string) unless new_record?
|
||||||
pool.remove!(self)
|
pool.remove!(self)
|
||||||
end
|
end
|
||||||
@@ -852,6 +855,18 @@ class Post < ActiveRecord::Base
|
|||||||
pool.remove!(self)
|
pool.remove!(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_pool_category_pseudo_tags
|
||||||
|
self.pool_string = (pool_string.scan(/\S+/) - ["pool:series", "pool:collection"]).join(" ")
|
||||||
|
|
||||||
|
pool_categories = pools.select("category").map(&:category)
|
||||||
|
if pool_categories.include?("series")
|
||||||
|
self.pool_string = "#{pool_string} pool:series".strip
|
||||||
|
end
|
||||||
|
if pool_categories.include?("collection")
|
||||||
|
self.pool_string = "#{pool_string} pool:collection".strip
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module VoteMethods
|
module VoteMethods
|
||||||
|
|||||||
@@ -426,13 +426,23 @@ class Tag < ActiveRecord::Base
|
|||||||
q[:artcomm_ids] << user_id unless user_id.blank?
|
q[:artcomm_ids] << user_id unless user_id.blank?
|
||||||
|
|
||||||
when "-pool"
|
when "-pool"
|
||||||
q[:tags][:exclude] << "pool:#{Pool.name_to_id($2)}"
|
if $2.downcase == "series"
|
||||||
|
q[:tags][:exclude] << "pool:series"
|
||||||
|
elsif $2.downcase == "collection"
|
||||||
|
q[:tags][:exclude] << "pool:collection"
|
||||||
|
else
|
||||||
|
q[:tags][:exclude] << "pool:#{Pool.name_to_id($2)}"
|
||||||
|
end
|
||||||
|
|
||||||
when "pool"
|
when "pool"
|
||||||
if $2.downcase == "none"
|
if $2.downcase == "none"
|
||||||
q[:pool] = "none"
|
q[:pool] = "none"
|
||||||
elsif $2.downcase == "any"
|
elsif $2.downcase == "any"
|
||||||
q[:pool] = "any"
|
q[:pool] = "any"
|
||||||
|
elsif $2.downcase == "series"
|
||||||
|
q[:tags][:related] << "pool:series"
|
||||||
|
elsif $2.downcase == "collection"
|
||||||
|
q[:tags][:related] << "pool:collection"
|
||||||
elsif $2.include?("*")
|
elsif $2.include?("*")
|
||||||
pools = Pool.name_matches($2).select("id").limit(Danbooru.config.tag_query_limit).order("post_count DESC")
|
pools = Pool.name_matches($2).select("id").limit(Danbooru.config.tag_query_limit).order("post_count DESC")
|
||||||
q[:tags][:include] += pools.map {|pool| "pool:#{pool.id}"}
|
q[:tags][:include] += pools.map {|pool| "pool:#{pool.id}"}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
<div id="a-edit">
|
<div id="a-edit">
|
||||||
<%= simple_form_for(@pool) do |f| %>
|
<%= simple_form_for(@pool) do |f| %>
|
||||||
<h1>Edit Pool: <%= @pool.pretty_name %></h1>
|
<h1>Edit Pool: <%= @pool.pretty_name %></h1>
|
||||||
|
|
||||||
|
<%= error_messages_for "pool" %>
|
||||||
|
|
||||||
<%= f.input :name, :as => :string, :input_html => { :value => @pool.pretty_name } %>
|
<%= f.input :name, :as => :string, :input_html => { :value => @pool.pretty_name } %>
|
||||||
<%= dtext_field "pool", "description" %>
|
<%= dtext_field "pool", "description" %>
|
||||||
<%= dtext_preview_button "pool", "description" %>
|
<%= dtext_preview_button "pool", "description" %>
|
||||||
|
|||||||
16
script/fixes/032_add_pool_category_pseudo_tags.rb
Normal file
16
script/fixes/032_add_pool_category_pseudo_tags.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
|
||||||
|
|
||||||
|
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
|
||||||
|
|
||||||
|
CurrentUser.user = User.admins.first
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
|
||||||
|
CurrentUser.without_safe_mode do
|
||||||
|
Post.tag_match("pool:any").find_each do |post|
|
||||||
|
post.reload
|
||||||
|
post.set_pool_category_pseudo_tags
|
||||||
|
Post.where(:id => post.id).update_all(:pool_string => post.pool_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user