View source
<?php
function acl_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("create table if not exists {acl} (\n acl_id int(10) NOT NULL default 0,\n module varchar(255),\n name varchar(255),\n PRIMARY KEY (acl_id)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("create table if not exists {acl_user} (\n acl_id int(10) NOT NULL default 0,\n uid int(10) NOT NULL default 0,\n PRIMARY KEY (acl_id, uid),\n KEY uid (uid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("create table if not exists {acl_node} (\n acl_id int(10) NOT NULL default 0,\n nid int(10) NOT NULL default 0,\n grant_view tinyint(1) unsigned NOT NULL default '0',\n grant_update tinyint(1) unsigned NOT NULL default '0',\n grant_delete tinyint(1) unsigned NOT NULL default '0',\n priority smallint(2) NOT NULL default '0',\n PRIMARY KEY (acl_id, nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {acl} (\n acl_id integer NOT NULL DEFAULT 0,\n module varchar(255),\n name varchar(255),\n PRIMARY KEY (acl_id)\n );");
db_query("CREATE SEQUENCE {acl}_acl_id_seq;");
db_query("CREATE TABLE {acl_user} (\n acl_id integer NOT NULL DEFAULT 0,\n uid int NOT NULL DEFAULT 0,\n PRIMARY KEY (acl_id, uid)\n );");
db_query("CREATE INDEX {acl_user}_uid_index ON {acl_user} (uid)");
db_query("CREATE TABLE {acl_node} (\n acl_id integer NOT NULL DEFAULT 0,\n nid int NOT NULL DEFAULT 0,\n grant_view smallint NOT NULL default 0,\n grant_update smallint NOT NULL default 0,\n grant_delete smallint NOT NULL default 0,\n priority smallint NOT NULL default 0,\n PRIMARY KEY (acl_id, nid)\n );");
break;
}
}
function acl_uninstall() {
if ($GLOBALS['db_type'] == 'pgsql') {
db_query('DROP INDEX {acl_user}_uid_index');
}
db_query('DROP TABLE {acl}');
db_query('DROP TABLE {acl_user}');
db_query('DROP TABLE {acl_node}');
}
function acl_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
db_query('LOCK TABLES {sequences} WRITE');
$ret[] = update_sql("UPDATE {sequences} SET name = '" . db_prefix_tables('{acl}_acl_id') . "' WHERE name = 'acl_id'");
db_query('UNLOCK TABLES');
break;
case 'pgsql':
db_query('START TRANSACTION;');
$ret[] = update_sql("CREATE SEQUENCE {acl}_acl_id_seq START " . db_next_id('acl_id'));
db_query('COMMIT;');
break;
}
return $ret;
}
function acl_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql('ALTER TABLE {acl} DROP INDEX acl_id');
$ret[] = update_sql('ALTER TABLE {acl_user} DROP INDEX acl_id');
$ret[] = update_sql('ALTER TABLE {acl_node} DROP INDEX acl_id');
$ret[] = update_sql('ALTER TABLE {acl_node} DROP INDEX nid');
$ret[] = update_sql('ALTER TABLE {acl} ADD PRIMARY KEY (acl_id)');
$ret[] = update_sql('ALTER TABLE {acl_user} ADD PRIMARY KEY (acl_id, uid)');
$ret[] = update_sql('ALTER TABLE {acl_node} ADD PRIMARY KEY (acl_id, nid)');
break;
case 'pgsql':
$ret[] = update_sql('ALTER TABLE {acl} DROP PRIMARY KEY , ADD PRIMARY KEY (acl_id)');
$ret[] = update_sql('ALTER TABLE {acl_user} DROP PRIMARY KEY , ADD PRIMARY KEY (acl_id, uid)');
$ret[] = update_sql('ALTER TABLE {acl_node} DROP PRIMARY KEY , ADD PRIMARY KEY (acl_id, nid)');
$ret[] = update_sql('CREATE INDEX {acl_user}_uid_index ON {acl_user} (uid)');
break;
}
return $ret;
}
function acl_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
break;
case 'mysql':
if (version_compare(mysql_get_server_info($GLOBALS['active_db']), '4.1.0', '<')) {
return array();
}
break;
case 'pgsql':
return array();
}
$ret = update_convert_table_utf8('acl');
$ret = array_merge($ret, update_convert_table_utf8('acl_node'));
$ret = array_merge($ret, update_convert_table_utf8('acl_user'));
return $ret;
}
function acl_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("ALTER TABLE {acl_node} ADD INDEX (nid)");
break;
case 'pgsql':
$ret[] = update_sql('CREATE INDEX {acl_node}_nid_index ON {acl_node} (nid)');
break;
}
db_query("DELETE FROM {acl_node} WHERE nid NOT IN (SELECT nid FROM {node})");
return $ret;
}
function acl_update_5() {
$ret = array();
db_query("DELETE FROM {acl_user} WHERE uid NOT IN (SELECT uid FROM {users})");
return $ret;
}
function acl_update_6() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("ALTER TABLE {acl_node} ADD priority smallint(2) NOT NULL default 0");
break;
case 'pgsql':
db_add_column($ret, 'acl_node', 'priority', 'smallint', array(
'default' => 0,
'not null' => TRUE,
));
break;
}
return $ret;
}