Moved to global Observer::Transaction.commit which executes model based transitions.

This commit is contained in:
Martin Edenhofer 2016-04-14 09:17:13 +02:00
parent ef64d1e1d7
commit 6d02578d61
11 changed files with 109 additions and 97 deletions

View file

@ -51,7 +51,7 @@ class ApplicationController < ActionController::Base
# execute events
def trigger_events
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
end
# Finds the User with the ID stored in the session with the key

View file

@ -486,8 +486,8 @@ retrns
end
end
# execute ticket notification events
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
# run postmaster post filter
Setting.where(area: 'Postmaster::PostFilter').order(:name).each {|setting|

View file

@ -60,10 +60,10 @@ class Job < ApplicationModel
next if !changed
ticket.save
# execute ticket notification events
if !job.disable_notification
Observer::Ticket::Notification.transaction
end
# execute ticket transaction
Observer::Ticket::Transaction.commit(
disable_notification: job.disable_notification
)
end
end
end

View file

@ -6,7 +6,9 @@ require 'notification_factory'
class Observer::Ticket::Notification < ActiveRecord::Observer
observe :ticket, 'ticket::_article'
def self.transaction
def self.transaction(params)
return if params[:disable_notification]
# return if we run import mode
return if Setting.get('import_mode')

View file

@ -0,0 +1,10 @@
class Observer::Transaction
def self.commit(params = {})
# execute ticket transactions
Observer::Ticket::Notification.transaction(params)
end
end

View file

@ -157,8 +157,8 @@ returns
ticket.save!
# we do not have an destructor at this point, so we need to
# execute ticket events manually
Observer::Ticket::Notification.transaction
# execute object transaction manually
Observer::Transaction.commit
result.push ticket
}
@ -473,7 +473,7 @@ condition example
end
# validate pre_condition values
return nil if selector['pre_condition'] && selector['pre_condition'] !~ /^(set|current_user\.|specific)/
return nil if selector['pre_condition'] && selector['pre_condition'] !~ /^(not_set|current_user\.|specific)/
# get attributes
attributes = attribute.split(/\./)
@ -484,7 +484,7 @@ condition example
end
if selector['operator'] == 'is'
if selector['pre_condition'] == 'set'
if selector['pre_condition'] == 'not_set'
if attributes[1] =~ /^(created_by|updated_by|owner|customer|user)_id/
query += "#{attribute} NOT IN (?)"
bind_params.push 1
@ -511,7 +511,7 @@ condition example
# rubocop:enable Style/IfInsideElse
end
elsif selector['operator'] == 'is not'
if selector['pre_condition'] == 'set'
if selector['pre_condition'] == 'not_set'
if attributes[1] =~ /^(created_by|updated_by|owner|customer|user)_id/
query += "#{attribute} IN (?)"
bind_params.push 1

View file

@ -296,8 +296,8 @@ result
end
to_article(post, ticket, page)
# execute ticket events
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
end
ticket

View file

@ -235,8 +235,8 @@ class TweetBase
raise "Unknown tweet type '#{tweet.class}'"
end
# execute ticket events
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
end
if @connection_type == 'stream'

View file

@ -171,8 +171,8 @@ class HistoryTest < ActiveSupport::TestCase
end
end
# execute ticket events
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
# execute background jobs
Delayed::Worker.new.work_off

View file

@ -60,8 +60,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
tickets = []
tickets.push ticket1
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -79,8 +79,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
updated_by_id: customer_user.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -117,8 +117,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
tickets = []
tickets.push ticket2
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -136,8 +136,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
updated_by_id: customer_user.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -173,8 +173,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# remember ticket
tickets.push ticket3
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -192,8 +192,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
updated_by_id: customer_user.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -217,8 +217,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
internal: false
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -256,8 +256,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# remember ticket
tickets.push ticket4
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -275,8 +275,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
updated_by_id: customer_user.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -312,8 +312,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
# remember ticket
tickets.push ticket5
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -331,8 +331,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase
updated_by_id: customer_user.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off

View file

@ -85,9 +85,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
)
assert(ticket1)
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = nil
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -120,9 +120,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
)
assert(ticket1)
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = true
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -158,9 +158,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
)
assert( ticket1, 'ticket created - ticket notification simple' )
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = true
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -173,8 +173,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket1.priority = Ticket::Priority.lookup(name: '3 high')
ticket1.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -195,8 +195,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: agent1.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -220,8 +220,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: agent1.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -254,8 +254,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: agent1.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
assert(ticket2, 'ticket created')
@ -270,8 +270,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket2.priority = Ticket::Priority.lookup(name: '3 high')
ticket2.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -285,8 +285,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket2.priority = Ticket::Priority.lookup(name: '2 normal')
ticket2.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -319,8 +319,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: agent2.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
assert(ticket3, 'ticket created')
@ -335,8 +335,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket3.priority = Ticket::Priority.lookup(name: '3 high')
ticket3.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -350,8 +350,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket3.priority = Ticket::Priority.lookup(name: '2 normal')
ticket3.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -363,8 +363,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
article_inbound.internal = true
article_inbound.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -425,9 +425,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: customer.id,
)
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -440,8 +440,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket1.priority = Ticket::Priority.lookup(name: '3 high')
ticket1.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -474,8 +474,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: customer.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -488,8 +488,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket2.priority = Ticket::Priority.lookup(name: '3 high')
ticket2.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -522,8 +522,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: customer.id,
)
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -536,8 +536,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket3.priority = Ticket::Priority.lookup(name: '3 high')
ticket3.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -587,9 +587,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: customer.id,
)
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -602,8 +602,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket4.priority = Ticket::Priority.lookup(name: '3 high')
ticket4.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -653,9 +653,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: customer.id,
)
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -668,8 +668,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket5.priority = Ticket::Priority.lookup(name: '3 high')
ticket5.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -720,9 +720,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: customer.id,
)
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -737,8 +737,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket6.priority = Ticket::Priority.lookup(name: '3 high')
ticket6.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -799,9 +799,9 @@ class TicketNotificationTest < ActiveSupport::TestCase
created_by_id: customer.id,
)
# execute ticket transaction
# execute object transaction
Rails.configuration.webserver_is_active = false
Observer::Ticket::Notification.transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -816,8 +816,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
ticket7.priority = Ticket::Priority.lookup(name: '3 high')
ticket7.save
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
#puts Delayed::Job.all.inspect
Delayed::Worker.new.work_off
@ -856,8 +856,8 @@ class TicketNotificationTest < ActiveSupport::TestCase
)
assert(ticket1, 'ticket created')
# execute ticket transaction
Observer::Ticket::Notification.transaction
# execute object transaction
Observer::Transaction.commit
# update ticket attributes
ticket1.title = "#{ticket1.title} - #2"