X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FManagedEntities.php;h=a0935dcf28414dad3803ec998ab5c050588767ab;hb=5a4f674292060ff1f07ec653e2ec4bf915f6f6ef;hp=98fe3b0fef584b28056072bbf2eff063576aa63d;hpb=b2ac9e9ca74be7f852e37e0dfbf0e77627471c4d;p=civicrm-core.git diff --git a/CRM/Core/ManagedEntities.php b/CRM/Core/ManagedEntities.php index 98fe3b0fef..a0935dcf28 100644 --- a/CRM/Core/ManagedEntities.php +++ b/CRM/Core/ManagedEntities.php @@ -27,6 +27,8 @@ class CRM_Core_ManagedEntities { /** * Get an instance + * @param bool $fresh + * @return \CRM_Core_ManagedEntities */ public static function singleton($fresh = FALSE) { static $singleton; @@ -39,7 +41,7 @@ class CRM_Core_ManagedEntities { /** * Perform an asynchronous reconciliation when the transaction ends. */ - public static function scheduleReconcilation() { + public static function scheduleReconciliation() { CRM_Core_Transaction::addCallback( CRM_Core_Transaction::PHASE_POST_COMMIT, function () { @@ -51,15 +53,18 @@ class CRM_Core_ManagedEntities { } /** - * @param array $modules CRM_Core_Module - * @param array $declarations per hook_civicrm_managed + * @param array $modules + * CRM_Core_Module. + * @param array $declarations + * Per hook_civicrm_managed. */ public function __construct($modules, $declarations) { $this->moduleIndex = self::createModuleIndex($modules); if ($declarations !== NULL) { $this->declarations = self::cleanDeclarations($declarations); - } else { + } + else { $this->declarations = NULL; } } @@ -85,7 +90,8 @@ class CRM_Core_ManagedEntities { $this->onApiError($dao->entity_type, 'getsingle', $params, $result); } return $result; - } else { + } + else { return NULL; } } @@ -109,9 +115,11 @@ class CRM_Core_ManagedEntities { foreach ($decls as $moduleName => $todos) { if (isset($this->moduleIndex[TRUE][$moduleName])) { $this->reconcileEnabledModule($this->moduleIndex[TRUE][$moduleName], $todos); - } elseif (isset($this->moduleIndex[FALSE][$moduleName])) { + } + elseif (isset($this->moduleIndex[FALSE][$moduleName])) { // do nothing -- module should get swept up later - } else { + } + else { throw new Exception("Entity declaration references invalid or inactive module name [$moduleName]"); } } @@ -121,7 +129,8 @@ class CRM_Core_ManagedEntities { * Create, update, and delete entities declared by an active module * * @param \CRM_Core_Module|string $module string - * @param $todos array $name => array() + * @param array $todos + * $name => array(). */ public function reconcileEnabledModule(CRM_Core_Module $module, $todos) { $dao = new CRM_Core_DAO_Managed(); @@ -132,7 +141,8 @@ class CRM_Core_ManagedEntities { // update existing entity; remove from $todos $this->updateExistingEntity($dao, $todos[$dao->name]); unset($todos[$dao->name]); - } else { + } + else { // remove stale entity; not in $todos $this->removeStaleEntity($dao); } @@ -183,7 +193,8 @@ class CRM_Core_ManagedEntities { /** * Create a new entity * - * @param array $todo entity specification (per hook_civicrm_managedEntities) + * @param array $todo + * Entity specification (per hook_civicrm_managedEntities). */ public function insertNewEntity($todo) { $result = civicrm_api($todo['entity'], 'create', $todo['params']); @@ -204,7 +215,8 @@ class CRM_Core_ManagedEntities { * Update an entity which (a) is believed to exist and which (b) ought to be active. * * @param CRM_Core_DAO_Managed $dao - * @param array $todo entity specification (per hook_civicrm_managedEntities) + * @param array $todo + * Entity specification (per hook_civicrm_managedEntities). */ public function updateExistingEntity($dao, $todo) { $policy = CRM_Utils_Array::value('update', $todo, 'always'); @@ -267,7 +279,7 @@ class CRM_Core_ManagedEntities { case 'unused': $getRefCount = civicrm_api3($dao->entity_type, 'getrefcount', array( 'debug' => 1, - 'id' => $dao->entity_id + 'id' => $dao->entity_id, )); $total = 0; @@ -292,7 +304,7 @@ class CRM_Core_ManagedEntities { } CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', array( - 1 => array($dao->id, 'Integer') + 1 => array($dao->id, 'Integer'), )); } }