/**
  * 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');
     }
 }
 /**
  * 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');
     }
 }
 function testCreateSyncScheduledJob()
 {
     $expected_job = CRM_CiviMailchimp_Utils::createSyncScheduledJob();
     $job = new CRM_Core_BAO_Job();
     $job->name = 'Sync Contacts to Mailchimp';
     $job->find(TRUE);
     $this->assertEquals($expected_job->id, $job->id);
     $this->assertEquals($expected_job->name, $job->name);
 }
 /**
  * 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();
 }
示例#5
0
/**
 * This api cleans up all the old session entries and temp tables.
 *
 * We recommend that sites run this on an hourly basis.
 *
 * @param array $params
 *   Sends in various config parameters to decide what needs to be cleaned.
 */
function civicrm_api3_job_cleanup($params)
{
    $session = CRM_Utils_Array::value('session', $params, TRUE);
    $tempTable = CRM_Utils_Array::value('tempTables', $params, TRUE);
    $jobLog = CRM_Utils_Array::value('jobLog', $params, TRUE);
    $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);
    }
    if ($jobLog) {
        CRM_Core_BAO_Job::cleanup();
    }
    if ($tplCache) {
        $config = CRM_Core_Config::singleton();
        $config->cleanup(1, FALSE);
    }
    if ($dbCache) {
        CRM_Core_Config::clearDBCache();
    }
    if ($memCache) {
        CRM_Utils_System::flushCache();
    }
    if ($wordRplc) {
        CRM_Core_BAO_WordReplacement::rebuild();
    }
}
示例#6
0
/**
 * This api cleans up all the old session entries and temp tables. We recommend that sites run this on an hourly basis
 *
 * @param  array    $params (reference ) - sends in various config parameters to decide what needs to be cleaned
 *
 * @return boolean  true if success, else false
 * @static void
 * @access public
 */
function civicrm_api3_job_cleanup($params)
{
    $session = CRM_Utils_Array::value('session', $params, true);
    $tempTable = CRM_Utils_Array::value('tempTables', $params, true);
    $jobLog = CRM_Utils_Array::value('jobLog', $params, true);
    $prevNext = CRM_Utils_Array::value('prevNext', $params, true);
    $dbCache = CRM_Utils_Array::value('dbCache', $params, false);
    $memCache = CRM_Utils_Array::value('memCache', $params, false);
    if ($session || $tempTable || $prevNext) {
        CRM_Core_BAO_Cache::cleanup($session, $tempTable, $prevNext);
    }
    if ($jobLog) {
        CRM_Core_BAO_Job::cleanup();
    }
    if ($dbCache) {
        CRM_Core_Config::clearDBCache();
    }
    if ($memCache) {
        CRM_Utils_System::flushCache();
    }
}
 /**
  * Add a Scheduled Job of Syncing from CiviCRM to Mailchimp.
  *
  * CiviCRM 4.2 does not have a BAO or API method for adding a scheduled job,
  * so we're forced to do it ourselves.
  */
 static function createSyncScheduledJob()
 {
     $domain_id = CRM_Core_Config::domainID();
     $params = array('domain_id' => $domain_id, 'run_frequency' => 'Always', 'name' => 'Sync Contacts to Mailchimp', 'description' => 'Sync CiviCRM Contacts to Mailchimp Lists.', 'api_entity' => 'CiviMailchimp', 'api_action' => 'sync', 'parameters' => 'records_to_process_per_run=100', 'is_active' => 0);
     $job = new CRM_Core_BAO_Job();
     $job->copyValues($params);
     return $job->save();
 }