Kill trailing whitespace in ruby files
This commit is contained in:
@@ -2,7 +2,7 @@ class Post < ActiveRecord::Base
|
||||
class ApprovalError < Exception ; end
|
||||
class DisapprovalError < Exception ; end
|
||||
class SearchError < Exception ; end
|
||||
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id, :has_constraints
|
||||
after_destroy :delete_files
|
||||
after_destroy :delete_remote_files
|
||||
@@ -34,7 +34,7 @@ class Post < ActiveRecord::Base
|
||||
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :as => [:member, :builder, :privileged, :platinum, :contributor, :janitor, :moderator, :admin, :default]
|
||||
attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :contributor, :janitor, :moderator, :admin]
|
||||
attr_accessible :is_status_locked, :as => [:admin]
|
||||
|
||||
|
||||
module FileMethods
|
||||
def distribute_files
|
||||
RemoteFileManager.new(file_path).distribute
|
||||
@@ -42,14 +42,14 @@ class Post < ActiveRecord::Base
|
||||
RemoteFileManager.new(ssd_preview_file_path).distribute if Danbooru.config.ssd_path
|
||||
RemoteFileManager.new(large_file_path).distribute if has_large?
|
||||
end
|
||||
|
||||
|
||||
def delete_remote_files
|
||||
RemoteFileManager.new(file_path).delete
|
||||
RemoteFileManager.new(real_preview_file_path).delete
|
||||
RemoteFileManager.new(ssd_preview_file_path).delete if Danbooru.config.ssd_path
|
||||
RemoteFileManager.new(large_file_path).delete if has_large?
|
||||
end
|
||||
|
||||
|
||||
def delete_files
|
||||
FileUtils.rm_f(file_path)
|
||||
FileUtils.rm_f(large_file_path)
|
||||
@@ -60,11 +60,11 @@ class Post < ActiveRecord::Base
|
||||
def file_path_prefix
|
||||
Rails.env == "test" ? "test." : ""
|
||||
end
|
||||
|
||||
|
||||
def file_path
|
||||
"#{Rails.root}/public/data/#{file_path_prefix}#{md5}.#{file_ext}"
|
||||
end
|
||||
|
||||
|
||||
def large_file_path
|
||||
if has_large?
|
||||
"#{Rails.root}/public/data/sample/#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.jpg"
|
||||
@@ -72,11 +72,11 @@ class Post < ActiveRecord::Base
|
||||
file_path
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def real_preview_file_path
|
||||
"#{Rails.root}/public/data/preview/#{file_path_prefix}#{md5}.jpg"
|
||||
end
|
||||
|
||||
|
||||
def ssd_preview_file_path
|
||||
"#{Danbooru.config.ssd_path}/public/data/preview/#{file_path_prefix}#{md5}.jpg"
|
||||
end
|
||||
@@ -92,7 +92,7 @@ class Post < ActiveRecord::Base
|
||||
def file_url
|
||||
"/data/#{file_path_prefix}#{md5}.#{file_ext}"
|
||||
end
|
||||
|
||||
|
||||
def large_file_url
|
||||
if has_large?
|
||||
"/data/sample/#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.jpg"
|
||||
@@ -105,14 +105,14 @@ class Post < ActiveRecord::Base
|
||||
if !is_image?
|
||||
return "/images/download-preview.png"
|
||||
end
|
||||
|
||||
|
||||
if Danbooru.config.ssd_path
|
||||
"/ssd/data/preview/#{file_path_prefix}#{md5}.jpg"
|
||||
else
|
||||
"/data/preview/#{file_path_prefix}#{md5}.jpg"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def file_url_for(user)
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
@@ -121,12 +121,12 @@ class Post < ActiveRecord::Base
|
||||
else
|
||||
file_url
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
file_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def file_path_for(user)
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
@@ -135,34 +135,34 @@ class Post < ActiveRecord::Base
|
||||
else
|
||||
file_path
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
file_path
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def is_image?
|
||||
file_ext =~ /jpg|jpeg|gif|png/
|
||||
end
|
||||
|
||||
|
||||
def is_flash?
|
||||
file_ext =~ /swf/
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module ImageMethods
|
||||
def has_large?
|
||||
image_width.present? && image_width > Danbooru.config.large_image_width
|
||||
end
|
||||
|
||||
|
||||
def has_large
|
||||
has_large?
|
||||
end
|
||||
|
||||
|
||||
def large_image_width
|
||||
[Danbooru.config.large_image_width, image_width].min
|
||||
end
|
||||
|
||||
|
||||
def large_image_height
|
||||
ratio = Danbooru.config.large_image_width.to_f / image_width.to_f
|
||||
if ratio < 1
|
||||
@@ -171,58 +171,58 @@ class Post < ActiveRecord::Base
|
||||
image_height
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def image_width_for(user)
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
large_image_width
|
||||
|
||||
|
||||
else
|
||||
image_width
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def image_height_for(user)
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
large_image_height
|
||||
|
||||
|
||||
else
|
||||
image_height
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def resize_percentage
|
||||
100 * large_image_width.to_f / image_width.to_f
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module ApprovalMethods
|
||||
def is_approvable?
|
||||
!is_status_locked? && (is_pending? || is_flagged? || is_deleted?) && approver_id != CurrentUser.id
|
||||
end
|
||||
|
||||
|
||||
def flag!(reason)
|
||||
if is_status_locked?
|
||||
raise PostFlag::Error.new("Post is locked and cannot be flagged")
|
||||
end
|
||||
|
||||
|
||||
flag = flags.create(:reason => reason, :is_resolved => false)
|
||||
|
||||
|
||||
if flag.errors.any?
|
||||
raise PostFlag::Error.new(flag.errors.full_messages.join("; "))
|
||||
end
|
||||
|
||||
update_column(:is_flagged, true) unless is_flagged?
|
||||
end
|
||||
|
||||
|
||||
def appeal!(reason)
|
||||
if is_status_locked?
|
||||
raise PostAppeal::Error.new("Post is locked and cannot be appealed")
|
||||
end
|
||||
|
||||
|
||||
appeal = appeals.create(:reason => reason)
|
||||
|
||||
|
||||
if appeal.errors.any?
|
||||
raise PostAppeal::Error.new(appeal.errors.full_messages.join("; "))
|
||||
end
|
||||
@@ -233,17 +233,17 @@ class Post < ActiveRecord::Base
|
||||
errors.add(:is_status_locked, "; post cannot be approved")
|
||||
raise ApprovalError.new("Post is locked and cannot be approved")
|
||||
end
|
||||
|
||||
|
||||
if uploader_id == CurrentUser.id
|
||||
errors.add(:base, "You cannot approve a post you uploaded")
|
||||
raise ApprovalError.new("You cannot approve a post you uploaded")
|
||||
end
|
||||
|
||||
|
||||
if approver_id == CurrentUser.id
|
||||
errors.add(:approver, "have already approved this post")
|
||||
raise ApprovalError.new("You have previously approved this post and cannot approve it again")
|
||||
raise ApprovalError.new("You have previously approved this post and cannot approve it again")
|
||||
end
|
||||
|
||||
|
||||
flags.each {|x| x.resolve!}
|
||||
self.is_flagged = false
|
||||
self.is_pending = false
|
||||
@@ -252,12 +252,12 @@ class Post < ActiveRecord::Base
|
||||
save!
|
||||
# ModAction.create(:description => "approved post ##{id}")
|
||||
end
|
||||
|
||||
|
||||
def disapproved_by?(user)
|
||||
PostDisapproval.where(:user_id => user.id, :post_id => id).exists?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module PresenterMethods
|
||||
def presenter
|
||||
@presenter ||= PostPresenter.new(self)
|
||||
@@ -267,15 +267,15 @@ class Post < ActiveRecord::Base
|
||||
case rating
|
||||
when "q"
|
||||
"Questionable"
|
||||
|
||||
|
||||
when "e"
|
||||
"Explicit"
|
||||
|
||||
|
||||
when "s"
|
||||
"Safe"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def normalized_source
|
||||
if source =~ /pixiv\.net\/img/
|
||||
img_id = source[/(\d+)(_s|_m|(_big)?_p\d+)?\.[\w\?]+\s*$/, 1]
|
||||
@@ -290,28 +290,28 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module TagMethods
|
||||
def tag_array
|
||||
@tag_array ||= Tag.scan_tags(tag_string)
|
||||
end
|
||||
|
||||
|
||||
def tag_array_was
|
||||
@tag_array_was ||= Tag.scan_tags(tag_string_was)
|
||||
end
|
||||
|
||||
|
||||
def create_tags
|
||||
set_tag_string(tag_array.map {|x| Tag.find_or_create_by_name(x).name}.uniq.sort.join(" "))
|
||||
end
|
||||
|
||||
|
||||
def increment_tag_post_counts
|
||||
execute_sql("UPDATE tags SET post_count = post_count + 1 WHERE name IN (?)", tag_array) if tag_array.any?
|
||||
end
|
||||
|
||||
|
||||
def decrement_tag_post_counts
|
||||
execute_sql("UPDATE tags SET post_count = post_count - 1 WHERE name IN (?)", tag_array) if tag_array.any?
|
||||
end
|
||||
|
||||
|
||||
def update_tag_post_counts
|
||||
decrement_tags = tag_array_was - tag_array
|
||||
increment_tags = tag_array - tag_array_was
|
||||
@@ -321,55 +321,55 @@ class Post < ActiveRecord::Base
|
||||
Post.expire_cache_for_all(increment_tags)
|
||||
Post.expire_cache_for_all([""]) if new_record? || id <= 100_000
|
||||
end
|
||||
|
||||
|
||||
def set_tag_counts
|
||||
self.tag_count = 0
|
||||
self.tag_count_general = 0
|
||||
self.tag_count_artist = 0
|
||||
self.tag_count_copyright = 0
|
||||
self.tag_count_character = 0
|
||||
|
||||
|
||||
categories = Tag.categories_for(tag_array)
|
||||
categories.each_value do |category|
|
||||
self.tag_count += 1
|
||||
|
||||
|
||||
case category
|
||||
when Tag.categories.general
|
||||
self.tag_count_general += 1
|
||||
|
||||
|
||||
when Tag.categories.artist
|
||||
self.tag_count_artist += 1
|
||||
|
||||
|
||||
when Tag.categories.copyright
|
||||
self.tag_count_copyright += 1
|
||||
|
||||
|
||||
when Tag.categories.character
|
||||
self.tag_count_character += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def merge_old_tags
|
||||
if old_tag_string
|
||||
# If someone else committed changes to this post before we did,
|
||||
# then try to merge the tag changes together.
|
||||
current_tags = tag_array_was()
|
||||
new_tags = tag_array()
|
||||
old_tags = Tag.scan_tags(old_tag_string)
|
||||
old_tags = Tag.scan_tags(old_tag_string)
|
||||
set_tag_string(((current_tags + new_tags) - old_tags + (current_tags & new_tags)).uniq.sort.join(" "))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def reset_tag_array_cache
|
||||
@tag_array = nil
|
||||
@tag_array_was = nil
|
||||
end
|
||||
|
||||
|
||||
def set_tag_string(string)
|
||||
self.tag_string = string
|
||||
reset_tag_array_cache
|
||||
end
|
||||
|
||||
|
||||
def normalize_tags
|
||||
normalized_tags = Tag.scan_tags(tag_string)
|
||||
normalized_tags = TagAlias.to_aliased(normalized_tags)
|
||||
@@ -379,52 +379,52 @@ class Post < ActiveRecord::Base
|
||||
normalized_tags.sort!
|
||||
set_tag_string(normalized_tags.uniq.sort.join(" "))
|
||||
end
|
||||
|
||||
|
||||
def filter_metatags(tags)
|
||||
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent):/}
|
||||
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|fav):/}
|
||||
apply_pre_metatags
|
||||
return tags
|
||||
end
|
||||
|
||||
|
||||
def apply_post_metatags
|
||||
return unless @post_metatags
|
||||
|
||||
|
||||
@post_metatags.each do |tag|
|
||||
case tag
|
||||
when /^-pool:(\d+)$/
|
||||
pool = Pool.find_by_id($1.to_i)
|
||||
remove_pool!(pool) if pool
|
||||
|
||||
|
||||
when /^-pool:(.+)$/
|
||||
pool = Pool.find_by_name($1)
|
||||
remove_pool!(pool) if pool
|
||||
|
||||
|
||||
when /^pool:(\d+)$/
|
||||
pool = Pool.find_by_id($1.to_i)
|
||||
add_pool!(pool) if pool
|
||||
|
||||
|
||||
when /^pool:(.+)$/
|
||||
pool = Pool.find_by_name($1)
|
||||
if pool.nil?
|
||||
pool = Pool.create(:name => $1, :description => "This pool was automatically generated")
|
||||
end
|
||||
add_pool!(pool) if pool
|
||||
|
||||
|
||||
when /^fav:(.+)$/
|
||||
add_favorite!(CurrentUser.user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def apply_pre_metatags
|
||||
return unless @pre_metatags
|
||||
|
||||
|
||||
@pre_metatags.each do |tag|
|
||||
case tag
|
||||
when /^parent:none$/, /^parent:0$/
|
||||
self.parent_id = nil
|
||||
|
||||
|
||||
when /^parent:(\d+)$/
|
||||
self.parent_id = $1.to_i
|
||||
|
||||
@@ -433,31 +433,31 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def has_tag?(tag)
|
||||
tag_string =~ /(?:^| )#{tag}(?:$| )/
|
||||
end
|
||||
|
||||
|
||||
def has_dup_tag?
|
||||
has_tag?("duplicate") ? true : false
|
||||
end
|
||||
|
||||
|
||||
def tag_categories
|
||||
@tag_categories ||= Tag.categories_for(tag_array)
|
||||
end
|
||||
|
||||
|
||||
def copyright_tags
|
||||
typed_tags("copyright")
|
||||
end
|
||||
|
||||
|
||||
def character_tags
|
||||
typed_tags("character")
|
||||
end
|
||||
|
||||
|
||||
def artist_tags
|
||||
typed_tags("artist")
|
||||
end
|
||||
|
||||
|
||||
def typed_tags(name)
|
||||
@typed_tags ||= {}
|
||||
@typed_tags[name] ||= begin
|
||||
@@ -466,7 +466,7 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def essential_tag_string
|
||||
tag_array.each do |tag|
|
||||
if tag_categories[tag] == Danbooru.config.tag_category_mapping["copyright"]
|
||||
@@ -489,16 +489,16 @@ class Post < ActiveRecord::Base
|
||||
return tag_array.first
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module FavoriteMethods
|
||||
def favorited_by?(user_id)
|
||||
fav_string =~ /(?:\A| )fav:#{user_id}(?:\Z| )/
|
||||
end
|
||||
|
||||
|
||||
def append_user_to_fav_string(user_id)
|
||||
update_column(:fav_string, (fav_string + " fav:#{user_id}").strip)
|
||||
end
|
||||
|
||||
|
||||
def add_favorite!(user)
|
||||
return if favorited_by?(user.id)
|
||||
append_user_to_fav_string(user.id)
|
||||
@@ -506,11 +506,11 @@ class Post < ActiveRecord::Base
|
||||
increment!(:score) if CurrentUser.is_privileged?
|
||||
user.add_favorite!(self)
|
||||
end
|
||||
|
||||
|
||||
def delete_user_from_fav_string(user_id)
|
||||
update_column(:fav_string, fav_string.gsub(/(?:\A| )fav:#{user_id}(?:\Z| )/, " ").strip)
|
||||
end
|
||||
|
||||
|
||||
def remove_favorite!(user)
|
||||
return unless favorited_by?(user.id)
|
||||
decrement!(:fav_count)
|
||||
@@ -518,12 +518,12 @@ class Post < ActiveRecord::Base
|
||||
delete_user_from_fav_string(user.id)
|
||||
user.remove_favorite!(self)
|
||||
end
|
||||
|
||||
|
||||
def favorited_user_ids
|
||||
fav_string.scan(/\d+/)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module UploaderMethods
|
||||
def initialize_uploader
|
||||
if uploader_id.blank?
|
||||
@@ -531,12 +531,12 @@ class Post < ActiveRecord::Base
|
||||
self.uploader_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def uploader_name
|
||||
User.id_to_name(uploader_id).tr("_", " ")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module PoolMethods
|
||||
def pools
|
||||
@pools ||= begin
|
||||
@@ -544,18 +544,18 @@ class Post < ActiveRecord::Base
|
||||
Pool.where(["is_deleted = false and id in (?)", pool_ids])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def belongs_to_pool?(pool)
|
||||
pool_string =~ /(?:\A| )pool:#{pool.id}(?:\Z| )/
|
||||
end
|
||||
|
||||
|
||||
def add_pool!(pool)
|
||||
return if belongs_to_pool?(pool)
|
||||
self.pool_string = "#{pool_string} pool:#{pool.id}".strip
|
||||
update_column(:pool_string, pool_string) unless new_record?
|
||||
pool.add!(self)
|
||||
end
|
||||
|
||||
|
||||
def remove_pool!(pool)
|
||||
return unless belongs_to_pool?(pool)
|
||||
self.pool_string = pool_string.gsub(/(?:\A| )pool:#{pool.id}(?:\Z| )/, " ").strip
|
||||
@@ -563,7 +563,7 @@ class Post < ActiveRecord::Base
|
||||
pool.remove!(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module VoteMethods
|
||||
def can_be_voted_by?(user)
|
||||
!votes.exists?(["user_id = ?", user.id])
|
||||
@@ -585,7 +585,7 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module CountMethods
|
||||
def fix_post_counts
|
||||
post.set_tag_counts
|
||||
@@ -595,17 +595,17 @@ class Post < ActiveRecord::Base
|
||||
post.update_column(:tag_count_copyright, post.tag_count_copyright)
|
||||
post.update_column(:tag_count_character, post.tag_count_character)
|
||||
end
|
||||
|
||||
|
||||
def get_count_from_cache(tags)
|
||||
count = Cache.get(count_cache_key(tags))
|
||||
|
||||
|
||||
if count.nil?
|
||||
count = select_value_sql("SELECT post_count FROM tags WHERE name = ?", tags.to_s)
|
||||
end
|
||||
|
||||
|
||||
count
|
||||
end
|
||||
|
||||
|
||||
def set_count_in_cache(tags, count, expiry = nil)
|
||||
if expiry.nil?
|
||||
if count < 100
|
||||
@@ -614,14 +614,14 @@ class Post < ActiveRecord::Base
|
||||
expiry = (count * 4).minutes
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Cache.put(count_cache_key(tags), count, expiry)
|
||||
end
|
||||
|
||||
|
||||
def count_cache_key(tags)
|
||||
"pfc:#{Cache.sanitize(tags)}"
|
||||
end
|
||||
|
||||
|
||||
def fast_count(tags = "")
|
||||
tags = tags.to_s.strip
|
||||
|
||||
@@ -633,7 +633,7 @@ class Post < ActiveRecord::Base
|
||||
count = fast_count_search(tags)
|
||||
else
|
||||
count = get_count_from_cache(tags)
|
||||
|
||||
|
||||
if count.to_i == 0
|
||||
count = fast_count_search(tags)
|
||||
end
|
||||
@@ -643,7 +643,7 @@ class Post < ActiveRecord::Base
|
||||
rescue SearchError
|
||||
0
|
||||
end
|
||||
|
||||
|
||||
def fast_count_search(tags)
|
||||
count = Post.with_timeout(500, Danbooru.config.blank_tag_search_fast_count || 1_000_000) do
|
||||
Post.tag_match(tags).count
|
||||
@@ -654,19 +654,19 @@ class Post < ActiveRecord::Base
|
||||
count
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module CacheMethods
|
||||
def expire_cache_for_all(tag_names)
|
||||
Danbooru.config.all_server_hosts.each do |host|
|
||||
delay(:queue => host).expire_cache(tag_names)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def expire_cache(tag_names)
|
||||
tag_names.each do |tag_name|
|
||||
Cache.delete(Post.count_cache_key(tag_name))
|
||||
end
|
||||
|
||||
|
||||
if Post.fast_count("").to_i < 1000
|
||||
Cache.delete(Post.count_cache_key(""))
|
||||
end
|
||||
@@ -674,7 +674,7 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module ParentMethods
|
||||
# A parent has many children. A child belongs to a parent.
|
||||
# A parent has many children. A child belongs to a parent.
|
||||
# A parent cannot have a parent.
|
||||
#
|
||||
# After deleting a child:
|
||||
@@ -686,14 +686,14 @@ class Post < ActiveRecord::Base
|
||||
# After deleting a parent:
|
||||
# - Move favorites to the first child.
|
||||
# - Reparent all active children to the first active child.
|
||||
|
||||
|
||||
module ClassMethods
|
||||
def update_has_children_flag_for(post_id)
|
||||
return if post_id.nil?
|
||||
has_children = Post.exists?(["is_deleted = ? AND parent_id = ?", false, post_id])
|
||||
execute_sql("UPDATE posts SET has_children = ? WHERE id = ?", has_children, post_id)
|
||||
end
|
||||
|
||||
|
||||
def recalculate_has_children_for_all_posts
|
||||
transaction do
|
||||
execute_sql("UPDATE posts SET has_children = false WHERE has_children = true")
|
||||
@@ -701,7 +701,7 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def self.included(m)
|
||||
m.extend(ClassMethods)
|
||||
end
|
||||
@@ -712,13 +712,13 @@ class Post < ActiveRecord::Base
|
||||
errors.add(:parent, "can not have a parent")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update_parent_on_destroy
|
||||
Post.update_has_children_flag_for(id)
|
||||
Post.update_has_children_flag_for(parent_id) if parent_id
|
||||
Post.update_has_children_flag_for(parent_id_was) if parent_id_was && parent_id != parent_id_was
|
||||
end
|
||||
|
||||
|
||||
def update_children_on_destroy
|
||||
if children.size == 0
|
||||
# do nothing
|
||||
@@ -741,7 +741,7 @@ class Post < ActiveRecord::Base
|
||||
Post.update_has_children_flag_for(parent_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def give_favorites_to_parent
|
||||
return if parent.nil?
|
||||
|
||||
@@ -753,26 +753,26 @@ class Post < ActiveRecord::Base
|
||||
update_column(:score, 0)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module DeletionMethods
|
||||
def annihilate!
|
||||
if is_status_locked?
|
||||
self.errors.add(:is_status_locked, "; cannot delete post")
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
ModAction.create(:description => "permanently deleted post ##{id}")
|
||||
decrement_tag_post_counts
|
||||
delete!(:without_mod_action => true)
|
||||
destroy
|
||||
end
|
||||
|
||||
|
||||
def delete!(options = {})
|
||||
if is_status_locked?
|
||||
self.errors.add(:is_status_locked, "; cannot delete post")
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
Post.transaction do
|
||||
update_column(:is_deleted, true)
|
||||
update_column(:is_pending, false)
|
||||
@@ -782,19 +782,19 @@ class Post < ActiveRecord::Base
|
||||
update_parent_on_destroy
|
||||
# decrement_tag_post_counts
|
||||
update_column(:parent_id, nil)
|
||||
|
||||
|
||||
unless options[:without_mod_action]
|
||||
ModAction.create(:description => "deleted post ##{id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def undelete!
|
||||
if is_status_locked?
|
||||
self.errors.add(:is_status_locked, "; cannot undelete post")
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
self.is_deleted = false
|
||||
self.approver_id = CurrentUser.id
|
||||
save
|
||||
@@ -803,7 +803,7 @@ class Post < ActiveRecord::Base
|
||||
ModAction.create(:description => "undeleted post ##{id}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module VersionMethods
|
||||
def create_version
|
||||
if created_at == updated_at
|
||||
@@ -824,31 +824,31 @@ class Post < ActiveRecord::Base
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def revert_to(target)
|
||||
self.tag_string = target.tags
|
||||
self.rating = target.rating
|
||||
self.source = target.source
|
||||
self.parent_id = target.parent_id
|
||||
end
|
||||
|
||||
|
||||
def revert_to!(target)
|
||||
revert_to(target)
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module NoteMethods
|
||||
def last_noted_at_as_integer
|
||||
last_noted_at.to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module ApiMethods
|
||||
def hidden_attributes
|
||||
super + [:tag_index]
|
||||
end
|
||||
|
||||
|
||||
def serializable_hash(options = {})
|
||||
options ||= {}
|
||||
options[:except] ||= []
|
||||
@@ -860,7 +860,7 @@ class Post < ActiveRecord::Base
|
||||
hash = super(options)
|
||||
hash
|
||||
end
|
||||
|
||||
|
||||
def to_xml(options = {}, &block)
|
||||
options ||= {}
|
||||
options[:procs] ||= []
|
||||
@@ -868,7 +868,7 @@ class Post < ActiveRecord::Base
|
||||
options[:procs] << lambda {|options, record| options[:builder].tag!("has-large", record.has_large?, :type => "boolean")}
|
||||
super(options, &block)
|
||||
end
|
||||
|
||||
|
||||
def to_legacy_json
|
||||
return {
|
||||
"has_comments" => last_commented_at.present?,
|
||||
@@ -892,7 +892,7 @@ class Post < ActiveRecord::Base
|
||||
"file_url" => file_url
|
||||
}.to_json
|
||||
end
|
||||
|
||||
|
||||
def status
|
||||
if is_pending?
|
||||
"pending"
|
||||
@@ -905,44 +905,44 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module SearchMethods
|
||||
def pending
|
||||
where("is_pending = ?", true)
|
||||
end
|
||||
|
||||
|
||||
def flagged
|
||||
where("is_flagged = ?", true)
|
||||
end
|
||||
|
||||
|
||||
def pending_or_flagged
|
||||
where("(is_pending = ? or (is_flagged = ? and id in (select _.post_id from post_flags _ where _.created_at >= ?)))", true, true, 1.week.ago)
|
||||
end
|
||||
|
||||
|
||||
def undeleted
|
||||
where("is_deleted = ?", false)
|
||||
end
|
||||
|
||||
|
||||
def deleted
|
||||
where("is_deleted = ?", true)
|
||||
end
|
||||
|
||||
|
||||
def visible(user)
|
||||
Danbooru.config.can_user_see_post_conditions(user)
|
||||
end
|
||||
|
||||
|
||||
def commented_before(date)
|
||||
where("last_commented_at < ?", date).order("last_commented_at DESC")
|
||||
end
|
||||
|
||||
|
||||
def has_notes
|
||||
where("last_noted_at is not null")
|
||||
end
|
||||
|
||||
|
||||
def for_user(user_id)
|
||||
where("uploader_id = ?", user_id)
|
||||
end
|
||||
|
||||
|
||||
def available_for_moderation(hidden)
|
||||
if hidden.present?
|
||||
where("posts.id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id)
|
||||
@@ -950,31 +950,31 @@ class Post < ActiveRecord::Base
|
||||
where("posts.id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def hidden_from_moderation
|
||||
where("id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id)
|
||||
end
|
||||
|
||||
|
||||
def raw_tag_match(tag)
|
||||
where("posts.tag_index @@ to_tsquery('danbooru', E?)", tag.to_escaped_for_tsquery)
|
||||
end
|
||||
|
||||
|
||||
def tag_match(query)
|
||||
PostQueryBuilder.new(query).build
|
||||
end
|
||||
|
||||
|
||||
def positive
|
||||
where("score > 1")
|
||||
end
|
||||
|
||||
|
||||
def negative
|
||||
where("score < -1")
|
||||
end
|
||||
|
||||
|
||||
def updater_name_matches(name)
|
||||
where("updater_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)
|
||||
end
|
||||
|
||||
|
||||
def after_id(num)
|
||||
if num.present?
|
||||
where("id > ?", num.to_i).reorder("id asc")
|
||||
@@ -982,7 +982,7 @@ class Post < ActiveRecord::Base
|
||||
where("true")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def before_id(num)
|
||||
if num.present?
|
||||
where("id < ?", num.to_i).reorder("id desc")
|
||||
@@ -990,27 +990,27 @@ class Post < ActiveRecord::Base
|
||||
where("true")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def search(params)
|
||||
q = scoped
|
||||
return q if params.blank?
|
||||
|
||||
|
||||
if params[:before_id].present?
|
||||
q = q.before_id(params[:before_id].to_i)
|
||||
end
|
||||
|
||||
|
||||
if params[:after_id].present?
|
||||
q = q.after_id(params[:after_id].to_i)
|
||||
end
|
||||
|
||||
|
||||
if params[:tag_match].present?
|
||||
q = q.tag_match(params[:tag_match])
|
||||
end
|
||||
|
||||
|
||||
q
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
include FileMethods
|
||||
include ImageMethods
|
||||
include ApprovalMethods
|
||||
@@ -1028,7 +1028,7 @@ class Post < ActiveRecord::Base
|
||||
include NoteMethods
|
||||
include ApiMethods
|
||||
extend SearchMethods
|
||||
|
||||
|
||||
def reload(options = nil)
|
||||
super
|
||||
reset_tag_array_cache
|
||||
|
||||
Reference in New Issue
Block a user