Exemple #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;
 }
Exemple #2
0
 /**
  * @param Enlight_Components_Cron_Job $job
  * @return boolean
  */
 public function startJob(Enlight_Components_Cron_Job $job)
 {
     $job->setStart();
     $this->updateJob($job);
     return $this->update(array($this->_columns['end'] => null), array($this->getAdapter()->quoteIdentifier($this->_primary) . ' = ?' => $job->getId())) > 0;
 }
Exemple #3
0
 /**
  * Starts a job by handing it over to
  *
  * @param Enlight_Components_Cron_Job $job
  * @return void|bool
  */
 private function startJob(Enlight_Components_Cron_Job $job)
 {
     $nextRun = $job->getNext();
     // get next Date
     // Turn clock forward
     do {
         $nextRun->addSecond($job->getInterval());
     } while ($nextRun->compare(new Zend_Date()) >= 0);
     $job->setStart(new Zend_Date());
     $job->setEnd(null);
     try {
         $this->_adapter->updateJob($job);
         $job->setNext($nextRun);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Exemple #4
0
 /**
  * @todo Implement testSetEnd().
  */
 public function testSetEnd()
 {
     $ts = new Zend_Date();
     $this->assertInstanceOf('Enlight_Components_Cron_Job', $this->job->setStart($ts));
     $this->assertEquals($ts, $this->job->getStart());
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function startJob(Enlight_Components_Cron_Job $job)
 {
     $job->setStart();
     $this->updateJob($job);
     return $this->connection->update($this->tableName, ['end' => null], ['id' => $job->getId()]) > 0;
 }