*/
public function save($hook = TRUE) {
if (!empty($this->id)) {
- $this->update();
+ if ($hook) {
+ $preEvent = new \Civi\Core\DAO\Event\PreUpdate($this);
+ \Civi::dispatcher()->dispatch("civi.dao.preUpdate", $preEvent);
+ }
+
+ $result = $this->update();
if ($hook) {
- $event = new \Civi\Core\DAO\Event\PostUpdate($this);
- \Civi::service('dispatcher')->dispatch("civi.dao.postUpdate", $event);
+ $event = new \Civi\Core\DAO\Event\PostUpdate($this, $result);
+ \Civi::dispatcher()->dispatch("civi.dao.postUpdate", $event);
}
$this->clearDbColumnValueCache();
}
else {
- $this->insert();
+ if ($hook) {
+ $preEvent = new \Civi\Core\DAO\Event\PreUpdate($this);
+ \Civi::dispatcher()->dispatch("civi.dao.preInsert", $preEvent);
+ }
+
+ $result = $this->insert();
if ($hook) {
- $event = new \Civi\Core\DAO\Event\PostUpdate($this);
- \Civi::service('dispatcher')->dispatch("civi.dao.postInsert", $event);
+ $event = new \Civi\Core\DAO\Event\PostUpdate($this, $result);
+ \Civi::dispatcher()->dispatch("civi.dao.postInsert", $event);
}
}
$this->free();
*/
public function delete($useWhere = FALSE) {
$preEvent = new \Civi\Core\DAO\Event\PreDelete($this);
- \Civi::service('dispatcher')->dispatch("civi.dao.preDelete", $preEvent);
+ \Civi::dispatcher()->dispatch("civi.dao.preDelete", $preEvent);
$result = parent::delete($useWhere);
$event = new \Civi\Core\DAO\Event\PostDelete($this, $result);
- \Civi::service('dispatcher')->dispatch("civi.dao.postDelete", $event);
+ \Civi::dispatcher()->dispatch("civi.dao.postDelete", $event);
$this->free();
$this->clearDbColumnValueCache();
foreach ($fields as $fieldName => $fieldDef) {
$dbName = $fieldDef['name'];
$FKClassName = $fieldDef['FKClassName'] ?? NULL;
- $required = $fieldDef['required'] ?? NULL;
- if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
+ if (isset($params[$dbName]) && !is_array($params[$dbName])) {
$object->$dbName = $params[$dbName];
}
$fields = civicrm_api3('CustomField', 'get', [
'return' => ['column_name', 'custom_group_id.table_name'],
'data_type' => 'ContactReference',
+ 'options' => ['limit' => 0],
])['values'];
foreach ($fields as $field) {
$cidRefs[$field['custom_group_id.table_name']][] = $field['column_name'];