diff --git a/app/jobs/scheduled/clean_up_drafts.rb b/app/jobs/scheduled/clean_up_drafts.rb deleted file mode 100644 index b3ace672b50..00000000000 --- a/app/jobs/scheduled/clean_up_drafts.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Jobs - class CleanUpDrafts < Jobs::Scheduled - every 1.week - - def execute(args) - delete_drafts_older_than_n_days = SiteSetting.delete_drafts_older_than_n_days.days.ago - - # remove old drafts - Draft.where("updated_at < ?", delete_drafts_older_than_n_days).destroy_all - end - end -end diff --git a/app/models/draft.rb b/app/models/draft.rb index efc098984e4..2a209fd0f14 100644 --- a/app/models/draft.rb +++ b/app/models/draft.rb @@ -41,6 +41,10 @@ class Draft < ActiveRecord::Base WHERE s.draft_key = drafts.draft_key AND s.user_id = drafts.user_id )") + + # remove old drafts + delete_drafts_older_than_n_days = SiteSetting.delete_drafts_older_than_n_days.days.ago + Draft.where("updated_at < ?", delete_drafts_older_than_n_days).destroy_all end end diff --git a/config/site_settings.yml b/config/site_settings.yml index 33764aff1ed..c514c802975 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -893,7 +893,7 @@ uncategorized: default: 0 hidden: true - delete_drafts_older_than_n_days: 90 + delete_drafts_older_than_n_days: 180 tos_topic_id: default: -1 diff --git a/spec/models/draft_spec.rb b/spec/models/draft_spec.rb index 55cd3ac82a4..ab1b0ff185b 100644 --- a/spec/models/draft_spec.rb +++ b/spec/models/draft_spec.rb @@ -34,7 +34,7 @@ describe Draft do expect(Draft.get(@user, "test", 1)).to eq "hello" end - it 'can cleanup old' do + it 'can cleanup old drafts' do user = Fabricate(:user) key = Draft::NEW_TOPIC @@ -55,6 +55,13 @@ describe Draft do Draft.cleanup! expect(Draft.count).to eq 1 + + # should cleanup drafts more than 180 days old + SiteSetting.stubs(:delete_drafts_older_than_n_days).returns(180) + + Draft.last.update_columns(updated_at: 200.days.ago) + Draft.cleanup! + expect(Draft.count).to eq 0 end