/**
* Identify any enabled/disabled modules. Add new entities, update
* existing entities, and remove orphaned (stale) entities.
+ * @param bool $ignoreUpgradeMode
*
* @throws Exception
*/
- public function reconcile() {
+ public function reconcile($ignoreUpgradeMode = FALSE) {
+ // Do not reconcile whilst we are in upgrade mode
+ if (CRM_Core_Config::singleton()->isUpgradeMode() && !$ignoreUpgradeMode) {
+ return;
+ }
if ($error = $this->validate($this->getDeclarations())) {
throw new Exception($error);
}
}
/**
- * Update an entity which (a) is believed to exist and which (b) ought to be active.
+ * Update an entity which is believed to exist.
*
* @param CRM_Core_DAO_Managed $dao
* @param array $todo
$doUpdate = ($policy == 'always');
if ($doUpdate) {
- $defaults = [
- 'id' => $dao->entity_id,
- 'is_active' => 1, // FIXME: test whether is_active is valid
- ];
+ $defaults = ['id' => $dao->entity_id, 'is_active' => 1];
$params = array_merge($defaults, $todo['params']);
+
+ $manager = CRM_Extension_System::singleton()->getManager();
+ if ($dao->entity_type === 'Job' && !$manager->extensionIsBeingInstalledOrEnabled($dao->module)) {
+ // Special treatment for scheduled jobs:
+ //
+ // If we're being called as part of enabling/installing a module then
+ // we want the default behaviour of setting is_active = 1.
+ //
+ // However, if we're just being called by a normal cache flush then we
+ // should not re-enable a job that an administrator has decided to disable.
+ //
+ // Without this logic there was a problem: site admin might disable
+ // a job, but then when there was a flush op, the job was re-enabled
+ // which can cause significant embarrassment, depending on the job
+ // ("Don't worry, sending mailings is disabled right now...").
+ unset($params['is_active']);
+ }
+
$result = civicrm_api($dao->entity_type, 'create', $params);
if ($result['is_error']) {
$this->onApiError($dao->entity_type, 'create', $params, $result);