You are here

function civicrm_cron_admin_settings in CiviCRM Cron 7.2

Same name and namespace in other branches
  1. 6 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
Implementation of hook_menu().

File

./civicrm_cron.module, line 36
CiviCRM Cron Module

Code

function civicrm_cron_admin_settings($form, &$form_state) {
  global $base_url;
  $form = array();
  if (!civicrm_initialize()) {
    drupal_set_message(t('Failed to initialize CiviCRM'), 'error');
    return;
  }
  $key = variable_get('civicrm_cron_sitekey', NULL);
  if (empty($form_state['input']['civicrm_cron_sitekey']) && $key != NULL) {
    $result = drupal_http_request($base_url . '/civicrm-cron/passthrough?key=' . $key);

    //look for the CiviCRM error in response... successful processing returns nothing
    if (!empty($result->data)) {
      drupal_set_message($result->data, 'error');
    }
    else {
      drupal_set_message(t('CiviCRM Cron Successfully Run'));
    }
  }

  //if it's still NULL at this point, set to site key constant
  if ($key == NULL) {
    $key = CIVICRM_SITE_KEY;
    if (empty($form_state['input']['civicrm_cron_sitekey'])) {
      drupal_set_message(t('Save the Configuration to Test CiviCRM Cron'), 'warning');
    }
  }
  $form['civicrm_cron_sitekey'] = array(
    '#type' => 'textfield',
    '#title' => t('Sitekey'),
    '#default_value' => $key,
    '#description' => t('Must match the sitekey found in the civicrm-settings.php file.  Leave this field empty to attempt to lookup the current site key.'),
  );
  $form['civicrm_cron_advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('CiviMail Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // CiviMail job is the only job appears to be the only job that requires authenitcation
  // added username and pass back to resolve https://drupal.org/node/2088595
  $cron_values['name'] = variable_get('civicrm_cron_username', NULL);
  $cron_values['pass'] = variable_get('civicrm_cron_password', NULL);
  if ($cron_values['name']) {
    $account = user_load_by_name($cron_values['name']);
    if ($account && user_access('view all contacts', $account) && user_access('access CiviCRM', $account) && user_access('access CiviMail', $account)) {
      drupal_set_message(t('User has correct permissions to run CiviMail job'));
    }
    else {
      drupal_set_message(t('User does NOT have correct permissions to run CiviMail job'), 'error');
    }
  }
  $form['civicrm_cron_advanced']['help'] = array(
    '#type' => 'markup',
    '#markup' => 'A username and password of a Drupal user with the permission to view all contacts,
    access CiviCRM, and access CiviMail is required for CiviMail. Passing the username and password
    is less secure.  ONLY configure this if you are using CiviMail.',
  );
  $form['civicrm_cron_advanced']['civicrm_cron_username'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#default_value' => $cron_values['name'],
    '#description' => t('CiviCRM runs cron as a specific user.  This user should have MINIMAL permissions since the password will be saved in the database and seen in the logs.'),
  );
  $form['civicrm_cron_advanced']['civicrm_cron_password'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#default_value' => $cron_values['pass'],
    '#description' => t('The password for user defined above.  This will appear blank after it is saved.'),
  );
  return system_settings_form($form);
}