FEATURE: Add site setting to delay/disable expired event post deletion

FEATURE: Add site setting to delay/disable expired event post deletion

diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index d584adc..e4123c6 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2,6 +2,7 @@ en:
   site_settings:
     calendar_enabled: "Enable the discourse-calendar plugin. This will add support for a [calendar][/calendar] tag in the first post of a topic."
     holiday_calendar_topic_id: "Topic ID of staffs holiday / absence calendar."
+    delete_expired_event_posts_after: "Posts with expired events will be automatically deleted after (n) hours. Set to -1 to disable deletion."
   discourse_calendar:
     calendar_must_be_in_first_post: "Calendar tag can only be used in first post of a topic."
     more_than_one_calendar: "You can’t have more than one calendar in a post."
diff --git a/config/settings.yml b/config/settings.yml
index e0b9fde..cf16963 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -5,3 +5,5 @@ plugins:
   holiday_calendar_topic_id:
     default: ""
     client: true
+  delete_expired_event_posts_after:
+    default: 1
diff --git a/jobs/scheduled/ensure_expired_event_destruction.rb b/jobs/scheduled/ensure_expired_event_destruction.rb
index d12ca87..84ec6e7 100644
--- a/jobs/scheduled/ensure_expired_event_destruction.rb
+++ b/jobs/scheduled/ensure_expired_event_destruction.rb
@@ -3,6 +3,10 @@ module Jobs
     every 10.minutes
 
     def execute(args)
+      delay = SiteSetting.delete_expired_event_posts_after
+
+      return if delay < 0
+
       calendar_post_ids = PostCustomField
         .where(name: ::DiscourseCalendar::CALENDAR_CUSTOM_FIELD)
         .pluck(:post_id)
@@ -26,7 +30,7 @@ module Jobs
 
           to_time = to ? Time.parse(to) : Time.parse(from) + 24.hours
 
-          if (to_time + 1.hour) < Time.zone.now
+          if (to_time + delay.hour) < Time.zone.now
             if post = pcf.post.topic.posts.find_by(post_number: post_number)
               PostDestroyer.new(Discourse.system_user, post).destroy
             end

GitHub sha: 3d66cb46

@vinothkannans can you add a test for this please ?

1 Like