View source
<?php
function customfilter_install() {
$result = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$result[] = db_query("CREATE TABLE {customfilter_set} (\n `sid` int(10) unsigned NOT NULL default '0',\n `name` varchar(32) NOT NULL default '',\n `cache` tinyint(1) NOT NULL default '1',\n `description` text,\n `shorttips` text,\n `longtips` text,\n PRIMARY KEY(sid) \n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
$result[] = db_query("CREATE TABLE {customfilter_filter} (\n `fid` int(10) unsigned NOT NULL default '0',\n `sid` int(10) unsigned NOT NULL default '0',\n `parentid` int(10) unsigned NOT NULL default '0',\n `name` varchar(32) NOT NULL default '',\n `description` text,\n `matches` int(2) NOT NULL default '1',\n `pattern` text,\n `replacement` text,\n `func` tinyint(1) NOT NULL default '0',\n `weight` int(5) NOT NULL default '0',\n PRIMARY KEY(fid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
break;
case 'pgsql':
$result[] = db_query("CREATE TABLE {customfilter_set} (\n sid serial,\n name varchar(32) NOT NULL default '',\n cache smallint NOT NULL default '1',\n description text,\n shorttips text,\n longtips text,\n PRIMARY KEY(sid) \n )");
$result[] = db_query("CREATE TABLE {customfilter_filter} (\n fid serial,\n sid int_unsigned NOT NULL default '0',\n parentid int_unsigned NOT NULL default '0',\n name varchar(32) NOT NULL default '',\n description text,\n matches smallint NOT NULL default '1',\n pattern text,\n replacement text,\n func smallint NOT NULL default '0',\n weight int NOT NULL default '0',\n PRIMARY KEY(fid)\n )");
break;
}
if (count($result) == count(array_filter($result))) {
drupal_set_message(t('The CustomFilter module has successfully added its tables to the database.'));
}
else {
drupal_set_message(t('Drupal was unable to install the database tables for the CustomFilter module.'), 'error');
}
}
function customfilter_uninstall() {
db_query("DROP TABLE {customfilter_filter}");
db_query("DROP TABLE {customfilter_set}");
}
function customfilter_update_1() {
$result = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$result[] = update_sql("ALTER TABLE {customfilter_set} ADD COLUMN `cache` boolean NOT NULL default '1' AFTER `name`;");
break;
case 'pgsql':
break;
}
return $result;
}