Esempio n. 1
0
/**
 * Build cron job names SELECT query from crong_jobs_config array
 *
 * @param string What fields to get, separated by comma
 * @return string SQL query
 */
function cron_job_sql_query($fields = 'key,name')
{
    global $DB;
    $cron_jobs_config = get_cron_jobs_config();
    // We need to set the collation explicitly if the current db connection charset is utf-8 in order to avoid "Illegal mix of collation" issue
    // Basically this is a hack which should be reviewed when the charset issues are fixed generally.
    // TODO: asimo>Review this temporary solution after the charset issues were fixed.
    $default_collation = $DB->connection_charset == 'utf8' ? ' COLLATE utf8_general_ci' : '';
    $name_query = '';
    if (!empty($cron_jobs_config)) {
        $fields = explode(',', $fields);
        $name_query = 'SELECT task_' . implode(', task_', $fields) . ' FROM (' . "\n";
        $first_task = true;
        foreach ($cron_jobs_config as $ctsk_key => $ctsk_data) {
            $field_values = '';
            $field_separator = '';
            foreach ($fields as $field) {
                $field_values .= $field_separator . $DB->quote($field == 'key' ? $ctsk_key : $ctsk_data[$field]) . $default_collation . ' AS task_' . $field;
                $field_separator = ', ';
            }
            if ($first_task) {
                $name_query .= "\t" . 'SELECT ' . $field_values . "\n";
                $first_task = false;
            } else {
                $name_query .= "\t" . 'UNION SELECT ' . $field_values . "\n";
            }
        }
        $name_query .= ') AS inner_temp';
    }
    return $name_query;
}
Esempio n. 2
0
    die('Please, do not access this page directly.');
}
global $localtimenow, $edited_Cronjob;
// Determine if we are creating or updating...
global $action;
$creating = is_create_action($action);
$Form = new Form(NULL, 'cronjob');
$Form->global_icon(T_('Cancel!'), 'close', regenerate_url('action'));
$Form->begin_form('fform', $creating ? T_('New scheduled job') : T_('Edit scheduled job'));
$Form->add_crumb('crontask');
$Form->hiddens_by_key(get_memorized('action'));
$Form->hidden('action', $creating ? 'create' : 'update');
$Form->begin_fieldset(T_('Job details') . get_manual_link('scheduled-job-form'));
if ($creating && $action != 'copy') {
    // New cronjob
    $cron_jobs_names = get_cron_jobs_config('name');
    // Exclude these cron jobs from manual creating
    unset($cron_jobs_names['send-post-notifications']);
    unset($cron_jobs_names['send-comment-notifications']);
    $Form->select_input_array('cjob_type', get_param('cjob_type'), $cron_jobs_names, T_('Job type'));
} else {
    // Edit cronjob
    if ($action == 'edit') {
        $Form->info(T_('Job #'), $edited_Cronjob->ID);
    }
    $Form->info(T_('Default job name'), cron_job_name($edited_Cronjob->key, '', $edited_Cronjob->params));
    $Form->text_input('cjob_name', $edited_Cronjob->name, 50, T_('Job name'), '', array('maxlength' => 255));
}
$Form->date_input('cjob_date', date2mysql($edited_Cronjob->start_timestamp), T_('Schedule date'), array('required' => true));
$Form->time_input('cjob_time', date2mysql($edited_Cronjob->start_timestamp), T_('Schedule time'), array('required' => true));
$Form->duration_input('cjob_repeat_after', $edited_Cronjob->repeat_after, T_('Repeat every'), 'days', 'minutes', array('minutes_step' => 1));
Esempio n. 3
0
 /**
  * Load data from Request form fields.
  *
  * @return boolean true if loaded data seems valid.
  */
 function load_from_Request()
 {
     $cron_jobs_config = get_cron_jobs_config();
     if ($this->ID > 0 || get_param('ctsk_ID') > 0) {
         // Update or copy cron job
         $cjob_name = param('cjob_name', 'string', true);
     } else {
         // Create new cron job
         $cjob_type = param('cjob_type', 'string', true);
         if (!isset($cron_jobs_config[$cjob_type])) {
             // This cron job type doesn't exist, so this is an invalid state
             debug_die('Invalid job type received');
         }
     }
     // start datetime:
     param_date('cjob_date', T_('Please enter a valid date.'), true);
     param_time('cjob_time');
     $this->set('start_datetime', form_date(get_param('cjob_date'), get_param('cjob_time')));
     // repeat after:
     $cjob_repeat_after = param_duration('cjob_repeat_after');
     if ($cjob_repeat_after == 0) {
         $cjob_repeat_after = NULL;
     }
     $this->set('repeat_after', $cjob_repeat_after);
     // name:
     if (!empty($cjob_name) && $cjob_name != $this->get('name')) {
         $this->set('name', $cjob_name);
     }
     if ($this->ID == 0 && get_param('ctsk_ID') == 0) {
         // Set these params only on creating and copying actions
         // key:
         $this->set('key', $cjob_type);
         // params:
         $this->set('params', $cron_jobs_config[$cjob_type]['params']);
     }
     return !param_errors_detected();
 }