2019-05-02 18:17:27 -04:00
# frozen_string_literal: true
2014-06-27 12:26:03 -04:00
module Jobs
2019-10-02 00:01:53 -04:00
class Tl3Promotions < :: Jobs :: Scheduled
2014-06-27 12:26:03 -04:00
daily at : 4 . hours
def execute ( args )
2020-04-16 12:28:16 -04:00
if SiteSetting . default_trust_level < 3
# Demotions
demoted_user_ids = [ ]
User
. real
. joins (
" LEFT JOIN (SELECT gu.user_id, MAX(g.grant_trust_level) AS group_granted_trust_level FROM groups g, group_users gu WHERE g.id = gu.group_id GROUP BY gu.user_id) tl ON users.id = tl.user_id " ,
)
. where ( trust_level : TrustLevel [ 3 ] , manual_locked_trust_level : nil )
. where (
" group_granted_trust_level IS NULL OR group_granted_trust_level < ? " ,
TrustLevel [ 3 ] ,
)
. find_each do | u |
# Don't demote too soon after being promoted
next if u . on_tl3_grace_period?
2014-07-08 17:39:36 -04:00
2024-11-22 15:28:43 -05:00
modifier_applied , demoted_user_id =
DiscoursePluginRegistry . apply_modifier (
:tl3_custom_demotions ,
false ,
u ,
demoted_user_ids ,
)
if modifier_applied
demoted_user_ids << demoted_user_id
next
end
2020-04-16 12:28:16 -04:00
if Promotion . tl3_lost? ( u )
demoted_user_ids << u . id
Promotion . new ( u ) . change_trust_level! ( TrustLevel [ 2 ] )
2023-01-09 07:20:10 -05:00
end
2020-04-16 12:28:16 -04:00
end
2014-06-27 12:26:03 -04:00
end
2024-11-22 15:28:43 -05:00
override =
DiscoursePluginRegistry . apply_modifier ( :tl3_custom_promotions , false , demoted_user_ids )
return override if override
2014-06-27 12:26:03 -04:00
# Promotions
2018-02-05 17:54:07 -05:00
User
. real
. not_suspended
2018-08-09 20:42:23 -04:00
. where ( trust_level : TrustLevel [ 2 ] , manual_locked_trust_level : nil )
2018-02-05 17:54:07 -05:00
. where . not ( id : demoted_user_ids )
. joins ( :user_stat )
. where ( " user_stats.days_visited >= ? " , SiteSetting . tl3_requires_days_visited )
. where ( " user_stats.topics_entered >= ? " , SiteSetting . tl3_requires_topics_viewed_all_time )
. where ( " user_stats.posts_read_count >= ? " , SiteSetting . tl3_requires_posts_read_all_time )
. where ( " user_stats.likes_given >= ? " , SiteSetting . tl3_requires_likes_given )
. where ( " user_stats.likes_received >= ? " , SiteSetting . tl3_requires_likes_received )
2014-09-05 01:20:39 -04:00
. find_each { | u | Promotion . new ( u ) . review_tl2 }
2014-06-27 12:26:03 -04:00
end
end
end