Просмотр исходного кода

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

Martin Edenhofer 9 лет назад
Родитель
Сommit
6d02578d61

+ 1 - 1
app/controllers/application_controller.rb

@@ -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

+ 2 - 2
app/models/channel/email_parser.rb

@@ -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|

+ 4 - 4
app/models/job.rb

@@ -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

+ 3 - 1
app/models/observer/ticket/notification.rb

@@ -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')

+ 10 - 0
app/models/observer/transaction.rb

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

+ 5 - 5
app/models/ticket.rb

@@ -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

+ 2 - 2
lib/facebook.rb

@@ -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

+ 2 - 2
lib/tweet_base.rb

@@ -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'

+ 2 - 2
test/unit/history_test.rb

@@ -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

+ 22 - 22
test/unit/online_notifiaction_test.rb

@@ -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
 

Некоторые файлы не были показаны из-за большого количества измененных файлов