You are here

function _scheduler_lightweight_cron in Scheduler 7

Same name and namespace in other branches
  1. 6 scheduler.module \_scheduler_lightweight_cron()

Form constructor for the lightweight cron form to allow a manual run.

1 string reference to '_scheduler_lightweight_cron'
scheduler_menu in ./scheduler.module
Implements hook_menu().

File

./scheduler.admin.inc, line 406
Administration forms for the Scheduler module.

Code

function _scheduler_lightweight_cron($form, &$form_state) {
  $form = array();
  $prefix_text = t("You can test Scheduler's lightweight cron process interactively");
  $form['scheduler_cron'] = array(
    '#type' => 'submit',
    '#prefix' => '<div class="container-inline">' . $prefix_text . ': ',
    '#value' => t("Run Scheduler's lightweight cron now"),
    '#submit' => array(
      '_scheduler_lightweight_cron_submit',
    ),
    '#suffix' => "</div>\n",
  );
  $form['scheduler_cron_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Lightweight cron settings'),
  );
  $form['scheduler_cron_settings']['scheduler_lightweight_log'] = array(
    '#type' => 'checkbox',
    '#title' => t('Log every activation and completion message.'),
    '#default_value' => variable_get('scheduler_lightweight_log', 1),
    '#description' => t("When this option is checked, Scheduler will write an entry to the log every time the lightweight cron process is started and completed. This is useful during set up and testing, but can result in a large number of log entries. Any actions performed during the lightweight cron run will always be logged regardless of this setting."),
  );
  $form['scheduler_cron_settings']['scheduler_lightweight_access_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Lightweight cron access key'),
    '#size' => 100,
    '#default_value' => variable_get('scheduler_lightweight_access_key', ''),
    '#description' => t("Similar to Drupal's cron key this acts as a security token to prevent unauthorised calls to scheduler/cron. The key should be passed as scheduler/cron/&lt;this key&gt;. To disable security for lightweight cron leave this field blank."),
  );
  if (isset($form_state['scheduler_generate_new_key'])) {
    $new_access_key = substr(md5(rand()), 0, 20);

    // @codingStandardsIgnoreStart
    // We have to use $form_state['input'] here as storing the new key in
    // $form_state['values'] does not work. It is acceptable to use it on the
    // left of an assignment even if PHPCS does not think so.
    $form_state['input']['scheduler_lightweight_access_key'] = $new_access_key;

    // @codingStandardsIgnoreEnd
    drupal_set_message(t('A new random key has been generated but not saved. If you wish to use this, first "Save Configuration" to store the value, then modify your crontab job.'), 'warning');
  }
  $form['scheduler_cron_settings']['create_key'] = array(
    '#type' => 'submit',
    '#value' => t('Generate new random key'),
    '#submit' => array(
      '_scheduler_generate_key',
    ),
  );
  return system_settings_form($form);
}