function elysia_cron_settings_form in Elysia Cron 6
Same name and namespace in other branches
- 5.2 elysia_cron.admin.inc \elysia_cron_settings_form()
- 5 elysia_cron.admin.inc \elysia_cron_settings_form()
- 6.2 elysia_cron.admin.inc \elysia_cron_settings_form()
- 7.2 elysia_cron.admin.inc \elysia_cron_settings_form()
- 7 elysia_cron.admin.inc \elysia_cron_settings_form()
1 string reference to 'elysia_cron_settings_form'
File
- ./
elysia_cron.admin.inc, line 90
Code
function elysia_cron_settings_form() {
global $elysia_cron_settings, $elysia_cron_settings_by_channel;
elysia_cron_initialize();
$form = array();
$form['prefix_1'] = array(
'#type' => 'fieldset',
'#title' => t('Click for help and cron rules and script syntax'),
'#collapsible' => true,
'#collapsed' => true,
'#description' => <<<EOT
<h3>Fields order</h3>
<pre>
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0)
| | | | |
* * * * *
</pre>
<p>Each of the patterns from the first five fields may be either * (an asterisk),
which matches all legal values, or a list of elements separated by commas (see below).</p>
<p>For "day of the week" (field 5), 0 is considered Sunday, 6 is Saturday
(7 is an illegal value)</p>
<p>A job is executed when the time/date specification fields all match the current
time and date. There is one exception: if both "day of month" and "day of week"
are restricted (not "*"), then either the "day of month" field (3) or the "day of week"
field (5) must match the current day (even though the other of the two fields
need not match the current day).</p>
<h3>Fields operators</h3>
<p>There are several ways of specifying multiple date/time values in a field:</p>
<ul>
<li>The comma (',') operator specifies a list of values, for example: "1,3,4,7,8"</li>
<li>The dash ('-') operator specifies a range of values, for example: "1-6", which is equivalent to "1,2,3,4,5,6"</li>
<li>The asterisk ('*') operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to 'every hour' (subject to matching other specified fields).</li>
<li>The slash ('/') operator (called "step") can be used to skip a given number of values. For example, "*/3" in the hour time field is equivalent to "0,3,6,9,12,15,18,21".</li>
</ul>
<h3>Examples</h3>
<pre>
*/15 * * * * : Execute job every 15 minutes
0 2,14 * * *: Execute job every day at 2:00 and 14:00
0 2 * * 1-5: Execute job at 2:00 of every working day
0 12 1 */2 1: Execute job every 2 month, at 12:00 of first day of the month OR at every monday.
</pre>
<h3>Script</h3>
<p>You can use the script section to easily create new jobs (by calling a php function)
or to change the scheduling of an existing job.</p>
<p>Every line of the script can be a comment (if it starts with #) or a job definition.</p>
<p>The syntax of a job definition is:</p>
<code>
<-> [rule] <ch:CHANNEL> [job]
</code>
<p>(Tokens betweens [] are mandatory)</p>
<ul>
<li><->: a line starting with "-" means that the job is DISABLED.</li>
<li>[rule]: a crontab schedule rule. See above.</li>
<li><ch:CHANNEL>: set the channel of the job.</li>
<li>[job]: could be the name of a supported job (for example: 'search_cron') or a function call, ending with ; (for example: 'process_queue();').</li>
</ul>
<p>A comment on the line just preceding a job definition is considered the job description.</p>
<p>Remember that script OVERRIDES all settings on single jobs sections or channel sections of the configuration</p>
<h3>Examples of script</h3>
<pre>
# Search indexing every 2 hours (i'm setting this as the job description)
0 */2 * * * search_cron
# I'll check for module status only on sunday nights
# (and this is will not be the job description, see the empty line below)
0 2 * * 0 update_status_cron
# Trackback ping process every 15min and on a channel called "net"
*/15 * * * * ch:net trackback_cron
# Disable node_cron (i must set the cron rule even if disabled)
- */15 * * * * node_cron
# Launch function send_summary_mail('test@test.com', false); every night
# And set its description to "Send daily summary"
# Send daily summary
0 1 * * * send_summary_mail('test@test.com', false);
</pre>
EOT
,
);
$form['prefix_2'] = array(
'#markup' => '<hr>',
);
$form['main'] = array(
'#title' => t('Main'),
'#type' => 'fieldset',
'#collapsible' => false,
'#collapsed' => false,
);
$form['main']['elysia_cron_disabled'] = array(
'#title' => t('Global disable'),
'#type' => 'checkbox',
'#default_value' => variable_get('elysia_cron_disabled', false),
);
$form['installation'] = array(
'#title' => t('Installation settings'),
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
);
if (EC_DRUPAL_VERSION >= 7) {
$form['installation']['cron_safe_threshold'] = array(
'#type' => 'select',
'#title' => t('Run cron on visitor\'s requests, every'),
'#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
'#description' => t('Setting a time here will enable the "poormanscron" method, which runs the Drupal cron operation using normal browser/page requests instead of having to set up a crontab to request the cron.php script. This approach requires that your site gets regular traffic/visitors in order to trigger the cron request.') . '<br />' . t('This way is fine if you don\'t need a great control over job starting times and execution frequency.') . '<br />' . t('If you need a fine grained control over cron timings use the crontab metod, as <a href="!cron_url">described in Drupal installation guide</a>.', array(
'!cron_url' => url('http://drupal.org/cron'),
)) . '<br />' . t('If you have a very large site, or you need to execute some jobs very often (more than once an hour) refer to Elysia cron\'s INSTALL.TXT to improve main cron setup.'),
'#options' => array(
0 => t('Never / Use external crontab'),
) + drupal_map_assoc(array(
3600,
10800,
21600,
43200,
86400,
604800,
), 'format_interval'),
);
}
$form['installation']['cron_key'] = array(
'#title' => t('Cron key'),
'#type' => 'textfield',
'#default_value' => variable_get('cron_key', ''),
'#description' => t('This is used to avoid external cron calling. If you set this cron will by accessible only by calling http://site/cron.php?cron_key=XXX, so you\'ll need to modify system crontab to support this (Logged user with [administer elysia_cron] permission avoid this check).'),
);
$form['installation']['elysia_cron_allowed_hosts'] = array(
'#title' => t('Allowed hosts'),
'#type' => 'textfield',
'#default_value' => variable_get('elysia_cron_allowed_hosts', ''),
'#description' => t('Insert a list of ip addresses separated by , that can run cron.php (Logged user with [administer elysia_cron] permission avoid this check).'),
);
$form['installation']['elysia_cron_default_rule'] = array(
'#title' => t('Default schedule rule'),
'#type' => 'textfield',
'#default_value' => variable_get('elysia_cron_default_rule', false),
'#description' => t('If you don\'t specify a rule for a process, and if it has not a module specified one, this rule will apply'),
);
if (!ini_get('safe_mode')) {
$form['installation']['elysia_cron_time_limit'] = array(
'#title' => t('Time limit'),
'#type' => 'textfield',
'#default_value' => variable_get('elysia_cron_time_limit', 240),
'#description' => t('Set the number of seconds a channel is allowed to run. If you have some jobs that needs more time to execute increase it or set to 0 to disable the limit (WARN: that way a stuck job will block the channel forever!).'),
);
}
$form['installation']['elysia_cron_stuck_time'] = array(
'#title' => t('Stuck time'),
'#type' => 'textfield',
'#default_value' => variable_get('elysia_cron_stuck_time', 3600),
'#description' => t('How many seconds the process should wait to consider the job as stuck (so the channel can run again)'),
);
$form['installation']['elysia_cron_debug_messages'] = array(
'#title' => t('Debug'),
'#type' => 'select',
'#default_value' => variable_get('elysia_cron_debug_messages', 0),
'#options' => array(
0 => 'Disabled',
1 => 'Enabled',
),
'#description' => t('Enable extended logging (in watchdog)'),
);
$default_ruless = '';
$default_rules = variable_get('elysia_cron_default_rules', $GLOBALS['elysia_cron_default_rules']);
foreach ($default_rules as $dk => $dr) {
$default_ruless .= $dr . ' = ' . $dk . "\n";
}
$form['installation']['elysia_cron_default_rules'] = array(
'#title' => t('Predefined rules'),
'#type' => 'textarea',
'#rows' => 5,
'#default_value' => $default_ruless,
'#description' => t('You can put here standard rules used in your system, each one with its own caption. Put each rule in a separate line, in the form "caption = rule". For example: <i>"every 15 minutes = */15 * * * *"</i>.'),
);
$form['installation']['elysia_cron_alert_fieldset'] = array(
'#title' => t('External cron tracking'),
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
'#description' => t('This lets you use an external tracking system like <a href="http://www.host-tracker.com/">Host Tracker</a> to be used to monitor the health of cron on your site. Point the tracking service to <a href="!cron-ping-url">!cron-ping-url</a>. If Elysia cron has been called within the time interval specified below, the ping page will return HTTP 200. If not, the ping page will throw a 404 (page not found).', array(
'!cron-ping-url' => url('admin/build/cron/ping'),
)),
);
$form['installation']['elysia_cron_alert_fieldset']['elysia_cron_alert_interval'] = array(
'#title' => t('Lapse interval (minutes)'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => variable_get('elysia_cron_alert_interval', 60),
'#description' => t('Specify the number of minutes to allow to lapse before the cron ping page returns a 404 (page not found).'),
);
$form['elysia_cron_script_fieldset'] = array(
'#title' => t('Script'),
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => !variable_get('elysia_cron_script', ''),
);
$form['elysia_cron_script_fieldset']['elysia_cron_script'] = array(
'#type' => 'textarea',
'#rows' => 20,
'#default_value' => variable_get('elysia_cron_script', ''),
'#description' => t('You can specify new cron jobs or modify existing schedules by adding lines to the script.<br>' . '<b>Warning</b> All rules specified in the script will OVERRIDE single job settings and channel settings (sections below).'),
);
$form['single_job'] = array(
'#title' => t('Single job settings'),
'#description' => '<b>' . t('Disabled') . '</b>: ' . t('Flag this to disable job execution') . '<br />' . '<b>' . t('Schedule rule') . '</b>: ' . t('Timing rule for the job. Leave empty to use default rule (shown after the field in parenthesis)') . '<br />' . '<b>' . t('Weight') . '</b>: ' . t('Use this to specify execution order: low weights are executed before high weights. Default value shown in parenthesis') . '<br />' . '<b>' . t('Channel') . '</b>: ' . t('Specify a channel for the job (create the channel if not exists)') . '<br /><br />',
'#type' => 'fieldset',
'#collapsible' => true,
);
$jobchannels = array(
'#title' => t('Job channel associations'),
'#description' => t('Leave empty for default channel'),
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
);
foreach ($elysia_cron_settings_by_channel as $channel => $cconf) {
foreach ($cconf as $job => $conf) {
if ($job != '#data' && empty($conf['expression'])) {
$form['single_job']['elysia_cron_' . $job] = array(
'#title' => $job,
// t('Job !job', array('!job' => $job)),
'#description' => elysia_cron_description($job),
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => !elysia_cron_get_job_rule($job) && !elysia_cron_get_job_weight($job) && !elysia_cron_is_job_disabled($job) && !elysia_cron_get_job_channel($job),
);
//if (!$form['single_job']['elysia_cron_'.$job]['#collapsed'])
// $form['single_job']['#collapsed'] = false;
$rule = elysia_cron_get_job_rule($job);
$options = array_merge(array(
'default' => t('Default') . ' (' . (!empty($default_rules[$conf['default_rule']]) ? $default_rules[$conf['default_rule']] : $conf['default_rule']) . ')',
), $default_rules);
if ($rule && !isset($options[$rule])) {
$options[$rule] = $rule;
}
$options['custom'] = t('Custom') . ' ...';
$form['single_job']['elysia_cron_' . $job]['_elysia_cron_seljob_rule_' . $job] = array(
'#title' => t('Schedule rule'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $rule ? $rule : 'default',
);
$form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_rule_' . $job] = array(
'#title' => t('Schedule rule'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $rule ? $rule : $conf['default_rule'],
);
$form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_weight_' . $job] = array(
'#title' => t('Weight'),
'#type' => 'textfield',
'#size' => 4,
'#default_value' => elysia_cron_get_job_weight($job),
'#description' => '(' . $conf['default_weight'] . ')',
);
//$form['single_job']['elysia_cron_'.$job]['elysia_cron_'.$job.'_disabled'] = array(
$form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_disabled_' . $job] = array(
'#title' => t('Disabled'),
'#type' => 'checkbox',
'#default_value' => elysia_cron_is_job_disabled($job, false),
);
//$jobchannels['elysia_cron_'.$job.'_channel'] = array(
$form['single_job']['elysia_cron_' . $job]['_elysia_cron_job_channel_' . $job] = array(
'#title' => t('Channel'),
// t('Channel for !job', array('!job' => $job)),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => elysia_cron_get_job_channel($job),
);
//if (elysia_cron_get_job_channel($job))
// $jobchannels['#collapsed'] = false;
}
}
}
$form['channels'] = array(
'#title' => t('Channels settings'),
'#type' => 'fieldset',
'#collapsible' => true,
);
foreach ($elysia_cron_settings_by_channel as $channel => $conf) {
$form['channels']['elysia_cron_ch_' . $channel] = array(
'#title' => $channel,
// t('Channel !channel', array('!channel' => $channel)),
'#type' => 'fieldset',
);
$form['channels']['elysia_cron_ch_' . $channel]['_elysia_cron_ch_disabled_' . $channel] = array(
'#title' => t('Disabled'),
'#type' => 'checkbox',
'#default_value' => elysia_cron_is_channel_disabled($channel, ''),
);
$form['channels']['elysia_cron_ch_' . $channel]['_elysia_cron_ch_rule_' . $channel] = array(
'#title' => t('Default schedule rule'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => elysia_cron_get_channel_rule($channel),
);
//if (elysia_cron_is_channel_disabled($channel))
// $form['channels']['#collapsed'] = false;
}
//$form['channels']['jobchannels'] = $jobchannels;
$form['buttons'] = array(
'#type' => 'actions',
);
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['buttons']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
);
if (!empty($_POST) && form_get_errors()) {
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
}
return _dcr_form($form);
}