/** * @param CRM_Core_ScheduledJob $job */ public function executeJob($job) { $this->currentJob = $job; $this->logEntry('Starting execution of ' . $job->name); $job->saveLastRun(); $singleRunParamsKey = strtolower($job->api_entity . '_' . $job->api_action); if (array_key_exists($singleRunParamsKey, $this->singleRunParams)) { $params = $this->singleRunParams[$singleRunParamsKey]; } else { $params = $job->apiParams; } try { $result = civicrm_api($job->api_entity, $job->api_action, $params); } catch (Exception $e) { $this->logEntry('Error while executing ' . $job->name . ': ' . $e->getMessage()); } $this->logEntry('Finished execution of ' . $job->name . ' with result: ' . $this->_apiResultToMessage($result)); $this->currentJob = FALSE; }
/** * Process the form submission. */ public function postProcess() { CRM_Utils_System::flushCache('CRM_Core_DAO_Job'); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_Job::del($this->_id); CRM_Core_Session::setStatus("", ts('Scheduled Job Deleted.'), "success"); return; } $values = $this->controller->exportValues($this->_name); $domainID = CRM_Core_Config::domainID(); $dao = new CRM_Core_DAO_Job(); $dao->id = $this->_id; $dao->domain_id = $domainID; $dao->run_frequency = $values['run_frequency']; $dao->parameters = $values['parameters']; $dao->name = $values['name']; $dao->api_entity = $values['api_entity']; $dao->api_action = $values['api_action']; $dao->description = $values['description']; $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0); // CRM-17686 $ts = strtotime($values['scheduled_run_date']); // if a date/time is supplied and not in the past, then set the next scheduled run... if ($ts > time()) { $dao->scheduled_run_date = CRM_Utils_Date::currentDBDate($ts); // warn about monthly/quarterly scheduling, if applicable if ($dao->run_frequency == 'Monthly' || $dao->run_frequency == 'Quarter') { $info = getdate($ts); if ($info['mday'] > 28) { CRM_Core_Session::setStatus(ts('Relative month values are calculated based on the length of month(s) that they pass through. The result will land on the same day of the month except for days 29-31 when the target month contains fewer days than the previous month. For example, if a job is scheduled to run on August 31st, the following invocation will occur on October 1st, and then the 1st of every month thereafter. To avoid this issue, please schedule Monthly and Quarterly jobs to run within the first 28 days of the month.'), ts('Warning'), 'info', array('expires' => 0)); } } } elseif ($dao->id) { $job = new CRM_Core_ScheduledJob(array('id' => $dao->id)); $job->clearScheduledRunDate(); } $dao->save(); // CRM-11143 - Give warning message if update_greetings is Enabled (is_active) since it generally should not be run automatically via execute action or runjobs url. if ($values['api_action'] == 'update_greeting' && CRM_Utils_Array::value('is_active', $values) == 1) { // pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org $docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki"); $msg = ts('The update greeting job can be very resource intensive and is typically not necessary to run on a regular basis. If you do choose to enable the job, we recommend you do not run it with the force=1 option, which would rebuild greetings on all records. Leaving that option absent, or setting it to force=0, will only rebuild greetings for contacts that do not currently have a value stored. %1', array(1 => $docLink)); CRM_Core_Session::setStatus($msg, ts('Warning: Update Greeting job enabled'), 'alert'); } }