You are here

top_searches.install in Top Searches 6

Same filename and directory in other branches
  1. 5 top_searches.install
  2. 7 top_searches.install

File

top_searches.install
View source
<?php

function top_searches_install() {

  // Create tables.
  drupal_install_schema('top_searches');
  variable_set('top_searches_show_counters', 0);
  variable_set('top_searches_block_items', 50);
  drupal_set_message(t('Top searches module installed successfully.'));
}
function top_searches_uninstall() {

  // Remove tables.
  drupal_uninstall_schema('top_searches');
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("DELETE FROM {variable} WHERE name LIKE 'top_searches%'");
      cache_clear_all('variables', 'cache');
      break;
  }
}
function top_searches_schema() {
  $schema['top_searches'] = array(
    'fields' => array(
      'qid' => array(
        'type' => 'serial',
        'length' => 11,
        'not_null' => TRUE,
        'unsigned' => TRUE,
      ),
      'q' => array(
        'type' => 'varchar',
        'length' => 255,
        'not_null' => TRUE,
        'default' => '',
      ),
      'counter' => array(
        'type' => 'int',
        'length' => 11,
        'not_null' => FALSE,
        'default' => 0,
        'unsigned' => TRUE,
      ),
    ),
    'unique keys' => array(
      'q' => array(
        'q',
      ),
    ),
    'primary key' => array(
      'qid',
    ),
  );
  return $schema;
}
function top_searches_update_6001() {
  $ret = array();

  // Remove all non-valid search phrases from the DB (according to http://drupal.org/node/621842)
  $result = db_query('SELECT * FROM {top_searches}');
  while ($row = db_fetch_array($result)) {
    $valid = _top_searches_valid_phrase($row['q']);
    if (!$valid) {
      $ret[] = update_sql("DELETE FROM {top_searches} WHERE qid = {$row['qid']}");
      $removed[] = $row['q'];
    }
  }
  if (!empty($removed)) {
    drupal_set_message(t('The following non-valid phrases were removed from Top Searches table: %s', array(
      '%s' => implode(', ', $removed),
    )));
  }
  return $ret;
}