X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FManagedEntities.php;h=22d9f12f82a4d065db3db11743ede9159104b1eb;hb=79caea9311cef5d5525405a24e3bcd08197eabde;hp=cf47fa6918bd14986f4c4e656c8ea927c5903ce5;hpb=1590080269b93b1f65d9f9b9211f246c38bfcfd2;p=civicrm-core.git diff --git a/CRM/Core/ManagedEntities.php b/CRM/Core/ManagedEntities.php index cf47fa6918..22d9f12f82 100644 --- a/CRM/Core/ManagedEntities.php +++ b/CRM/Core/ManagedEntities.php @@ -246,12 +246,12 @@ class CRM_Core_ManagedEntities { $dao->name = $todo['name']; $dao->entity_type = $todo['entity']; $dao->entity_id = $result['id']; - $dao->cleanup = CRM_Utils_Array::value('cleanup', $todo); + $dao->cleanup = $todo['cleanup'] ?? NULL; $dao->save(); } /** - * 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 @@ -262,12 +262,26 @@ class CRM_Core_ManagedEntities { $doUpdate = ($policy == 'always'); if ($doUpdate) { - $defaults = [ - 'id' => $dao->entity_id, - // FIXME: test whether is_active is valid - 'is_active' => 1, - ]; + $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);