You are here

function civicrm_cron_admin_settings in CiviCRM Cron 6

Same name and namespace in other branches
  1. 7.2 civicrm_cron.module \civicrm_cron_admin_settings()
  2. 7 civicrm_cron.module \civicrm_cron_admin_settings()

Builds the civicrm_cron admininstration settings form.

1 string reference to 'civicrm_cron_admin_settings'
civicrm_cron_menu in ./civicrm_cron.module

File

./civicrm_cron.module, line 88
Civicrm Cron Module Uses _cron for drupals cron job to trigger civicrm's new Consolidated Cron Jobs used by Visions Service Adventures website

Code

function civicrm_cron_admin_settings($form, &$form_state) {
  $form = array();
  if (!civicrm_initialize()) {
    drupal_set_message(t('Failed to initialize CiviCRM'));
    return;
  }
  $cron_values['name'] = variable_get('civicrm_cron_username', NULL);
  $cron_values['pass'] = variable_get('civicrm_cron_password', NULL);
  $cron_values['key'] = variable_get('civicrm_cron_sitekey', CIVICRM_SITE_KEY);
  $url = civicrm_cron_get_url($cron_values);
  if ($url) {
    $result = drupal_http_request($url);

    //look for the CiviCRM error in response... successful processing returns nothing
    if ($result->data) {
      drupal_set_message('Attempted to use the following URL to process CiviCRM\'s cron: ' . $url . ' <br /> CiviCRM Error: ' . $result->data, 'warning');
    }
    else {
      drupal_set_message(t('CiviCRM Cron Successfully Run'));
    }
  }
  $form['instructions'] = array(
    '#value' => '<div>' . t('Use this page to configure authentication settings for Drupal cron to automatically trigger CiviCRM\'s Consolidated Cron Jobs: ' . $base_url) . '</div>',
  );
  $form['civicrm_cron_username'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#description' => t('Name the drupal user under whose name the CiviCRM cronjobs should operate. <a href ="/admin/user/create" target ="_blank" >create new user</a>?'),
    '#default_value' => $cron_values['name'],
    '#size' => '20',
    '#maxlength' => '78',
  );
  $form['civicrm_cron_password'] = array(
    '#type' => 'textfield',
    '#title' => t('Cronjob Users Password'),
    '#description' => t('Enter the password for this drupal user account'),
    '#default_value' => $cron_values['pass'],
    '#size' => '20',
    '#maxlength' => '78',
  );
  $form['civicrm_cron_sitekey'] = array(
    '#type' => 'textfield',
    '#title' => t('Site Key'),
    '#description' => t('The site key can be found by looking in civicrm.settings.php, usually found in sites/default/civicrm.settings.php'),
    '#default_value' => $cron_values['key'],
  );
  return system_settings_form($form);
}