Squashed commit of the following:
commit c8f7c2c2c489708c16e4eef584f45995576e2ce8 Author: Martin Edenhofer <me@edenhofer.de> Date: Mon Sep 5 23:23:21 2016 +0200 Introduced Transaction.execute.
This commit is contained in:
parent
703ccd150f
commit
be67419379
8 changed files with 67 additions and 69 deletions
|
@ -419,14 +419,13 @@ retrns
|
||||||
|
|
||||||
# set interface handle
|
# set interface handle
|
||||||
original_interface_handle = ApplicationHandleInfo.current
|
original_interface_handle = ApplicationHandleInfo.current
|
||||||
ApplicationHandleInfo.current = "#{original_interface_handle}.postmaster"
|
|
||||||
|
|
||||||
ticket = nil
|
ticket = nil
|
||||||
article = nil
|
article = nil
|
||||||
session_user = nil
|
session_user = nil
|
||||||
|
|
||||||
# use transaction
|
# use transaction
|
||||||
ActiveRecord::Base.transaction do
|
Transaction.execute(interface_handle: "#{original_interface_handle}.postmaster") do
|
||||||
|
|
||||||
# get sender user
|
# get sender user
|
||||||
session_user_id = mail[ 'x-zammad-session-user-id'.to_sym ]
|
session_user_id = mail[ 'x-zammad-session-user-id'.to_sym ]
|
||||||
|
@ -552,11 +551,6 @@ retrns
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ApplicationHandleInfo.current = original_interface_handle
|
|
||||||
|
|
||||||
# execute object transaction
|
|
||||||
Observer::Transaction.commit
|
|
||||||
|
|
||||||
# run postmaster post filter
|
# run postmaster post filter
|
||||||
filters = {}
|
filters = {}
|
||||||
Setting.where(area: 'Postmaster::PostFilter').order(:name).each { |setting|
|
Setting.where(area: 'Postmaster::PostFilter').order(:name).each { |setting|
|
||||||
|
|
|
@ -40,16 +40,8 @@ class Job < ApplicationModel
|
||||||
|
|
||||||
if tickets
|
if tickets
|
||||||
tickets.each do |ticket|
|
tickets.each do |ticket|
|
||||||
|
Transaction.execute(disable_notification: job.disable_notification, reset_user_id: true) do
|
||||||
# use transaction
|
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
UserInfo.current_user_id = 1
|
|
||||||
ticket.perform_changes(job.perform, 'job')
|
ticket.perform_changes(job.perform, 'job')
|
||||||
|
|
||||||
# execute object transaction
|
|
||||||
Observer::Transaction.commit(
|
|
||||||
disable_notification: job.disable_notification
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Observer::Ticket::OnlineNotificationSeen::BackgroundJob
|
||||||
def perform
|
def perform
|
||||||
|
|
||||||
# set all online notifications to seen
|
# set all online notifications to seen
|
||||||
ActiveRecord::Base.transaction do
|
Transaction.execute do
|
||||||
ticket = Ticket.lookup(id: @ticket_id)
|
ticket = Ticket.lookup(id: @ticket_id)
|
||||||
OnlineNotification.list_by_object('Ticket', @ticket_id).each { |notification|
|
OnlineNotification.list_by_object('Ticket', @ticket_id).each { |notification|
|
||||||
next if notification.seen
|
next if notification.seen
|
||||||
|
|
|
@ -160,15 +160,12 @@ returns
|
||||||
.where('pending_time <= ?', Time.zone.now)
|
.where('pending_time <= ?', Time.zone.now)
|
||||||
|
|
||||||
tickets.each { |ticket|
|
tickets.each { |ticket|
|
||||||
ticket.state_id = next_state_map[ticket.state_id]
|
Transaction.execute do
|
||||||
ticket.updated_at = Time.zone.now
|
ticket.state_id = next_state_map[ticket.state_id]
|
||||||
ticket.updated_by_id = 1
|
ticket.updated_at = Time.zone.now
|
||||||
ticket.save!
|
ticket.updated_by_id = 1
|
||||||
|
ticket.save!
|
||||||
# we do not have an destructor at this point, so we need to
|
end
|
||||||
# execute object transaction manually
|
|
||||||
Observer::Transaction.commit
|
|
||||||
|
|
||||||
result.push ticket
|
result.push ticket
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -285,46 +282,50 @@ returns
|
||||||
def merge_to(data)
|
def merge_to(data)
|
||||||
|
|
||||||
# update articles
|
# update articles
|
||||||
Ticket::Article.where(ticket_id: id).each(&:touch)
|
Transaction.execute do
|
||||||
|
|
||||||
# quiet update of reassign of articles
|
Ticket::Article.where(ticket_id: id).each(&:touch)
|
||||||
Ticket::Article.where(ticket_id: id).update_all(['ticket_id = ?', data[:ticket_id] ])
|
|
||||||
|
|
||||||
# touch new ticket (to broadcast change)
|
# quiet update of reassign of articles
|
||||||
Ticket.find(data[:ticket_id]).touch
|
Ticket::Article.where(ticket_id: id).update_all(['ticket_id = ?', data[:ticket_id]])
|
||||||
|
|
||||||
# update history
|
# update history
|
||||||
|
|
||||||
# create new merge article
|
# create new merge article
|
||||||
Ticket::Article.create(
|
Ticket::Article.create(
|
||||||
ticket_id: id,
|
ticket_id: id,
|
||||||
type_id: Ticket::Article::Type.lookup(name: 'note').id,
|
type_id: Ticket::Article::Type.lookup(name: 'note').id,
|
||||||
sender_id: Ticket::Article::Sender.lookup(name: 'Agent').id,
|
sender_id: Ticket::Article::Sender.lookup(name: 'Agent').id,
|
||||||
body: 'merged',
|
body: 'merged',
|
||||||
internal: false,
|
internal: false,
|
||||||
created_by_id: data[:user_id],
|
created_by_id: data[:user_id],
|
||||||
updated_by_id: data[:user_id],
|
updated_by_id: data[:user_id],
|
||||||
)
|
)
|
||||||
|
|
||||||
# add history to both
|
# add history to both
|
||||||
|
|
||||||
# link tickets
|
# link tickets
|
||||||
Link.add(
|
Link.add(
|
||||||
link_type: 'parent',
|
link_type: 'parent',
|
||||||
link_object_source: 'Ticket',
|
link_object_source: 'Ticket',
|
||||||
link_object_source_value: data[:ticket_id],
|
link_object_source_value: data[:ticket_id],
|
||||||
link_object_target: 'Ticket',
|
link_object_target: 'Ticket',
|
||||||
link_object_target_value: id
|
link_object_target_value: id
|
||||||
)
|
)
|
||||||
|
|
||||||
# set state to 'merged'
|
# set state to 'merged'
|
||||||
self.state_id = Ticket::State.lookup(name: 'merged').id
|
self.state_id = Ticket::State.lookup(name: 'merged').id
|
||||||
|
|
||||||
# rest owner
|
# rest owner
|
||||||
self.owner_id = User.find_by(login: '-').id
|
self.owner_id = User.find_by(login: '-').id
|
||||||
|
|
||||||
# save ticket
|
# save ticket
|
||||||
save
|
save!
|
||||||
|
|
||||||
|
# touch new ticket (to broadcast change)
|
||||||
|
Ticket.find(data[:ticket_id]).touch
|
||||||
|
end
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
|
@ -1,3 +1,20 @@
|
||||||
class Transaction
|
class Transaction
|
||||||
|
def self.execute(options = {})
|
||||||
|
if options[:reset_user_id] == true
|
||||||
|
UserInfo.current_user_id = 1
|
||||||
|
end
|
||||||
|
original_interface_handle = ApplicationHandleInfo.current
|
||||||
|
if options[:interface_handle]
|
||||||
|
ApplicationHandleInfo.current = options[:interface_handle]
|
||||||
|
end
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
PushMessages.init
|
||||||
|
yield
|
||||||
|
if options[:interface_handle]
|
||||||
|
ApplicationHandleInfo.current = original_interface_handle
|
||||||
|
end
|
||||||
|
Observer::Transaction.commit(disable_notification: options[:disable_notification])
|
||||||
|
PushMessages.finish
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -285,9 +285,7 @@ result
|
||||||
ticket = nil
|
ticket = nil
|
||||||
|
|
||||||
# use transaction
|
# use transaction
|
||||||
ActiveRecord::Base.transaction do
|
Transaction.execute(reset_user_id: true) do
|
||||||
|
|
||||||
UserInfo.current_user_id = 1
|
|
||||||
existing_article = Ticket::Article.find_by(message_id: post['id'])
|
existing_article = Ticket::Article.find_by(message_id: post['id'])
|
||||||
ticket = if existing_article
|
ticket = if existing_article
|
||||||
existing_article.ticket
|
existing_article.ticket
|
||||||
|
@ -295,9 +293,6 @@ result
|
||||||
to_ticket(post, group_id, channel, page)
|
to_ticket(post, group_id, channel, page)
|
||||||
end
|
end
|
||||||
to_article(post, ticket, page)
|
to_article(post, ticket, page)
|
||||||
|
|
||||||
# execute object transaction
|
|
||||||
Observer::Transaction.commit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ticket
|
ticket
|
||||||
|
|
|
@ -6,6 +6,7 @@ module PushMessages
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.init
|
def self.init
|
||||||
|
return true if enabled?
|
||||||
Thread.current[:push_messages] = []
|
Thread.current[:push_messages] = []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ module PushMessages
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.finish
|
def self.finish
|
||||||
|
return false if !enabled?
|
||||||
Thread.current[:push_messages].each { |data|
|
Thread.current[:push_messages].each { |data|
|
||||||
Sessions.broadcast(
|
Sessions.broadcast(
|
||||||
data[:message],
|
data[:message],
|
||||||
|
@ -30,6 +32,7 @@ module PushMessages
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Thread.current[:push_messages] = nil
|
Thread.current[:push_messages] = nil
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -220,9 +220,8 @@ class TweetBase
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
|
|
||||||
UserInfo.current_user_id = 1
|
Transaction.execute(reset_user_id: true) do
|
||||||
|
|
||||||
# check if parent exists
|
# check if parent exists
|
||||||
user = to_user(tweet)
|
user = to_user(tweet)
|
||||||
|
@ -251,9 +250,6 @@ class TweetBase
|
||||||
else
|
else
|
||||||
raise "Unknown tweet type '#{tweet.class}'"
|
raise "Unknown tweet type '#{tweet.class}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
# execute object transaction
|
|
||||||
Observer::Transaction.commit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if @connection_type == 'stream'
|
if @connection_type == 'stream'
|
||||||
|
|
Loading…
Reference in a new issue