You are here

authcache.install in Authenticated User Page Caching (Authcache) 7

Same filename and directory in other branches
  1. 6 authcache.install
  2. 7.2 authcache.install

Install, update and uninstall functions for the authcache module.

File

authcache.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the authcache module.
 *
 */

/**
 * Implements hook_enable().
 */
function authcache_enable() {
  global $user;

  // Set authcache cookie for user so they don't receive cached anon pages.
  if (!drupal_is_cli()) {
    authcache_user_login($user, $user);
  }
}

/**
 * Implements hook_disable().
 */
function authcache_disable() {
}

/**
 * Implements hook_requirements().
 */
function authcache_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break during installation.
  $t = get_t();

  // Retrieve the name of the cache class used for the cache_page bin.
  $page_cache_class = get_class(_cache_get_object('cache_page'));
  $requirements['authcache'] = array(
    'title' => $t('Authcache'),
  );
  if (_authcache_backendstatus()) {
    $requirements['authcache']['value'] = $t('Using %class as cache backend', array(
      '%class' => $page_cache_class,
    ));
  }
  else {
    $requirements['authcache']['value'] = $t('authcache.inc is not the last entry in cache_backends variable.');
    $requirements['authcache']['description'] = $t('Your settings.php file must be modified to enable Authcache. See <a href="@url">README.txt</a>.', array(
      '@url' => base_path() . drupal_get_path('module', 'authcache') . '/README.txt',
    ));
    $requirements['authcache']['severity'] = $phase == 'runtime' ? REQUIREMENT_ERROR : REQUIREMENT_WARNING;
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function authcache_install() {

  // Ensure that the module is loaded early in the bootstrap:
  // TODO Please review the conversion of this statement to the D7 database API syntax.

  /* db_query("UPDATE {system} SET weight = -90 WHERE name = '%s'", 'authcache') */
  db_update('system')
    ->fields(array(
    'weight' => -90,
  ))
    ->condition('name', 'authcache')
    ->execute();
}

/**
 * Implements hook_uninstall().
 */
function authcache_uninstall() {

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

  /* db_query("DELETE FROM {variable} WHERE name LIKE '%s_%%'", 'authcache') */
  db_delete('variable')
    ->condition('name', 'authcache', 'LIKE')
    ->execute();
  cache_clear_all('variables', 'cache');
}

/**
 * Return true if settings.php is properly configured and authcache.inc is the
 * last entry in the cache_backends array.
 */
function _authcache_backendstatus() {

  // Check whether authcache.inc is last in cache_backends.
  $backends = variable_get('cache_backends', array());
  $last_in_backends = end($backends);
  $authcache_inc = drupal_get_path('module', 'authcache') . '/authcache.inc';
  return $authcache_inc == $last_in_backends;
}

Functions

Namesort descending Description
authcache_disable Implements hook_disable().
authcache_enable Implements hook_enable().
authcache_install Implements hook_install().
authcache_requirements Implements hook_requirements().
authcache_uninstall Implements hook_uninstall().
_authcache_backendstatus Return true if settings.php is properly configured and authcache.inc is the last entry in the cache_backends array.