2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
module ChecksKbClientNotification
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2022-02-24 11:15:19 +00:00
|
|
|
after_commit :notify_kb_clients_after
|
2019-06-04 03:40:48 +00:00
|
|
|
|
|
|
|
class_attribute :notify_kb_clients_suspend, default: false
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.disable_in_all_classes!
|
|
|
|
all_classes.each { |klass| klass.notify_kb_clients_suspend = true }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.enable_in_all_classes!
|
|
|
|
all_classes.each { |klass| klass.notify_kb_clients_suspend = false }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.all_classes
|
|
|
|
ActiveRecord::Base
|
|
|
|
.descendants
|
|
|
|
.select { |c| c.included_modules.include?(ChecksKbClientNotification) }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# generic call
|
|
|
|
|
2022-02-24 11:15:19 +00:00
|
|
|
def notify_kb_clients_after
|
2019-06-04 03:40:48 +00:00
|
|
|
return if self.class.notify_kb_clients_suspend?
|
|
|
|
|
2022-02-24 11:15:19 +00:00
|
|
|
ChecksKbClientNotificationJob.perform_later(self.class.name, id)
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
end
|