From 91dee34baec4406f9969b32bbde95a7d92cdcc17 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 23 May 2014 15:09:20 -0700 Subject: [PATCH] CRM-14478 - Allow components and hooks to influence refcounts --- CRM/Core/Component/Info.php | 13 +++++++++++++ CRM/Core/DAO.php | 6 ++++++ CRM/Utils/Hook.php | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/CRM/Core/Component/Info.php b/CRM/Core/Component/Info.php index 8278edfa38..cfdc1bb40f 100644 --- a/CRM/Core/Component/Info.php +++ b/CRM/Core/Component/Info.php @@ -171,6 +171,19 @@ abstract class CRM_Core_Component_Info { */ abstract public function getPermissions($getAllUnconditionally = FALSE); + /** + * Determine how many other records refer to a given record + * + * @param CRM_Core_DAO $dao the item for which we want a reference count + * @return array each item in the array is an array with keys: + * - name: string, eg "sql:civicrm_email:contact_id" + * - type: string, eg "sql" + * - count: int, eg "5" if there are 5 email addresses that refer to $dao + */ + public function getReferenceCounts($dao) { + return array(); + } + /** * Provides information about user dashboard element * offered by this component. diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index b475f23b28..764ca0a834 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1791,6 +1791,12 @@ SELECT contact_id } } + foreach (CRM_Core_Component::getEnabledComponents() as $component) { + /** @var $component CRM_Core_Component_Info */ + $counts = array_merge($counts, $component->getReferenceCounts($this)); + } + CRM_Utils_Hook::referenceCounts($this, $counts); + return $counts; } diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 4024d2668d..dfe84fa6d0 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -456,6 +456,23 @@ abstract class CRM_Utils_Hook { ); } + /** + * Determine how many other records refer to a given record + * + * @param CRM_Core_DAO $dao the item for which we want a reference count + * @param array $refCounts each item in the array is an array with keys: + * - name: string, eg "sql:civicrm_email:contact_id" + * - type: string, eg "sql" + * - count: int, eg "5" if there are 5 email addresses that refer to $dao + * @return void + */ + static function referenceCounts($dao, &$refCounts) { + return self::singleton()->invoke(2, $dao, $refCounts, + self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, + 'civicrm_referenceCounts' + ); + } + /** * This hook is called when building the amount structure for a Contribution or Event Page * -- 2.25.1