* @return array
*/
public static function getCleanupOptions() {
- return array(
+ return [
'always' => ts('Always'),
'never' => ts('Never'),
'unused' => ts('If Unused'),
- );
+ ];
}
/**
function () {
CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
},
- array(),
+ [],
'ManagedEntities::reconcile'
);
}
$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);
* 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]));
}
$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']) {
// 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);
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) {
}
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);
$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'],
+ ]);
}
}
*/
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());
* indexed by is_active,name
*/
protected static function createModuleIndex($modules) {
- $result = array();
+ $result = [];
foreach ($modules as $module) {
$result[$module->is_active][$module->name] = $module;
}
* 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) {
*/
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");
* @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']);
}