FIX: FirstReplyByEmail badge wasn't granted

DEPRECATED: PostProcess badge trigger
This commit is contained in:
Régis Hanol
2016-08-10 19:24:01 +02:00
parent d763ce08c0
commit e55e2aff94
9 changed files with 41 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
module Jobs
class GrantFirstReplyByEmail < Jobs::Onceoff
def execute_onceoff(args)
return unless SiteSetting.enable_badges
to_award = {}

View File

@@ -9,7 +9,7 @@ module Jobs
.select(:id, :created_at, :cooked, :user_id)
.visible
.public_posts
.where("cooked like '%emoji%'")
.where("cooked LIKE '%emoji%'")
.find_in_batches do |group|
group.each do |p|
doc = Nokogiri::HTML::fragment(p.cooked)

View File

@@ -11,9 +11,8 @@ module Jobs
.select(:id, :created_at, :raw, :user_id)
.visible
.public_posts
.where("raw like '%http%'")
.where("raw LIKE '%http%'")
.find_in_batches do |group|
group.each do |p|
begin
# Note we can't use `p.cooked` here because oneboxes have been cooked out

View File

@@ -66,14 +66,14 @@ class Badge < ActiveRecord::Base
PostRevision = 2
TrustLevelChange = 4
UserChange = 8
PostProcessed = 16
PostProcessed = 16 # deprecated
def self.is_none?(trigger)
[None].include? trigger
end
def self.uses_user_ids?(trigger)
[TrustLevelChange, UserChange, PostProcessed].include? trigger
[TrustLevelChange, UserChange].include? trigger
end
def self.uses_post_ids?(trigger)

View File

@@ -362,6 +362,10 @@ class Post < ActiveRecord::Base
post_number == 1
end
def is_reply_by_email?
via_email && post_number.present? && post_number > 1
end
def is_flagged?
post_actions.where(post_action_type_id: PostActionType.flag_types.values, deleted_at: nil).count != 0
end

View File

@@ -76,7 +76,7 @@ class BadgeGranter
end
end
def self.queue_badge_grant(type,opt)
def self.queue_badge_grant(type, opt)
return unless SiteSetting.enable_badges
payload = nil
@@ -105,12 +105,6 @@ class BadgeGranter
type: "PostAction",
post_ids: [action.post_id, action.related_post_id].compact!
}
when Badge::Trigger::PostProcessed
user = opt[:user]
payload = {
type: "PostProcessed",
user_ids: [user.id]
}
end
$redis.lpush queue_key, payload.to_json if payload
@@ -128,16 +122,17 @@ class BadgeGranter
limit -= 1
end
items = items.group_by{|i| i["type"]}
items = items.group_by { |i| i["type"] }
items.each do |type, list|
post_ids = list.map{|i| i["post_ids"]}.flatten.compact.uniq
user_ids = list.map{|i| i["user_ids"]}.flatten.compact.uniq
post_ids = list.flat_map { |i| i["post_ids"] }.compact.uniq
user_ids = list.flat_map { |i| i["user_ids"] }.compact.uniq
next unless post_ids.present? || user_ids.present?
find_by_type(type).each{ |badge|
find_by_type(type).each do |badge|
backfill(badge, post_ids: post_ids, user_ids: user_ids)
}
end
end
end
@@ -229,10 +224,10 @@ class BadgeGranter
MAX_ITEMS_FOR_DELTA = 200
def self.backfill(badge, opts=nil)
return unless SiteSetting.enable_badges
return unless badge.query.present? && badge.enabled
return unless badge.enabled
return unless badge.query.present?
post_ids = user_ids = nil
post_ids = opts[:post_ids] if opts
user_ids = opts[:user_ids] if opts
@@ -331,7 +326,6 @@ class BadgeGranter
raise ex
end
def self.revoke_ungranted_titles!
Badge.exec_sql("UPDATE users SET title = ''
WHERE NOT title IS NULL AND