You are here

function apdqc_disable in Asynchronous Prefetch Database Query Cache 7

Implements hook_disable().

Un-alter the cache bins removing the 'created' column.

Set the collation of cache tables back to utf8_bin.

Changes the semaphore table to InnoDB if it's currently MEMORY.

File

./apdqc.install, line 25
Handles APDQC installation and status checks.

Code

function apdqc_disable() {
  $maintenance_mode = variable_get('maintenance_mode', 0);
  $mm_changed = FALSE;
  if (!$maintenance_mode && variable_get('apdqc_table_indexes', APDQC_TABLE_INDEXES) && variable_get('apdqc_table_collations', APDQC_TABLE_COLLATIONS) && variable_get('apdqc_semaphore_memory', APDQC_SEMAPHORE_MEMORY)) {

    // Put site into maintenance mode and wait 2 seconds for requests to stop.
    variable_set('maintenance_mode', 1);
    sleep(2);
    $mm_changed = TRUE;
  }
  module_load_include('admin.inc', 'apdqc');
  if (variable_get('apdqc_table_indexes', APDQC_TABLE_INDEXES)) {

    // Drop the expire_created index; use expire.
    $before = array(
      'expire',
      'created',
    );
    $after = array(
      'expire',
    );
    apdqc_convert_cache_index($before, $after);
  }
  if (variable_get('apdqc_table_collations', APDQC_TABLE_COLLATIONS)) {

    // Change collation to utf8_general_ci.
    apdqc_admin_change_table_collation(TRUE, 'utf8_general_ci');
  }
  if (variable_get('apdqc_semaphore_memory', APDQC_SEMAPHORE_MEMORY)) {

    // Revert semaphore table to InnoDB if needed.
    // Get the real table name.
    $real_table_name_semaphore = str_replace("`", "'", Database::getConnection()
      ->prefixTables("{" . db_escape_table('semaphore') . "}"));
    $results = db_query("SHOW TABLE STATUS WHERE Name = {$real_table_name_semaphore}")
      ->fetchAssoc();
    if (strcasecmp($results['Engine'], 'InnoDB') != 0) {
      apdqc_admin_convert_semaphore_table_to_innodb(FALSE);
    }
  }
  if (variable_get('apdqc_sessions_schema', APDQC_SESSIONS_SCHEMA)) {
    apdqc_admin_sessions_table_update_schema(FALSE, TRUE);
  }
  if (variable_get('apdqc_semaphore_schema', APDQC_SESSIONS_SCHEMA)) {
    apdqc_admin_semaphore_table_update_schema(FALSE, TRUE);
  }
  if ($mm_changed) {
    variable_set('maintenance_mode', $maintenance_mode);
  }

  // Check settings.php.
  $apdqcache_found = FALSE;
  foreach (variable_get('cache_backends', array()) as $include) {
    if (stripos($include, '/apdqc/apdqc.cache.inc') !== FALSE) {
      $apdqcache_found = TRUE;
      break;
    }
  }
  $lock_inc = variable_get('lock_inc', 'includes/lock.inc');
  if (stripos($lock_inc, '/apdqc/apdqc.lock.inc') !== FALSE) {
    $apdqcache_found = TRUE;
  }
  $session = variable_get('session_inc', 'includes/session.inc');
  if (stripos($session, '/apdqc/apdqc.session.inc') !== FALSE) {
    $apdqcache_found = TRUE;
  }
  if ($apdqcache_found) {
    drupal_set_message(t('Be sure to edit your settings.php file and remove the apdqc code in there.'), 'error');
  }
}