From 8498c2b77c23e72823170ec24d02fbfaa3300f7a Mon Sep 17 00:00:00 2001 From: deepak-srivastava Date: Thu, 2 Oct 2014 15:27:16 +0100 Subject: [PATCH] switch listeners to symphony style --- CRM/Core/BAO/RecurringEntity.php | 15 ++++++---- CRM/Core/DAO.php | 15 ++++++---- Civi/Core/Container.php | 3 ++ Civi/Core/DAO/Event/PostDelete.php | 44 ++++++++++++++++++++++++++++++ Civi/Core/DAO/Event/PostUpdate.php | 44 ++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 Civi/Core/DAO/Event/PostDelete.php create mode 100644 Civi/Core/DAO/Event/PostUpdate.php diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index 512b339584..0e92e02791 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -483,14 +483,14 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { * This function acts as a listener to dao->update whenever there is an update, * and propagates any changes to all related entities present in recurring entity table * - * @param object $obj An object containing data that needs to be updated + * @param object $event An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just updated * * @access public * @static * * @return void */ - static public function triggerUpdate($obj) { + static public function triggerUpdate($event) { // if DB version is earlier than 4.6 skip any processing static $currentVer = NULL; if (!$currentVer) { @@ -501,6 +501,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { } static $processedEntities = array(); + $obj =& $event->object; if (empty($obj->id) || empty($obj->__table)) { return FALSE; } @@ -554,14 +555,15 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { * This function acts as a listener to dao->save, * and creates entries for linked entities in recurring entity table * - * @param object $obj An object containing data that needs to be updated + * @param object $event An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just inserted * * @access public * @static * * @return void */ - static public function triggerSave($obj) { + static public function triggerInsert($event) { + $obj =& $event->object; if (!array_key_exists($obj->__table, self::$_linkedEntitiesInfo)) { return FALSE; } @@ -643,14 +645,14 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { /** * This function acts as a listener to dao->delete, and deletes an entry from recurring_entity table * - * @param object $obj An object containing data that needs to be updated + * @param object $event An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just deleted * * @access public * @static * * @return void */ - static public function triggerDelete($obj){ + static public function triggerDelete($event){ // if DB version is earlier than 4.6 skip any processing static $currentVer = NULL; if (!$currentVer) { @@ -661,6 +663,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { } static $processedEntities = array(); + $obj =& $event->object; if (empty($obj->id) || empty($obj->__table)) { return FALSE; } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index c5c3a5d7eb..bfdf3964c9 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -450,11 +450,15 @@ class CRM_Core_DAO extends DB_DataObject { function save() { if (!empty($this->id)) { $this->update(); - CRM_Core_BAO_RecurringEntity::triggerUpdate($this); + + $event = new \Civi\Core\DAO\Event\PostUpdate($this); + \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("DAO::post-update", $event); } else { $this->insert(); - CRM_Core_BAO_RecurringEntity::triggerSave($this); + + $event = new \Civi\Core\DAO\Event\PostUpdate($this); + \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("DAO::post-insert", $event); } $this->free(); @@ -465,9 +469,10 @@ class CRM_Core_DAO extends DB_DataObject { function delete($useWhere = FALSE) { $result = parent::delete($useWhere); - if ($result) { - CRM_Core_BAO_RecurringEntity::triggerDelete($this); - } + + $event = new \Civi\Core\DAO\Event\PostDelete($this); + \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("DAO::post-delete", $event); + return $result; } diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index faecd4b407..709bb3c0d0 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -93,6 +93,9 @@ class Container { $dispatcher->addListener('hook_civicrm_post::Case', array('\Civi\CCase\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\Civi\CCase\Events', 'delegateToXmlListeners')); $dispatcher->addListener('hook_civicrm_caseChange', array('\Civi\CCase\SequenceListener', 'onCaseChange_static')); + $dispatcher->addListener('DAO::post-insert', array('\CRM_Core_BAO_RecurringEntity', 'triggerInsert')); + $dispatcher->addListener('DAO::post-update', array('\CRM_Core_BAO_RecurringEntity', 'triggerUpdate')); + $dispatcher->addListener('DAO::post-delete', array('\CRM_Core_BAO_RecurringEntity', 'triggerDelete')); return $dispatcher; } diff --git a/Civi/Core/DAO/Event/PostDelete.php b/Civi/Core/DAO/Event/PostDelete.php new file mode 100644 index 0000000000..1fd5485cb8 --- /dev/null +++ b/Civi/Core/DAO/Event/PostDelete.php @@ -0,0 +1,44 @@ +object = $object; + } +} diff --git a/Civi/Core/DAO/Event/PostUpdate.php b/Civi/Core/DAO/Event/PostUpdate.php new file mode 100644 index 0000000000..351b752224 --- /dev/null +++ b/Civi/Core/DAO/Event/PostUpdate.php @@ -0,0 +1,44 @@ +object = $object; + } +} -- 2.25.1