users: don't set inviter field; clear inviter field for most users.
* Don't set the inviter field for newly promoted users, or for Gold/Plat upgrades. * Clear the inviter field for paid Gold/Plat upgrades, and for users who have a feedback or a modaction listing who invited them. This leaves about 600 remaining users with an inviter field with no other record of who invited them. See #4750.
This commit is contained in:
@@ -18,7 +18,6 @@ class UserPromotion
|
|||||||
user.level = new_level
|
user.level = new_level
|
||||||
user.can_upload_free = can_upload_free unless can_upload_free.nil?
|
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.can_approve_posts = can_approve_posts unless can_approve_posts.nil?
|
||||||
user.inviter = promoter
|
|
||||||
|
|
||||||
create_user_feedback
|
create_user_feedback
|
||||||
create_dmail
|
create_dmail
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ class UserUpgrade < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def upgrade_recipient!
|
def upgrade_recipient!
|
||||||
recipient.update!(level: level, inviter: User.system)
|
recipient.update!(level: level)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_mod_action!
|
def create_mod_action!
|
||||||
|
|||||||
28
script/fixes/076_clear_inviters.rb
Executable file
28
script/fixes/076_clear_inviters.rb
Executable file
@@ -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
|
||||||
Reference in New Issue
Block a user