Merge pull request #6574 from eileenmcnaughton/CRM-17070
[civicrm-core.git] / api / v3 / Job.php
index 5a0e45c738d4cf9f51436bf09495553bd2a35fcf..7c6e2c179ebafa2eaf607584a84fee025bd70993 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
@@ -178,9 +178,9 @@ function civicrm_api3_job_send_reminder($params) {
   // in that case (ie. makes it non-configurable via the UI). Another approach would be to set a default of 0
   // in the _spec function - but since that is a deprecated value it seems more contentious than this approach
   $params['rowCount'] = 0;
-  $lock = new CRM_Core_Lock('civimail.job.EmailProcessor');
+  $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.core.ActionSchedule');
   if (!$lock->isAcquired()) {
-    return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
+    return civicrm_api3_create_error('Could not acquire lock, another ActionSchedule process is running');
   }
 
   $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params), $params);
@@ -354,7 +354,7 @@ function civicrm_api3_job_process_sms($params) {
  * @return array
  */
 function civicrm_api3_job_fetch_bounces($params) {
-  $lock = new CRM_Core_Lock('civimail.job.EmailProcessor');
+  $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor');
   if (!$lock->isAcquired()) {
     return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
   }
@@ -377,7 +377,7 @@ function civicrm_api3_job_fetch_bounces($params) {
  * @return array
  */
 function civicrm_api3_job_fetch_activities($params) {
-  $lock = new CRM_Core_Lock('civimail.job.EmailProcessor');
+  $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor');
   if (!$lock->isAcquired()) {
     return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
   }
@@ -430,7 +430,7 @@ function civicrm_api3_job_process_participant($params) {
  *   true if success, else false
  */
 function civicrm_api3_job_process_membership($params) {
-  $lock = new CRM_Core_Lock('civimail.job.updateMembership');
+  $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.member.UpdateMembership');
   if (!$lock->isAcquired()) {
     return civicrm_api3_create_error('Could not acquire lock, another Membership Processing process is running');
   }
@@ -568,6 +568,8 @@ function civicrm_api3_job_cleanup($params) {
   $prevNext  = CRM_Utils_Array::value('prevNext', $params, TRUE);
   $dbCache   = CRM_Utils_Array::value('dbCache', $params, FALSE);
   $memCache  = CRM_Utils_Array::value('memCache', $params, FALSE);
+  $tplCache  = CRM_Utils_Array::value('tplCache', $params, FALSE);
+  $wordRplc  = CRM_Utils_Array::value('wordRplc', $params, FALSE);
 
   if ($session || $tempTable || $prevNext) {
     CRM_Core_BAO_Cache::cleanup($session, $tempTable, $prevNext);
@@ -577,6 +579,11 @@ function civicrm_api3_job_cleanup($params) {
     CRM_Core_BAO_Job::cleanup();
   }
 
+  if ($tplCache) {
+    $config = CRM_Core_Config::singleton();
+    $config->cleanup(1, FALSE);
+  }
+
   if ($dbCache) {
     CRM_Core_Config::clearDBCache();
   }
@@ -584,6 +591,10 @@ function civicrm_api3_job_cleanup($params) {
   if ($memCache) {
     CRM_Utils_System::flushCache();
   }
+
+  if ($wordRplc) {
+    CRM_Core_BAO_WordReplacement::rebuild();
+  }
 }
 
 /**
@@ -616,7 +627,7 @@ function civicrm_api3_job_disable_expired_relationships($params) {
  * @throws \API_Exception
  */
 function civicrm_api3_job_group_rebuild($params) {
-  $lock = new CRM_Core_Lock('civimail.job.groupRebuild');
+  $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.core.GroupRebuild');
   if (!$lock->isAcquired()) {
     throw new API_Exception('Could not acquire lock, another EmailProcessor process is running');
   }