module RedmineEventOutbox
  module Patches
    module HelpdeskTicketPatch
      def self.included(base)
        base.class_eval do
          # Local fork hook: helpdesk ticket rows carry the real customer/email
          # identity for many tickets whose Redmine issue author is Anonymous.
          after_commit :record_event_outbox_helpdesk_ticket_created, :on => :create
          after_commit :record_event_outbox_helpdesk_ticket_updated, :on => :update
        end
      end

      def record_event_outbox_helpdesk_ticket_created
        RedmineEventOutbox::Event.record_helpdesk_ticket_created(self, User.current)
      end

      def record_event_outbox_helpdesk_ticket_updated
        RedmineEventOutbox::Event.record_helpdesk_ticket_updated(self, User.current)
      end
    end
  end
end
