*/
public function save($hook = TRUE) {
if (!empty($this->id)) {
- $this->update();
+ if ($hook) {
+ $preEvent = new \Civi\Core\DAO\Event\PreUpdate($this);
+ \Civi::service('dispatcher')->dispatch("civi.dao.preUpdate", $preEvent);
+ }
+
+ $result = $this->update();
if ($hook) {
- $event = new \Civi\Core\DAO\Event\PostUpdate($this);
+ $event = new \Civi\Core\DAO\Event\PostUpdate($this, $result);
\Civi::service('dispatcher')->dispatch("civi.dao.postUpdate", $event);
}
$this->clearDbColumnValueCache();
}
else {
- $this->insert();
+ if ($hook) {
+ $preEvent = new \Civi\Core\DAO\Event\PreUpdate($this);
+ \Civi::service('dispatcher')->dispatch("civi.dao.preInsert", $preEvent);
+ }
+
+ $result = $this->insert();
if ($hook) {
- $event = new \Civi\Core\DAO\Event\PostUpdate($this);
+ $event = new \Civi\Core\DAO\Event\PostUpdate($this, $result);
\Civi::service('dispatcher')->dispatch("civi.dao.postInsert", $event);
}
}
*/
public $object;
+ /**
+ * @var mixed
+ */
+ public $result;
+
/**
* @param $object
+ * @param $result
*/
- public function __construct($object) {
+ public function __construct($object, $result) {
$this->object = $object;
+ $this->result = $result;
}
}
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Core\DAO\Event;
+
+/**
+ * Class PreDelete
+ * @package Civi\Core\DAO\Event
+ */
+class PreUpdate extends \Symfony\Component\EventDispatcher\Event {
+
+ /**
+ * @var \CRM_Core_DAO
+ */
+ public $object;
+
+ /**
+ * @param $object
+ */
+ public function __construct($object) {
+ $this->object = $object;
+ }
+
+}