X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FManagedEntities.php;h=a3883286963a35fd7e1eef88b2c2655905ab25e3;hb=42b1aab33d897bac0413864358943caf39d60338;hp=5021859b01c0ef9a2cbabd1fa397aa7f369d5a34;hpb=43ab26fc5cbf60138b3ed1eb7444601333f8ab83;p=civicrm-core.git diff --git a/CRM/Core/ManagedEntities.php b/CRM/Core/ManagedEntities.php index 5021859b01..a388328696 100644 --- a/CRM/Core/ManagedEntities.php +++ b/CRM/Core/ManagedEntities.php @@ -13,11 +13,11 @@ class CRM_Core_ManagedEntities { * @return array */ public static function getCleanupOptions() { - return array( + return [ 'always' => ts('Always'), 'never' => ts('Never'), 'unused' => ts('If Unused'), - ); + ]; } /** @@ -55,7 +55,7 @@ class CRM_Core_ManagedEntities { function () { CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); }, - array(), + [], 'ManagedEntities::reconcile' ); } @@ -92,9 +92,9 @@ class CRM_Core_ManagedEntities { $dao->module = $moduleName; $dao->name = $name; if ($dao->find(TRUE)) { - $params = array( + $params = [ 'id' => $dao->entity_id, - ); + ]; $result = NULL; try { $result = civicrm_api3($dao->entity_type, 'getsingle', $params); @@ -191,6 +191,7 @@ class CRM_Core_ManagedEntities { $in = CRM_Core_DAO::escapeStrings(array_keys($this->moduleIndex[FALSE])); $dao = new CRM_Core_DAO_Managed(); $dao->whereAdd("module in ($in)"); + $dao->orderBy('id DESC'); $dao->find(); while ($dao->fetch()) { $this->disableEntity($dao); @@ -203,7 +204,7 @@ class CRM_Core_ManagedEntities { * unknown modules. */ public function reconcileUnknownModules() { - $knownModules = array(); + $knownModules = []; if (array_key_exists(0, $this->moduleIndex) && is_array($this->moduleIndex[0])) { $knownModules = array_merge($knownModules, array_keys($this->moduleIndex[0])); } @@ -215,6 +216,7 @@ class CRM_Core_ManagedEntities { if (!empty($knownModules)) { $in = CRM_Core_DAO::escapeStrings($knownModules); $dao->whereAdd("module NOT IN ($in)"); + $dao->orderBy('id DESC'); } $dao->find(); while ($dao->fetch()) { @@ -255,10 +257,11 @@ class CRM_Core_ManagedEntities { $doUpdate = ($policy == 'always'); if ($doUpdate) { - $defaults = array( + $defaults = [ 'id' => $dao->entity_id, - 'is_active' => 1, // FIXME: test whether is_active is valid - ); + // FIXME: test whether is_active is valid + 'is_active' => 1, + ]; $params = array_merge($defaults, $todo['params']); $result = civicrm_api($dao->entity_type, 'create', $params); if ($result['is_error']) { @@ -282,11 +285,11 @@ class CRM_Core_ManagedEntities { // FIXME: if ($dao->entity_type supports is_active) { if (TRUE) { // FIXME cascading for payproc types? - $params = array( + $params = [ 'version' => 3, 'id' => $dao->entity_id, 'is_active' => 0, - ); + ]; $result = civicrm_api($dao->entity_type, 'create', $params); if ($result['is_error']) { $this->onApiError($dao->entity_type, 'create', $params, $result); @@ -312,10 +315,10 @@ class CRM_Core_ManagedEntities { break; case 'unused': - $getRefCount = civicrm_api3($dao->entity_type, 'getrefcount', array( + $getRefCount = civicrm_api3($dao->entity_type, 'getrefcount', [ 'debug' => 1, 'id' => $dao->entity_id, - )); + ]); $total = 0; foreach ($getRefCount['values'] as $refCount) { @@ -330,21 +333,20 @@ class CRM_Core_ManagedEntities { } if ($doDelete) { - $params = array( + $params = [ 'version' => 3, 'id' => $dao->entity_id, - ); + ]; $check = civicrm_api3($dao->entity_type, 'get', $params); if ((bool) $check['count']) { $result = civicrm_api($dao->entity_type, 'delete', $params); if ($result['is_error']) { $this->onApiError($dao->entity_type, 'delete', $params, $result); } - - CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', array( - 1 => array($dao->id, 'Integer'), - )); } + CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', [ + 1 => [$dao->id, 'Integer'], + ]); } } @@ -355,7 +357,7 @@ class CRM_Core_ManagedEntities { */ public function getDeclarations() { if ($this->declarations === NULL) { - $this->declarations = array(); + $this->declarations = []; foreach (CRM_Core_Component::getEnabledComponents() as $component) { /** @var CRM_Core_Component_Info $component */ $this->declarations = array_merge($this->declarations, $component->getManagedEntities()); @@ -374,7 +376,7 @@ class CRM_Core_ManagedEntities { * indexed by is_active,name */ protected static function createModuleIndex($modules) { - $result = array(); + $result = []; foreach ($modules as $module) { $result[$module->is_active][$module->name] = $module; } @@ -389,14 +391,14 @@ class CRM_Core_ManagedEntities { * indexed by module,name */ protected static function createDeclarationIndex($moduleIndex, $declarations) { - $result = array(); + $result = []; if (!isset($moduleIndex[TRUE])) { return $result; } foreach ($moduleIndex[TRUE] as $moduleName => $module) { if ($module->is_active) { // need an empty array() for all active modules, even if there are no current $declarations - $result[$moduleName] = array(); + $result[$moduleName] = []; } } foreach ($declarations as $declaration) { @@ -413,7 +415,7 @@ class CRM_Core_ManagedEntities { */ protected static function validate($declarations) { foreach ($declarations as $declare) { - foreach (array('name', 'module', 'entity', 'params') as $key) { + foreach (['name', 'module', 'entity', 'params'] as $key) { if (empty($declare[$key])) { $str = print_r($declare, TRUE); return ("Managed Entity is missing field \"$key\": $str"); @@ -447,12 +449,12 @@ class CRM_Core_ManagedEntities { * @throws Exception */ protected function onApiError($entity, $action, $params, $result) { - CRM_Core_Error::debug_var('ManagedEntities_failed', array( + CRM_Core_Error::debug_var('ManagedEntities_failed', [ 'entity' => $entity, 'action' => $action, 'params' => $params, 'result' => $result, - )); + ]); throw new Exception('API error: ' . $result['error_message']); }