/**
  * This function creates a job for to run the SugarJobUpdateOpportunities class
  * @param integer $perJob
  * @returns array|string An array of the jobs that were created, unless there
  * is one, then just that job's id
  */
 public static function updateOpportunitiesForForecasting($perJob = 100)
 {
     $sq = new SugarQuery();
     $sq->select(array('id'));
     $sq->from(BeanFactory::getBean('Opportunities'));
     $sq->orderBy('date_closed');
     $rows = $sq->execute();
     if (empty($rows)) {
         return false;
     }
     $chunks = array_chunk($rows, $perJob);
     $jobs = array();
     // process the first job now
     $job = static::createJob($chunks[0], true);
     $jobs[] = $job->id;
     // run the first job
     $self = new self();
     $self->setJob($job);
     $self->sendNotifications = false;
     $self->run($job->data);
     $job_group = md5(microtime());
     for ($i = 1; $i < count($chunks); $i++) {
         $jobs[] = static::createJob($chunks[$i], false, $job_group);
     }
     // if only one job was created, just return that id
     if (count($jobs) == 1) {
         return array_shift($jobs);
     }
     return $jobs;
 }
Example #2
0
 /**
  * Check if task must be run at the given job time
  *
  * @example Cron::job('5 * * * 1-5')
  * 
  * @param string $time      Job in crontab style
  * @return boolean          Return true if given job is valid now
  */
 public static function job($time)
 {
     $c = new self();
     return $c->setJob($time)->execute();
 }