View source
<?php
function simple_access_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {simple_access_node} (\n nid int(10) unsigned NOT NULL default '0',\n gid int(10) unsigned NOT NULL default '0',\n `view` tinyint unsigned NOT NULL default '0',\n `update` tinyint unsigned NOT NULL default '0',\n `delete` tinyint unsigned NOT NULL default '0',\n PRIMARY KEY (nid, gid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {simple_access_groups} (\n gid int(10) NOT NULL default '0',\n name varchar(50) NOT NULL default '',\n weight int(3) NOT NULL default '0'\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {simple_access_roles} (\n gid int(10) NOT NULL default '0',\n rid int(10) NOT NULL default '0'\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {simple_access_groups} (\n nid integer unsigned NOT NULL default '0',\n gid integer unsigned NOT NULL default '0',\n view integer unsigned NOT NULL default '0',\n update integer unsigned NOT NULL default '0',\n delete integer unsigned NOT NULL default '0',\n );");
db_query("CREATE TABLE {simple_access_groups} (\n gid serial NOT NULL,\n name varchar(50) NOT NULL default '',\n weight integer NOT NULL default '0'\n );");
db_query("CREATE TABLE {simple_access_roles} (\n gid integer NOT NULL default '0',\n rid integer NOT NULL default '0'\n );");
break;
}
drupal_set_message(t('simple access has created the required tables.'));
}
function simple_access_uninstall() {
db_query('DROP TABLE {simple_access_groups}');
db_query('DROP TABLE {simple_access_roles}');
db_query('DROP TABLE {simple_access_node}');
variable_del('sa_display');
variable_del('sa_showgroups');
drupal_set_message(t('simple access has been uninstalled'));
}
function simple_access_enable() {
drupal_set_message(t('To fully activate simple_access you also need to !rebuild_permissions.', array(
'!rebuild_permissions' => l(t('rebuild permissions'), 'admin/content/node-settings'),
)));
}
function simple_access_disable() {
drupal_set_message(t('To fully disable simple_access you also need to !rebuild_permissions.', array(
'!rebuild_permissions' => l(t('rebuild permissions'), 'admin/content/node-settings'),
)));
}
function simple_access_update_1() {
return _system_update_utf8(array(
'simple_access_groups',
'simple_access_roles',
));
}
function simple_access_update_2() {
$ret[] = update_sql("CREATE TABLE {simple_access_node} SELECT nid, gid, grant_view, grant_update, grant_delete FROM {node_access} WHERE realm = 'simple_access'");
$ret[] = update_sql('ALTER TABLE {simple_access_node} ADD PRIMARY KEY (nid)');
$ret[] = update_sql("ALTER TABLE {simple_access_node} CHANGE `grant_view` `view` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0', CHANGE `grant_update` `update` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0', CHANGE `grant_delete` `delete` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' ");
return $ret;
}
function simple_access_update_3() {
$ret[] = update_sql('ALTER TABLE {simple_access_node} DROP PRIMARY KEY');
$ret[] = update_sql('ALTER TABLE {simple_access_node} ADD PRIMARY KEY (nid,gid)');
return $ret;
}