diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 4ac607f50..242086483 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -118,4 +118,21 @@ return all activity entries of an user list end +=begin + +cleanup old stream messages + + ActivityStream.cleanup + +optional you can parse the max oldest stream entries + + ActivityStream.cleanup(4.months) + +=end + + def self.cleanup(diff = 4.months) + ActivityStream.where('created_at < ?', Time.zone.now - diff).delete_all + true + end + end diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index 96ac1d653..808c93457 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -3,6 +3,7 @@ class OnlineNotification < ApplicationModel belongs_to :type_lookup, class_name: 'TypeLookup' belongs_to :object_lookup, class_name: 'ObjectLookup' + belongs_to :user after_create :notify_clients_after_change after_update :notify_clients_after_change @@ -188,4 +189,31 @@ returns: ) end +=begin + +cleanup old online notifications + + OnlineNotification.cleanup + +=end + + def self.cleanup + OnlineNotification.where('created_at < ?', Time.zone.now - 12.months).delete_all + OnlineNotification.where('seen = ? AND created_at < ?', true, Time.zone.now - 4.months).delete_all + + # notify all agents + users = Ticket::ScreenOptions.agents + users.each {|user| + Sessions.send_to( + user.id, + { + event: 'OnlineNotification::changed', + data: {} + } + ) + } + + true + end + end diff --git a/db/migrate/20150701000001_add_cleanup.rb b/db/migrate/20150701000001_add_cleanup.rb new file mode 100644 index 000000000..fbb0c1f56 --- /dev/null +++ b/db/migrate/20150701000001_add_cleanup.rb @@ -0,0 +1,24 @@ +class AddCleanup < ActiveRecord::Migration + def up + + # delete old entries + Scheduler.create_or_update( + name: 'Delete old activity stream entries.', + method: 'ActivityStream.cleanup', + period: 1.day, + prio: 2, + active: true, + updated_by_id: 1, + created_by_id: 1, + ) + Scheduler.create_or_update( + name: 'Delete old online notification entries.', + method: 'OnlineNotification.cleanup', + period: 1.day, + prio: 2, + active: true, + updated_by_id: 1, + created_by_id: 1, + ) + end +end