/**
  * @param null $date
  */
 public function saveLastRun($date = NULL)
 {
     $dao = new CRM_Core_DAO_Job();
     $dao->id = $this->id;
     $dao->last_run = $date == NULL ? CRM_Utils_Date::currentDBDate() : CRM_Utils_Date::currentDBDate($date);
     $dao->save();
 }
Exemplo n.º 2
0
 /**
  * Function  to delete scheduled job.
  *
  * @param $jobID
  *   ID of the job to be deleted.
  *
  * @return bool|null
  */
 public static function del($jobID)
 {
     if (!$jobID) {
         CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
     }
     $dao = new CRM_Core_DAO_Job();
     $dao->id = $jobID;
     if (!$dao->find(TRUE)) {
         return NULL;
     }
     if ($dao->delete()) {
         return TRUE;
     }
 }
Exemplo n.º 3
0
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 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);
     $dao->save();
     /************************************
      * begin com.klangsoft.flexiblejobs *
      ************************************/
     $ts = strtotime($values['schedule_at']);
     if ($ts < time()) {
         $ts = null;
     }
     CRM_Core_BAO_Setting::setItem($ts ?: null, 'com.klangsoft.flexiblejobs', 'job_' . $dao->id);
     /**********************************
      * end com.klangsoft.flexiblejobs *
      **********************************/
     // 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');
     }
 }
Exemplo n.º 4
0
 /**
  * Retrieves specific job from the database by id.
  * and creates ScheduledJob object.
  *
  * @param int $id
  * @param null $entity
  * @param null $action
  *
  * @return CRM_Core_ScheduledJob
  * @throws Exception
  */
 private function _getJob($id = NULL, $entity = NULL, $action = NULL)
 {
     if (is_null($id) && is_null($action)) {
         CRM_Core_Error::fatal('You need to provide either id or name to use this method');
     }
     $dao = new CRM_Core_DAO_Job();
     $dao->id = $id;
     $dao->api_entity = $entity;
     $dao->api_action = $action;
     $dao->find();
     while ($dao->fetch()) {
         CRM_Core_DAO::storeValues($dao, $temp);
         $job = new CRM_Core_ScheduledJob($temp);
     }
     return $job;
 }
Exemplo n.º 5
0
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 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);
     $dao->save();
     /************************************
      * begin com.klangsoft.flexiblejobs *
      ************************************/
     $ts = strtotime(trim("{$values['schedule_at']} {$values['schedule_at_time']}"));
     if ($ts < time()) {
         $ts = NULL;
     } else {
         // 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));
             }
         }
     }
     CRM_Core_BAO_Setting::setItem($ts ?: NULL, 'com.klangsoft.flexiblejobs', 'job_' . $dao->id);
     /**********************************
      * end com.klangsoft.flexiblejobs *
      **********************************/
     // 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');
     }
 }
Exemplo n.º 6
0
Arquivo: Job.php Projeto: kidaa30/yes
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['job'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Exemplo n.º 7
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 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('Selected Scheduled Job has been deleted.'));
         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_prefix = $values['api_prefix'];
     $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);
     $dao->save();
 }
Exemplo n.º 8
0
 /**
  * adds $value['foo_display'] for each $value['foo'] enum from civicrm_job
  *
  * @param array $values (reference)  the array up for enhancing
  * @return void
  */
 static function addDisplayEnums(&$values)
 {
     $enumFields =& CRM_Core_DAO_Job::getEnums();
     foreach ($enumFields as $enum) {
         if (isset($values[$enum])) {
             $values[$enum . '_display'] = CRM_Core_DAO_Job::tsEnum($enum, $values[$enum]);
         }
     }
 }