/**
* Get an instance
+ * @param bool $fresh
+ * @return \CRM_Core_ManagedEntities
*/
public static function singleton($fresh = FALSE) {
static $singleton;
/**
* 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 () {
}
/**
- * @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;
}
}
$this->onApiError($dao->entity_type, 'getsingle', $params, $result);
}
return $result;
- } else {
+ }
+ else {
return NULL;
}
}
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]");
}
}
* 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();
// 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);
}
/**
* 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']);
* 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');
case 'unused':
$getRefCount = civicrm_api3($dao->entity_type, 'getrefcount', array(
'debug' => 1,
- 'id' => $dao->entity_id
+ 'id' => $dao->entity_id,
));
$total = 0;
}
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_managed WHERE id = %1', array(
- 1 => array($dao->id, 'Integer')
+ 1 => array($dao->id, 'Integer'),
));
}
}