diff --git a/app/logical/user_promotion.rb b/app/logical/user_promotion.rb index 2ee8ee685..eaefa3ea9 100644 --- a/app/logical/user_promotion.rb +++ b/app/logical/user_promotion.rb @@ -18,7 +18,6 @@ class UserPromotion user.level = new_level user.can_upload_free = can_upload_free unless can_upload_free.nil? user.can_approve_posts = can_approve_posts unless can_approve_posts.nil? - user.inviter = promoter create_user_feedback create_dmail diff --git a/app/models/user_upgrade.rb b/app/models/user_upgrade.rb index de81fa214..58bd96b3a 100644 --- a/app/models/user_upgrade.rb +++ b/app/models/user_upgrade.rb @@ -119,7 +119,7 @@ class UserUpgrade < ApplicationRecord end def upgrade_recipient! - recipient.update!(level: level, inviter: User.system) + recipient.update!(level: level) end def create_mod_action! diff --git a/script/fixes/076_clear_inviters.rb b/script/fixes/076_clear_inviters.rb new file mode 100755 index 000000000..3a23eef44 --- /dev/null +++ b/script/fixes/076_clear_inviters.rb @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby + +require_relative "../../config/environment" + +User.transaction do + # Clear inviter for users who were listed as invited by Albert. Most of these + # are very old Gold upgrades. Others are old accounts who probably weren't + # invited by Albert himself. + p User.where(inviter_id: 1).count + User.where(inviter_id: 1).update_all(inviter_id: nil) + + # Clear inviter for older Gold and Platinum upgrades where the user was listed as having invited themselves. + p User.where("inviter_id = id").count + User.where("inviter_id = id").update_all(inviter_id: nil) + + # Clear inviter for newer Gold and Platinum upgrades where the user was listed as being invited by DanbooruBot. + p User.where(inviter_id: User.system.id).count + User.where(inviter_id: User.system.id).update_all(inviter_id: nil) + + # Clear inviter for users where there is a promotion feedback from the inviter. + p User.joins(:feedback).where.not(inviter_id: nil).where_regex(:body, "^(You have been promoted|You gained the ability|Promoted from|Promoted by)").where("inviter_id = user_feedback.creator_id").count + User.joins(:feedback).where.not(inviter_id: nil).where_regex(:body, "^(You have been promoted|You gained the ability|Promoted from|Promoted by)").where("inviter_id = user_feedback.creator_id").update_all(inviter_id: nil) + + # Clear inviter for users where there is a promotion modaction from the inviter. + sql = "JOIN (SELECT (regexp_matches(description, '/users/([0-9]+)'))[1]::integer as user_id, * FROM mod_actions) AS subquery ON subquery.user_id = users.id" + p User.joins(sql).where("subquery.category": [7, 8, 9, 19]).where("users.inviter_id = subquery.creator_id").count + User.joins(sql).where("subquery.category": [7, 8, 9, 19]).where("users.inviter_id = subquery.creator_id").update_all(inviter_id: nil) +end