2019-05-28 07:08:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2019-10-02 00:01:53 -04:00
|
|
|
class CleanUpUserExportTopics < ::Jobs::Onceoff
|
2019-05-28 07:08:41 -04:00
|
|
|
def execute_onceoff(args)
|
2019-05-30 00:54:45 -04:00
|
|
|
translated_keys = I18n.available_locales.map do |l|
|
|
|
|
I18n.with_locale(:"#{l}") { I18n.t("system_messages.csv_export_succeeded.subject_template") }
|
|
|
|
end.uniq
|
2019-05-28 07:08:41 -04:00
|
|
|
|
|
|
|
slugs = []
|
|
|
|
translated_keys.each do |k|
|
|
|
|
slugs << "%-#{Slug.for(k.gsub('[%{export_title}]', ''))}"
|
|
|
|
end
|
|
|
|
# "[%{export_title}] 資料匯出已完成" gets converted to "%-topic", do not match that slug.
|
|
|
|
slugs = slugs.reject { |s| s == "%-topic" }
|
|
|
|
|
2019-05-30 00:54:45 -04:00
|
|
|
topics = Topic.with_deleted.where(<<~SQL, slugs, UserExport::DESTROY_CREATED_BEFORE)
|
2019-05-28 07:08:41 -04:00
|
|
|
slug LIKE ANY(ARRAY[?]) AND
|
|
|
|
archetype = 'private_message' AND
|
|
|
|
subtype = 'system_message' AND
|
|
|
|
posts_count = 1 AND
|
|
|
|
created_at < ? AND
|
|
|
|
user_id = -1
|
|
|
|
SQL
|
|
|
|
|
|
|
|
topics.each do |t|
|
|
|
|
Topic.transaction do
|
|
|
|
t.posts.first.destroy!
|
|
|
|
t.destroy!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|