Example #1
0
 /**
  * Writes the Job object to the database. If an ID is provided this method will try to update a data set. If there
  * is no ID given, the system will create a new data set.
  *
  * @param Enlight_Components_Cron_Job $job
  * @return Enlight_Components_Cron_Adapter_Adapter
  */
 public function write(Enlight_Components_Cron_Job $job)
 {
     $data = array();
     $where = null;
     foreach ($this->_columns as $key => $value) {
         switch ($key) {
             case 'data':
                 $data[$key] = serialize($job->{$key});
                 break;
             default:
                 $data[$key] = $job->{$key};
         }
     }
     if (is_null($job->getId())) {
         $next = $job->getNext();
         if (empty($next)) {
             $job->setNext(new Zend_Date());
         }
         $start = $job->getStart();
         if (empty($start)) {
             $zd = new Zend_Date();
             $job->setStart($zd->subDay(1));
         }
         $end = $job->getEnd();
         if (empty($end)) {
             $zd = new Zend_Date();
             $job->setEnd($zd->subDay(1));
         }
         $this->insert($data);
     } else {
         $where = $this->getAdapter()->quoteInto($this->getAdapter()->quoteIdentifier($this->_primary) . ' = ?', $job->getId());
         $this->update($data, $where);
     }
     return $this;
 }
Example #2
0
 /**
  * Ends a job by handing it over to
  *
  * @param Enlight_Components_Cron_Job $job
  * @return void
  */
 protected function endJob(Enlight_Components_Cron_Job $job)
 {
     $now = new Zend_Date();
     $now = $now->getTimestamp();
     $interval = $job->getInterval();
     $next = $job->getNext()->getTimestamp();
     do {
         $next += $interval;
     } while ($now >= $next);
     $job->setNext($next);
     $job->setEnd($now);
     $this->adapter->updateJob($job);
 }
Example #3
0
 /**
  * @todo Implement testSetNext().
  */
 public function testSetNext()
 {
     $ts = new Zend_Date();
     $this->assertInstanceOf('Enlight_Components_Cron_Job', $this->job->setNext($ts));
     $this->assertEquals($ts, $this->job->getNext());
 }