public function beforeSave() { $this->newObject->set('status', sTaskRun::STATUS_SCHEDULED); $this->newObject->set('executedon', null); $this->newObject->set('errors', null); $this->newObject->set('message', null); // get timing or create one $timing = $this->getProperty('timing_new', 0); if (empty($timing)) { $timingNr = $this->getProperty('timing_number', 1); $timingInterval = $this->getProperty('timing_interval', 'minute') . ($timingNr != 1 ? 's' : ''); // to make it: minutes, hours, months.. etc. $timing = strtotime('+' . $timingNr . ' ' . $timingInterval); } if (empty($timing)) { $this->addFieldError('timing', $this->modx->lexicon('scheduler.error.no-timing')); } $this->newObject->setTiming($timing, false); return parent::beforeSave(); }
/** * @param sTaskRun $run * @return sTask $this */ public function run($run) { // Set status to executing (and save) so other triggers don't also run this one $run->set('status', sTaskRun::STATUS_EXECUTING); $run->save(); // Run the task $return = $this->_run($run); // All done! Update status, completed date and save. $run->set('status', $run->hasErrors() ? sTaskRun::STATUS_FAILURE : sTaskRun::STATUS_SUCCESS); $run->set('message', $return); $run->set('executedon', time()); $run->save(); return $this; }