You are here

function authcache_admin_config_submit in Authenticated User Page Caching (Authcache) 7

Same name and namespace in other branches
  1. 6 authcache.admin.inc \authcache_admin_config_submit()
  2. 7.2 authcache.admin.inc \authcache_admin_config_submit()

Authcache config form submit

File

./authcache.admin.inc, line 130
Admin forms and pages.

Code

function authcache_admin_config_submit($form, &$form_state) {
  global $user;
  $debug_user_ray = $cache_roles = array();

  // Roles
  $roles = $form_state['values']['authcache_roles'];
  foreach ($roles as $rid => $is_checked) {
    if ($is_checked) {
      $cache_roles[$rid] = $rid;
    }
  }

  // Debugging for users
  $debug_users = explode(',', $form_state['values']['debug_users']);
  foreach ($debug_users as $username) {
    $debug_user_ray[] = trim($username);
  }
  $form_state['values']['debug_users'] = $debug_user_ray;

  // Define/update page caching settings if needed
  $pagecaching = variable_get('authcache_pagecaching', FALSE);

  // Not defined, first config submit
  if (!$pagecaching) {
    variable_set('authcache_pagecaching', array(
      array(
        'option' => 0,
        'pages' => AUTHCACHE_NOCACHE_DEFAULT,
        'noadmin' => 1,
        'roles' => $cache_roles,
      ),
    ));
  }
  elseif ($cache_roles != variable_get('authcache_roles', $cache_roles)) {
    $pagecaching[0]['roles'] = $cache_roles;
    variable_set('authcache_pagecaching', $pagecaching);
  }

  // Clear sessions, except current user
  if ($form_state['values']['clear_sessions']) {

    // TODO Please review the conversion of this statement to the D7 database API syntax.

    /* db_query("DELETE FROM {sessions} WHERE sid <> '%s'", session_id()) */
    $num_deleted = db_delete('sessions')
      ->condition('sid', session_id(), '<>')
      ->execute();

    // Set cookie for current user
    $edit_ignored = NULL;
    authcache_user_login($edit_ignored, $user);
    drupal_set_message(t('%num user sessions have been invalidated.', array(
      '%num' => $num_deleted,
    )));
  }

  // Forcibly disable Drupal's built-in SQL caching (no need to cache page twice for anonymous users!)
  if (in_array(DRUPAL_ANONYMOUS_RID, $cache_roles) && variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) {
    variable_set('cache', CACHE_DISABLED);
    drupal_set_message(t("Drupal's built-in page caching for anonymous users has been disabled to avoid redundant caching."));
  }

  // Devel query logging
  variable_set('dev_query', $form_state['values']['dev_query']);

  // Delete variable if not in use
  foreach (array(
    'debug_all',
    'debug_page',
    'debug_users',
    'post',
    'http200',
    'noajax',
  ) as $key) {
    if ($value = $form_state['values'][$key]) {
      variable_set("authcache_{$key}", $value);
    }
    else {
      variable_del("authcache_{$key}");
    }
  }
  variable_set('authcache_roles', $cache_roles);
  drupal_set_message(t('Your Authcache settings have been saved.'));
  cache_clear_all('*', 'cache_page', TRUE);
  drupal_set_message(t('Cached pages cleared.'));
}