View source
<?php
function ad_permission_install() {
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_query("CREATE TABLE {ad_owners} (\n oid SERIAL NOT NULL PRIMARY KEY,\n aid INT NOT NULL DEFAULT '0',\n uid INT NOT NULL DEFAULT '0'\n );");
db_query("CREATE TABLE {ad_permissions} (\n oid INT NOT NULL DEFAULT '0' PRIMARY KEY,\n permissions TEXT NULL DEFAULT ''\n );");
db_query("CREATE TABLE {ad_hosts} (\n uid INT NOT NULL DEFAULT '0' PRIMARY KEY,\n \n hostid varchar(32) DEFAULT '',\n status INT NOT NULL DEFAULT '0',\n description TEXT NOT NULL DEFAULT ''\n );");
break;
case 'mysql':
case 'mysqli':
default:
db_query("CREATE TABLE IF NOT EXISTS {ad_owners} (\n oid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,\n aid INT(10) UNSIGNED NOT NULL DEFAULT '0',\n uid INT(10) UNSIGNED NOT NULL DEFAULT '0',\n\n PRIMARY KEY (oid),\n KEY (aid),\n KEY (uid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE IF NOT EXISTS {ad_permissions} (\n oid INT(11) UNSIGNED NOT NULL DEFAULT '0',\n permissions LONGTEXT NULL,\n PRIMARY KEY (oid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE IF NOT EXISTS {ad_hosts} (\n uid INT UNSIGNED NOT NULL DEFAULT '0',\n\n hostid varchar(32) DEFAULT '',\n\n status INT(2) UNSIGNED NOT NULL DEFAULT '0',\n description TEXT NULL,\n\n PRIMARY KEY (uid),\n KEY (status),\n KEY (hostid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
}
drupal_set_message(t('The necessary ad module tables have been created.'));
}
function ad_permission_update_5000() {
$ret = array();
$result = db_query('SELECT * FROM {ad_permissions}');
while ($permission = db_fetch_object($result)) {
$changed = FALSE;
$permissions = explode('|,|', $permission->permissions);
$key = array_search('manage active ad', $permissions);
if ($key !== FALSE) {
unset($permissions[$key]);
$permissions[] = 'manage active image';
$changed = TRUE;
}
$key = array_search('manage status', $permissions);
if ($key !== FALSE) {
unset($permissions[$key]);
$defaults = module_invoke_all('adapi', 'permissions', NULL);
$perms = array();
foreach ($defaults as $text => $default) {
if ($default && !strncmp($text, 'set status', strlen('set status'))) {
$perms[] = $text;
}
}
$permissions = array_merge($permissions, $perms);
$changed = TRUE;
}
if ($changed) {
$ret[] = update_sql("UPDATE {ad_permissions} SET permissions = '" . implode('|,|', $permissions) . "' WHERE oid = {$permission->oid}");
}
}
return $ret;
}
function ad_permission_uninstall() {
db_query('DROP TABLE {ad_hosts}');
db_query('DROP TABLE {ad_owners}');
db_query('DROP TABLE {ad_permissions}');
}