/**
  * Constructor
  *
  * @param Zend_Db_Table_Row_Abstract $task
  */
 public function __construct(Zend_Db_Table_Row_Abstract $task)
 {
     if (!$task->getTable() instanceof Core_Model_DbTable_Tasks) {
         throw new Core_Model_Exception(sprintf('Task must belong to the ' . 'Core_Model_DbTable_Tasks table, ' . 'given %s', get_class($task->getTable())));
     }
     $this->_task = $task;
 }
示例#2
0
 /**
  * Render the Zend_Db_Table_Row_Abstract in a table
  *
  * @param Zend_Db_Table_Row_Abstract $row
  * @param array $options
  * @return string
  */
 public function viewRow(Zend_Db_Table_Row_Abstract $row, array $options = array())
 {
     $table = $row->getTable();
     $rowData = $row->toArray();
     $ucFirst = isset($options['ucfirst']) ? (bool) $options['ucfirst'] : true;
     $showEmpty = isset($options['showEmpty']) ? (bool) $options['showEmpty'] : false;
     $tableClass = isset($options['class']) ? $options['class'] : 'ZVHViewRowTable';
     $columns = isset($options['columns']) ? (array) $options['columns'] : null;
     $xhtml = '<table class="' . $tableClass . '">';
     if (isset($options['header'])) {
         $xhtml .= '<thead>';
         $xhtml .= '    <tr><td colspan="2">' . $options['header'] . '</td></tr>';
         $xhtml .= '</thead>';
     }
     $xhtml .= '<tbody>';
     foreach ($rowData as $key => $value) {
         if (!$table->isIdentity($key) && ($columns == null || $columns != null && in_array($key, $columns)) && (!empty($value) || empty($value) && $showEmpty)) {
             $xhtml .= '<tr>';
             $xhtml .= '    <td><strong>' . ($ucFirst ? ucfirst($key) : $key) . '</strong></td>';
             $xhtml .= '    <td>' . $value . '</td>';
             $xhtml .= '</tr>';
         }
     }
     $xhtml .= '</tbody></table>';
     return $xhtml;
 }
示例#3
0
文件: Abstract.php 项目: robeendey/ce
 public function __construct(Zend_Db_Table_Row_Abstract $task)
 {
     if (!$task->getTable() instanceof Core_Model_DbTable_Tasks) {
         throw new Core_Model_Exception('Task must belong to the Core_Model_DbTable_Tasks table');
     }
     $this->_task = $task;
 }
示例#4
0
 /**
  * 
  *
  * @param Zend_Db_Table_Row_Abstract $row
  * @return void
  */
 public function postSaveRow(Zend_Db_Table_Row_Abstract $photo)
 {
     if (false === $this->_extractExif || 'Photos' != get_class($photo->getTable())) {
         return;
     }
     $exif = $photo->getTable()->readExif($photo);
     $photo->getTable()->addExif($photo, $exif);
 }
 /**
  * Constructor
  * 
  * @param Zend_Db_Table_Row_Abstract $job
  * @param Zend_Db_Table_Row_Abstract $jobType
  */
 public function __construct(Zend_Db_Table_Row_Abstract $job, $jobType = null)
 {
     if (!$job->getTable() instanceof Core_Model_DbTable_Jobs) {
         throw new Core_Model_Exception(sprintf('Job must belong to the ' . 'Core_Model_DbTable_Jobs table, ' . 'given %s', get_class($job->getTable())));
     }
     $this->_job = $job;
     if (null === $jobType) {
         // Get job info if not provided
         $jobType = Engine_Api::_()->getDbtable('jobtypes', 'core')->find($job->jobtype_id)->current();
     }
     $this->_jobType = $jobType;
     // Load persistent data
     if (!empty($job->data)) {
         $this->_data = Zend_Json::decode($job->data);
         if (!is_array($this->_data)) {
             $this->_data = array();
         }
     }
 }
示例#6
0
 /**
  * Render the Zend_Db_Table_Row_Abstract in a table
  *
  * @param Zend_Db_Table_Row_Abstract $row
  * @return string
  */
 public function viewRow(Zend_Db_Table_Row_Abstract $row, $header = null, $columns = null)
 {
     $table = $row->getTable();
     $rowData = $row->toArray();
     $xhtml = '<table class="ZVHViewRowTable">';
     if ($header) {
         $xhtml .= '<thead>';
         $xhtml .= sprintf('<tr><td colspan="2">%s</td></tr>', $header);
         $xhtml .= '</thead>';
     }
     $xhtml .= '<tbody>';
     foreach ($rowData as $key => $value) {
         if (!$table->isIdentity($key) && ($columns != null && in_array($key, $columns))) {
             $xhtml .= '<tr>';
             $xhtml .= sprintf('<td><strong>%s</strong></td>', $key);
             $xhtml .= sprintf('<td>%s</td>', $value);
             $xhtml .= '</tr>';
         }
     }
     $xhtml .= '</tbody></table>';
     return $xhtml;
 }
示例#7
0
 protected function _executeJob(Zend_Db_Table_Row_Abstract $job)
 {
     // Get job info
     $jobTypeTable = Engine_Api::_()->getDbtable('jobtypes', 'core');
     $jobType = $jobTypeTable->find($job->jobtype_id)->current();
     // Prepare data
     $data = array();
     $where = array('job_id = ?' => $job->job_id, 'state = ?' => $job->state);
     if ($job->state == 'pending') {
         $data['state'] = 'active';
         $data['started_date'] = new Zend_Db_Expr('NOW()');
         $data['modified_date'] = new Zend_Db_Expr('NOW()');
     } else {
         if ($job->state == 'sleeping') {
             $data['state'] = 'active';
             $data['modified_date'] = new Zend_Db_Expr('NOW()');
         } else {
             // wth is this?
             $this->getLog()->log('Job Execution Duplicate: ' . $jobType->title . ' ' . $job->state, Zend_Log::NOTICE);
             return;
         }
     }
     // Attempt lock
     $table = $job->getTable();
     $affected = $table->update($data, $where);
     if (1 !== $affected) {
         $this->getLog()->log('Job Execution Failed Lock: ' . $jobType->title, Zend_Log::NOTICE);
         return;
     }
     // Refresh
     $job->refresh();
     // Register fatal error handler
     if (!$this->_isShutdownRegistered) {
         register_shutdown_function(array($this, 'handleShutdown'));
         $this->_isShutdownRegistered = true;
     }
     // Signal execution
     $this->_isExecuting = true;
     $this->_executingJob = $job;
     $this->_executingJobType = $jobType;
     // Log
     if (APPLICATION_ENV == 'development') {
         $this->getLog()->log('Job Execution Start: ' . $jobType->title, Zend_Log::NOTICE);
     }
     // Initialize
     $isComplete = true;
     $wasIdle = false;
     $messages = array();
     $progress = null;
     try {
         // Check job type
         if (!$jobType || !$jobType->plugin) {
             throw new Engine_Exception(sprintf('Missing job type with ID "%1$d"', $job->jobtype_id));
         }
         // Get plugin
         $plugin = $jobTypeTable->getJobPlugin($job, $jobType);
         // Execute
         $plugin->execute();
         // Cleanup
         $isComplete = (bool) $plugin->isComplete();
         //$progress = $plugin->getProgress();
         $wasIdle = $plugin->wasIdle();
         // If job set itself to failed, it failed. Otherwise, job may have not
         // set a status
         if ($job->state == 'failed' || $job->state == 'cancelled') {
             $status = false;
         } else {
             $status = true;
         }
     } catch (Exception $e) {
         $messages[] = $e->getMessage();
         $this->getLog()->log(sprintf('Job Execution Error: [%d] [%s] %s %s', $job->job_id, $jobType->type, $jobType->title, $e->__toString()), Zend_Log::ERR);
         $status = false;
     }
     // Log
     if (APPLICATION_ENV == 'development') {
         if ($status) {
             $this->getLog()->log(sprintf('Job Execution Complete: [%d] [%s] %s', $job->job_id, $jobType->type, $jobType->title), Zend_Log::NOTICE);
         } else {
             $this->getLog()->log(sprintf('Job Execution Complete (with errors): [%d] [%s] %s', $job->job_id, $jobType->type, $jobType->title), Zend_Log::ERR);
         }
     }
     // Update job
     $job->messages .= ltrim(join("\n", $messages) . "\n", "\n");
     $job->modified_date = new Zend_Db_Expr('NOW()');
     if (!$isComplete) {
         $job->is_complete = false;
         $job->state = 'sleeping';
     } else {
         $job->is_complete = true;
         $job->state = $status ? 'completed' : 'failed';
         $job->completion_date = new Zend_Db_Expr('NOW()');
     }
     $job->save();
     // Cleanup
     $this->_executingJobType = null;
     $this->_executingJob = null;
     $this->_isExecuting = false;
 }