Example #1
0
 $select = $field->getSelect();
 $select->setSize(1);
 $select->addOption($this->i18n('status_activated'), 1);
 $select->addOption($this->i18n('status_deactivated'), 0);
 if ($func == 'add') {
     $select->setSelected(1);
 }
 $field = $form->addSelectField('type');
 $field->setLabel($this->i18n('type'));
 $select = $field->getSelect();
 $select->setSize(1);
 $typeFieldId = $field->getAttribute('id');
 $types = rex_cronjob_manager::getTypes();
 $cronjobs = [];
 foreach ($types as $class) {
     $cronjob = rex_cronjob::factory($class);
     if ($cronjob instanceof rex_cronjob) {
         $cronjobs[$class] = $cronjob;
         $select->addOption($cronjob->getTypeName(), $class);
     }
 }
 if ($func == 'add') {
     $select->setSelected('rex_cronjob_phpcode');
 }
 $activeType = $field->getValue();
 if ($func != 'add' && !in_array($activeType, $types)) {
     if (!$activeType && !$field->getValue()) {
         $warning = rex_i18n::rawMsg('cronjob_not_found');
     } else {
         $warning = rex_i18n::rawMsg('cronjob_type_not_found', $field->getValue(), $activeType);
     }
 function tryExecute($query_or_id, $log = true)
 {
     global $REX;
     if (is_int($query_or_id)) {
         $environment = (int) $REX['REDAXO'];
         $this->sql->setQuery('
             SELECT    id, name, type, parameters, `interval`
             FROM      ' . REX_CRONJOB_TABLE . '
             WHERE     id=' . $query_or_id . ' AND environment LIKE "%|' . $environment . '|%"
             LIMIT     1
         ');
     } else {
         $this->sql->setQuery($query_or_id);
     }
     if ($this->sql->getRows() != 1) {
         $success = false;
         $this->manager->setMessage('Cronjob not found in database');
         $this->manager->saveNextTime($this->getMinNextTime());
     } else {
         $id = $this->sql->getValue('id');
         $name = $this->sql->getValue('name');
         $type = $this->sql->getValue('type');
         $params = unserialize($this->sql->getValue('parameters'));
         $interval = $this->sql->getValue('interval');
         $nexttime = self::calculateNextTime($interval);
         $this->setNextTime($id, $nexttime);
         $this->manager->saveNextTime($this->getMinNextTime());
         $cronjob = rex_cronjob::factory($type);
         $success = $this->manager->tryExecute($cronjob, $name, $params, $log, $id);
     }
     return $success;
 }
Example #3
0
 public function tryExecuteSql(rex_sql $sql, $log = true, $resetExecutionStart = false)
 {
     if ($sql->getRows() > 0) {
         $id = $sql->getValue('id');
         $name = $sql->getValue('name');
         $type = $sql->getValue('type');
         $params = json_decode($sql->getValue('parameters'), true);
         $interval = $sql->getValue('interval');
         $cronjob = rex_cronjob::factory($type);
         $success = $this->getManager()->tryExecute($cronjob, $name, $params, $log, $id);
         $this->setNextTime($id, $interval, $resetExecutionStart);
         return $success;
     }
     return false;
 }
Example #4
0
 $fieldset = $func == 'edit' ? $I18N->msg('cronjob_edit') : $I18N->msg('cronjob_add');
 $form = rex_form::factory(REX_CRONJOB_TABLE, $fieldset, 'id = ' . $oid, 'post', false, 'rex_cronjob_form');
 $form->addParam('oid', $oid);
 $form->setApplyUrl('index.php?page=cronjob');
 $form->setEditMode($func == 'edit');
 $form->addHiddenField('nexttime');
 $field =& $form->addSelectField('type');
 $field->setLabel($I18N->msg('cronjob_type'));
 $select =& $field->getSelect();
 $select->setSize(1);
 $typeFieldId = $field->getAttribute('id');
 $types = rex_cronjob_manager::getTypes();
 $cronjobs = array();
 foreach ($types as $class) {
     $cronjob = rex_cronjob::factory($class);
     if (rex_cronjob::isValid($cronjob)) {
         $cronjobs[$class] = $cronjob;
         $select->addOption($cronjob->getTypeName(), $class);
     }
 }
 if ($func == 'add') {
     $select->setSelected('rex_cronjob_phpcode');
 }
 $activeType = $field->getValue();
 $field =& $form->addTextField('name');
 $field->setLabel($I18N->msg('cronjob_name'));
 $field->getValidator()->add('notEmpty', $I18N->msg('cronjob_error_no_name'));
 $nameFieldId = $field->getAttribute('id');
 if ($func != 'add' && !in_array($activeType, $types)) {
     if (!$activeType && !$field->getValue()) {
         $warning = $I18N->msg('cronjob_not_found');
Example #5
0
 private function tryExecuteJob(array $job, $log = true, $resetExecutionStart = false)
 {
     $params = json_decode($job['parameters'], true);
     $cronjob = rex_cronjob::factory($job['type']);
     $success = $this->getManager()->tryExecute($cronjob, $job['name'], $params, $log, $job['id']);
     $this->setNextTime($job['id'], $job['interval'], $resetExecutionStart);
     return $success;
 }