projects
/
civicrm-core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #5479 from eileenmcnaughton/4.6
[civicrm-core.git]
/
CRM
/
Core
/
ManagedEntities.php
diff --git
a/CRM/Core/ManagedEntities.php
b/CRM/Core/ManagedEntities.php
index 4dbe82f381d889d00c00b3ab132a37bcb84b5a8b..4de184a28c1b1d11092c1f98481327da4c5e87f4 100644
(file)
--- a/
CRM/Core/ManagedEntities.php
+++ b/
CRM/Core/ManagedEntities.php
@@
-7,6
+7,11
@@
*/
class CRM_Core_ManagedEntities {
*/
class CRM_Core_ManagedEntities {
+ /**
+ * Get clean up options.
+ *
+ * @return array
+ */
public static function getCleanupOptions() {
return array(
'always' => ts('Always'),
public static function getCleanupOptions() {
return array(
'always' => ts('Always'),
@@
-16,17
+21,20
@@
class CRM_Core_ManagedEntities {
}
/**
}
/**
- * @var array($status => array($name => CRM_Core_Module))
+ * @var array
+ * Array($status => array($name => CRM_Core_Module)).
*/
protected $moduleIndex;
/**
*/
protected $moduleIndex;
/**
- * @var array per hook_civicrm_managed
+ * @var array
+ * List of all entity declarations.
+ * @see CRM_Utils_Hook::managed()
*/
protected $declarations;
/**
*/
protected $declarations;
/**
- * Get an instance
+ * Get an instance
.
* @param bool $fresh
* @return \CRM_Core_ManagedEntities
*/
* @param bool $fresh
* @return \CRM_Core_ManagedEntities
*/
@@
-45,7
+53,7
@@
class CRM_Core_ManagedEntities {
CRM_Core_Transaction::addCallback(
CRM_Core_Transaction::PHASE_POST_COMMIT,
function () {
CRM_Core_Transaction::addCallback(
CRM_Core_Transaction::PHASE_POST_COMMIT,
function () {
- CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
+
CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
},
array(),
'ManagedEntities::reconcile'
},
array(),
'ManagedEntities::reconcile'
@@
-70,8
+78,12
@@
class CRM_Core_ManagedEntities {
}
/**
}
/**
- * Read
the managed entity
+ * Read
a managed entity using APIv3.
*
*
+ * @param string $moduleName
+ * The name of the module which declared entity.
+ * @param string $name
+ * The symbolic name of the entity.
* @return array|NULL
* API representation, or NULL if the entity does not exist
*/
* @return array|NULL
* API representation, or NULL if the entity does not exist
*/
@@
-97,6
+109,12
@@
class CRM_Core_ManagedEntities {
}
}
}
}
+ /**
+ * Identify any enabled/disabled modules. Add new entities, update
+ * existing entities, and remove orphaned (stale) entities.
+ *
+ * @throws Exception
+ */
public function reconcile() {
if ($error = $this->validate($this->getDeclarations())) {
throw new Exception($error);
public function reconcile() {
if ($error = $this->validate($this->getDeclarations())) {
throw new Exception($error);
@@
-106,7
+124,12
@@
class CRM_Core_ManagedEntities {
$this->reconcileUnknownModules();
}
$this->reconcileUnknownModules();
}
-
+ /**
+ * For all enabled modules, add new entities, update
+ * existing entities, and remove orphaned (stale) entities.
+ *
+ * @throws Exception
+ */
public function reconcileEnabledModules() {
// Note: any thing currently declared is necessarily from
// an active module -- because we got it from a hook!
public function reconcileEnabledModules() {
// Note: any thing currently declared is necessarily from
// an active module -- because we got it from a hook!
@@
-127,11
+150,13
@@
class CRM_Core_ManagedEntities {
}
/**
}
/**
- * Create, update, and delete entities declared by an active module
+ * For one enabled module, add new entities, update existing entities,
+ * and remove orphaned (stale) entities.
*
*
- * @param \CRM_Core_Module
|string $module string
+ * @param \CRM_Core_Module
$module
* @param array $todos
* @param array $todos
- * $name => array().
+ * List of entities currently declared by this module.
+ * array(string $name => array $entityDef).
*/
public function reconcileEnabledModule(CRM_Core_Module $module, $todos) {
$dao = new CRM_Core_DAO_Managed();
*/
public function reconcileEnabledModule(CRM_Core_Module $module, $todos) {
$dao = new CRM_Core_DAO_Managed();
@@
-155,6
+180,9
@@
class CRM_Core_ManagedEntities {
}
}
}
}
+ /**
+ * For all disabled modules, disable any managed entities.
+ */
public function reconcileDisabledModules() {
if (empty($this->moduleIndex[FALSE])) {
return;
public function reconcileDisabledModules() {
if (empty($this->moduleIndex[FALSE])) {
return;
@@
-170,6
+198,10
@@
class CRM_Core_ManagedEntities {
}
}
}
}
+ /**
+ * Remove any orphaned (stale) entities that are linked to
+ * unknown modules.
+ */
public function reconcileUnknownModules() {
$knownModules = array();
if (array_key_exists(0, $this->moduleIndex) && is_array($this->moduleIndex[0])) {
public function reconcileUnknownModules() {
$knownModules = array();
if (array_key_exists(0, $this->moduleIndex) && is_array($this->moduleIndex[0])) {
@@
-177,7
+209,6
@@
class CRM_Core_ManagedEntities {
}
if (array_key_exists(1, $this->moduleIndex) && is_array($this->moduleIndex[1])) {
$knownModules = array_merge($knownModules, array_keys($this->moduleIndex[1]));
}
if (array_key_exists(1, $this->moduleIndex) && is_array($this->moduleIndex[1])) {
$knownModules = array_merge($knownModules, array_keys($this->moduleIndex[1]));
-
}
$dao = new CRM_Core_DAO_Managed();
}
$dao = new CRM_Core_DAO_Managed();
@@
-192,7
+223,7
@@
class CRM_Core_ManagedEntities {
}
/**
}
/**
- * Create a new entity
+ * Create a new entity
.
*
* @param array $todo
* Entity specification (per hook_civicrm_managedEntities).
*
* @param array $todo
* Entity specification (per hook_civicrm_managedEntities).
@@
-264,9
+295,10
@@
class CRM_Core_ManagedEntities {
}
/**
}
/**
- * Remove a stale entity (if policy allows)
+ * Remove a stale entity (if policy allows)
.
*
* @param CRM_Core_DAO_Managed $dao
*
* @param CRM_Core_DAO_Managed $dao
+ * @throws Exception
*/
public function removeStaleEntity($dao) {
$policy = empty($dao->cleanup) ? 'always' : $dao->cleanup;
*/
public function removeStaleEntity($dao) {
$policy = empty($dao->cleanup) ? 'always' : $dao->cleanup;
@@
-313,6
+345,11
@@
class CRM_Core_ManagedEntities {
}
}
}
}
+ /**
+ * Get declarations.
+ *
+ * @return array|null
+ */
public function getDeclarations() {
if ($this->declarations === NULL) {
$this->declarations = array();
public function getDeclarations() {
if ($this->declarations === NULL) {
$this->declarations = array();
@@
-327,7
+364,8
@@
class CRM_Core_ManagedEntities {
}
/**
}
/**
- * @param $modules
+ * @param array $modules
+ * Array<CRM_Core_Module>.
*
* @return array
* indexed by is_active,name
*
* @return array
* indexed by is_active,name
@@
-341,8
+379,8
@@
class CRM_Core_ManagedEntities {
}
/**
}
/**
- * @param $moduleIndex
- * @param $declarations
+ * @param
array
$moduleIndex
+ * @param
array
$declarations
*
* @return array
* indexed by module,name
*
* @return array
* indexed by module,name
@@
-414,4
+452,5
@@
class CRM_Core_ManagedEntities {
));
throw new Exception('API error: ' . $result['error_message']);
}
));
throw new Exception('API error: ' . $result['error_message']);
}
+
}
}