CRM-20958 - Create case-activity triggers (to update case when activity changes)
authorTim Otten <totten@civicrm.org>
Thu, 27 Jul 2017 03:40:26 +0000 (20:40 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 6 Sep 2017 17:41:02 +0000 (10:41 -0700)
Civi/Core/Container.php

index 85f6120460e07627f6307fb7fa546e5ad1907507..75d95000178e578c26ccc9d2ef71e7ef6f4180fa 100644 (file)
@@ -218,6 +218,29 @@ class Container {
       array('civicrm_case', 'Case')
     ))->addTag('kernel.event_listener', array('event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo'));
 
+    $container->setDefinition('civi.case.staticTriggers', new Definition(
+      'Civi\Core\SqlTrigger\StaticTriggers',
+      array(
+        array(
+          array(
+            'upgrade_check' => array('table' => 'civicrm_case', 'column' => 'modified_date'),
+            'table' => 'civicrm_case_activity',
+            'when' => 'AFTER',
+            'event' => array('INSERT'),
+            'sql' => "\nUPDATE civicrm_case SET modified_date = CURRENT_TIMESTAMP WHERE id = NEW.case_id;\n",
+          ),
+          array(
+            'upgrade_check' => array('table' => 'civicrm_case', 'column' => 'modified_date'),
+            'table' => 'civicrm_activity',
+            'when' => 'BEFORE',
+            'event' => array('UPDATE', 'DELETE'),
+            'sql' => "\nUPDATE civicrm_case SET modified_date = CURRENT_TIMESTAMP WHERE id IN (SELECT ca.case_id FROM civicrm_case_activity ca WHERE ca.activity_id = OLD.id);\n",
+          ),
+        ),
+      )
+    ))
+      ->addTag('kernel.event_listener', array('event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo'));
+
     $container->setDefinition('civi_token_compat', new Definition(
       'Civi\Token\TokenCompatSubscriber',
       array()