From 060c30531765f076b14dbfd10a50230019b2aced Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 17 Dec 2013 13:13:27 -0500 Subject: [PATCH] #1326: Add script to move favorites to parent --- script/fixes/024_move_favorites_to_parent.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 script/fixes/024_move_favorites_to_parent.rb diff --git a/script/fixes/024_move_favorites_to_parent.rb b/script/fixes/024_move_favorites_to_parent.rb new file mode 100644 index 000000000..684909ce6 --- /dev/null +++ b/script/fixes/024_move_favorites_to_parent.rb @@ -0,0 +1,19 @@ +#!/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 + sample_tags = %w(pixiv_manga_sample pixiv_thumbnail deviantart_thumbnail thumbnail nico_nico_thumbnail twitpic_thumbnail tumblr_sample imageboard_sample nijie_sample) + Post.tag_match(sample_tags.map{|tag| "~" + tag}.join(" ")).where("is_deleted = true and parent_id is not null and fav_count > 0").find_each do |post| + if (post.parent.tag_array & sample_tags).any? + next + else + post.give_favorites_to_parent + end + end +end