From 2947b25d6eb1c5ec8aba2c5d19469c120297dcea Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 20 Jul 2017 15:42:03 -0700 Subject: [PATCH] script to remove expunged posts from users' favorites --- script/fixes/048_remove_expunged_favorites.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 script/fixes/048_remove_expunged_favorites.rb diff --git a/script/fixes/048_remove_expunged_favorites.rb b/script/fixes/048_remove_expunged_favorites.rb new file mode 100644 index 000000000..79bee23ed --- /dev/null +++ b/script/fixes/048_remove_expunged_favorites.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +CurrentUser.user = User.system +CurrentUser.ip_addr = "127.0.0.1" + +ModAction.without_timeout do + ModAction.where(creator_id: 1).where("created_at > ? and description like ?", "2017-07-18", "permanently deleted post%").find_each do |ma| + post_id = ma.description.scan(/\d+/).first + puts "deleting favorites for #{post_id}" + Favorite.destroy_all(post_id: post_id) + end +end