From 547f002f7179ae89cf246785481498f6efca48c1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 14 Jul 2017 17:20:48 +0200 Subject: [PATCH] Implemented issue #1254 - Feature Request: clear caller log. --- app/models/cti/log.rb | 18 ++++++++++++++++++ db/migrate/20170714000003_cleanup_cti_log.rb | 18 ++++++++++++++++++ db/seeds/schedulers.rb | 9 +++++++++ 3 files changed, 45 insertions(+) create mode 100644 db/migrate/20170714000003_cleanup_cti_log.rb diff --git a/app/models/cti/log.rb b/app/models/cti/log.rb index c5cdc7519..fa63b7d48 100644 --- a/app/models/cti/log.rb +++ b/app/models/cti/log.rb @@ -358,5 +358,23 @@ returns ) } end + +=begin + +cleanup caller logs + + Cti::Log.cleanup + +optional you can put the max oldest chat entries as argument + + Cti::Log.cleanup(12.months) + +=end + + def self.cleanup(diff = 12.months) + Cti::Log.where('created_at < ?', Time.zone.now - diff).delete_all + true + end + end end diff --git a/db/migrate/20170714000003_cleanup_cti_log.rb b/db/migrate/20170714000003_cleanup_cti_log.rb new file mode 100644 index 000000000..4b9e59cbe --- /dev/null +++ b/db/migrate/20170714000003_cleanup_cti_log.rb @@ -0,0 +1,18 @@ +class CleanupCtiLog < ActiveRecord::Migration + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + Scheduler.create_if_not_exists( + name: 'Cleanup Cti::Log', + method: 'Cti::Log.cleanup', + period: 1.month, + prio: 2, + active: true, + updated_by_id: 1, + created_by_id: 1, + ) + end + +end diff --git a/db/seeds/schedulers.rb b/db/seeds/schedulers.rb index 94fbe49f6..659e610f3 100644 --- a/db/seeds/schedulers.rb +++ b/db/seeds/schedulers.rb @@ -156,6 +156,15 @@ Scheduler.create_if_not_exists( updated_by_id: 1, created_by_id: 1, ) +Scheduler.create_if_not_exists( + name: 'Cleanup Cti::Log', + method: 'Cti::Log.cleanup', + period: 1.month, + prio: 2, + active: true, + updated_by_id: 1, + created_by_id: 1, +) Scheduler.create_if_not_exists( name: 'Import Jobs', method: 'ImportJob.start_registered',