2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-19 03:46:50 +08:00
|
|
|
module Jobs
|
2019-10-02 12:01:53 +08:00
|
|
|
class PendingQueuedPostsReminder < ::Jobs::Scheduled
|
2015-06-19 03:46:50 +08:00
|
|
|
|
|
|
|
every 1.hour
|
|
|
|
|
|
|
|
def execute(args)
|
2017-09-13 05:44:31 +08:00
|
|
|
return true unless SiteSetting.notify_about_queued_posts_after > 0
|
2015-06-19 03:46:50 +08:00
|
|
|
|
2017-05-23 04:26:18 +08:00
|
|
|
queued_post_ids = should_notify_ids
|
|
|
|
|
|
|
|
if queued_post_ids.size > 0 && last_notified_id.to_i < queued_post_ids.max
|
2017-09-13 05:44:31 +08:00
|
|
|
PostCreator.create(
|
|
|
|
Discourse.system_user,
|
|
|
|
target_group_names: Group[:moderators].name,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.system_message,
|
|
|
|
title: I18n.t('system_messages.queued_posts_reminder.subject_template', count: queued_post_ids.size),
|
|
|
|
raw: I18n.t('system_messages.queued_posts_reminder.text_body_template', base_url: Discourse.base_url)
|
|
|
|
)
|
|
|
|
|
2017-05-23 04:26:18 +08:00
|
|
|
self.last_notified_id = queued_post_ids.max
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_notify_ids
|
2019-01-04 01:03:01 +08:00
|
|
|
ReviewableQueuedPost.where(status: Reviewable.statuses[:pending]).where(
|
|
|
|
'created_at < ?', SiteSetting.notify_about_queued_posts_after.hours.ago
|
|
|
|
).pluck(:id)
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id
|
2019-12-03 17:05:53 +08:00
|
|
|
(i = Discourse.redis.get(self.class.last_notified_key)) && i.to_i
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id=(arg)
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.redis.set(self.class.last_notified_key, arg)
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.last_notified_key
|
2017-05-23 04:26:18 +08:00
|
|
|
"last_notified_queued_post_id".freeze
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|