View source
<?php
function top_searches_install() {
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() {
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();
$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;
}