You are here

function prod_check_settings_form_submit in Production check & Production monitor 7

Same name and namespace in other branches
  1. 6 includes/prod_check.admin.inc \prod_check_settings_form_submit()

Submit for settings form.

TODO: is it better to split all of these in separate functions and use buttons with the #submit property? The latter is better readability wise I guess.

File

includes/prod_check.admin.inc, line 456

Code

function prod_check_settings_form_submit($form, &$form_state) {
  switch ($form_state['values']['op']) {
    case t('Force immediate module list reporting'):
      variable_set('prod_check_module_list_lastrun', -1);
      break;
    case t('Save configuration'):
      variable_set('prod_check_sitemail', $form_state['values']['prod_check_sitemail']);

      // PHP errors.
      if (module_exists('dblog')) {
        variable_set('prod_check_dblog_php', $form_state['values']['prod_check_dblog_php']);
        variable_set('prod_check_dblog_php_threshold', $form_state['values']['prod_check_dblog_php_threshold']);
      }

      // APC/OPcache.
      variable_set('prod_check_apc_expunge', $form_state['values']['prod_check_apc_expunge']);
      variable_set('prod_check_apcuser', $form_state['values']['prod_check_apcuser']);
      if (!empty($form_state['values']['prod_check_apcpass'])) {
        variable_set('prod_check_apcpass', $form_state['values']['prod_check_apcpass']);
      }
      else {
        variable_set('prod_check_apcpass', 'password');
      }
      variable_set('prod_check_exclude_disabled_modules', $form_state['values']['prod_check_exclude_disabled_modules']);
      if ($form_state['values']['prod_check_enable_xmlrpc']) {

        // Enable.
        variable_set('prod_check_enable_xmlrpc', $form_state['values']['prod_check_enable_xmlrpc']);
        variable_set('prod_check_xmlrpc_key', $form_state['values']['prod_check_xmlrpc_key']);
        variable_set('prod_check_module_list_day', $form_state['values']['prod_check_module_list_day']);
        variable_set('prod_check_module_list_time', $form_state['values']['prod_check_module_list_time']);
      }
      else {

        // Disable.
        variable_set('prod_check_enable_xmlrpc', 0);
      }

      // This is why we didn't use a system_settings_form().
      if (isset($form_state['values']['prod_check_enable_nagios']) && $form_state['values']['prod_check_enable_nagios']) {
        $checks = array();
        foreach ($form_state['values']['monitor_settings'] as $set => $data) {
          foreach ($data as $check => $value) {
            if ($value) {
              $checks[$set][] = $value;
            }
          }
        }

        // Enable.
        variable_set('prod_check_enable_nagios', $form_state['values']['prod_check_enable_nagios']);
        variable_set('prod_check_nagios_checks', $checks);
        variable_set('prod_check_nagios_unique', $form_state['values']['prod_check_nagios_unique']);
        variable_set('prod_check_nagios_verbose', $form_state['values']['prod_check_nagios_verbose']);
      }
      else {

        // Disable.
        variable_set('prod_check_enable_nagios', 0);
      }
      drupal_set_message(t('The configuration options have been saved.'));
      break;
    case t('Reset to defaults'):

      // This beats multiple variable_del() calls.
      // Don't delete prod_check_module_list_lastrun!
      // DELETE FROM {variable} WHERE name LIKE "prod_check\_%" AND name <> "prod_check_module_list_lastrun"'
      db_delete('variable')
        ->condition('name', 'prod_check\\_%', 'LIKE')
        ->condition('name', 'prod_check_module_list_lastrun', '<>')
        ->execute();
      cache_clear_all('variables', 'cache_bootstrap');
      drupal_set_message(t('The configuration options have been reset to their default values.'));
      break;
  }
}