if (!empty($this->id)) {
if ($hook) {
$preEvent = new \Civi\Core\DAO\Event\PreUpdate($this);
- \Civi::service('dispatcher')->dispatch("civi.dao.preUpdate", $preEvent);
+ \Civi::dispatcher()->dispatch("civi.dao.preUpdate", $preEvent);
}
$result = $this->update();
if ($hook) {
$event = new \Civi\Core\DAO\Event\PostUpdate($this, $result);
- \Civi::service('dispatcher')->dispatch("civi.dao.postUpdate", $event);
+ \Civi::dispatcher()->dispatch("civi.dao.postUpdate", $event);
}
$this->clearDbColumnValueCache();
}
else {
if ($hook) {
$preEvent = new \Civi\Core\DAO\Event\PreUpdate($this);
- \Civi::service('dispatcher')->dispatch("civi.dao.preInsert", $preEvent);
+ \Civi::dispatcher()->dispatch("civi.dao.preInsert", $preEvent);
}
$result = $this->insert();
if ($hook) {
$event = new \Civi\Core\DAO\Event\PostUpdate($this, $result);
- \Civi::service('dispatcher')->dispatch("civi.dao.postInsert", $event);
+ \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();
if (!$blockCopyofCustomValues) {
$newObject->copyCustomFields($object->id, $newObject->id);
}
- CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName(str_replace('_BAO_', '_DAO_', $daoName)), $newObject->id, $newObject);
+ CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName($daoName), $newObject->id, $newObject);
}
return $newObject;
*
* Refer to CRM-17454 for information on the danger of querying the information
* schema to derive this.
+ *
+ * @throws \CiviCRM_API3_Exception
*/
public static function getReferencesToContactTable() {
if (isset(\Civi::$statics[__CLASS__]) && isset(\Civi::$statics[__CLASS__]['contact_references'])) {
}
self::appendCustomTablesExtendingContacts($contactReferences);
self::appendCustomContactReferenceFields($contactReferences);
-
- // FixME for time being adding below line statically as no Foreign key constraint defined for table 'civicrm_entity_tag'
- $contactReferences['civicrm_entity_tag'][] = 'entity_id';
\Civi::$statics[__CLASS__]['contact_references'] = $contactReferences;
return \Civi::$statics[__CLASS__]['contact_references'];
}
+ /**
+ * Get all dynamic references to the given table.
+ *
+ * @param string $tableName
+ *
+ * @return array
+ */
+ public static function getDynamicReferencesToTable($tableName) {
+ if (!isset(\Civi::$statics[__CLASS__]['contact_references_dynamic'][$tableName])) {
+ \Civi::$statics[__CLASS__]['contact_references_dynamic'][$tableName] = [];
+ $coreReferences = CRM_Core_DAO::getReferencesToTable($tableName);
+ foreach ($coreReferences as $coreReference) {
+ if ($coreReference instanceof \CRM_Core_Reference_Dynamic) {
+ \Civi::$statics[__CLASS__]['contact_references_dynamic'][$tableName][$coreReference->getReferenceTable()][] = $coreReference->getReferenceKey();
+ }
+ }
+ }
+ return \Civi::$statics[__CLASS__]['contact_references_dynamic'][$tableName];
+ }
+
/**
* Add custom tables that extend contacts to the list of contact references.
*