You are here

simple_access.install in Simple Access 5.2

Simple Access Installation file

File

simple_access.install
View source
<?php

/**
 * @file
 * Simple Access Installation file
 */

/**
 * Implementation of hook_install()
 */
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        `sa_view` tinyint unsigned NOT NULL default '0',\n        `sa_update` tinyint unsigned NOT NULL default '0',\n        `sa_delete` tinyint unsigned NOT NULL default '0',\n        PRIMARY KEY  (nid, gid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {simple_access_owner} (\n        nid int(10) unsigned NOT NULL default '0',\n        `sa_view` tinyint unsigned NOT NULL default '0',\n        `sa_update` tinyint unsigned NOT NULL default '0',\n        `sa_delete` tinyint unsigned NOT NULL default '0',\n        PRIMARY KEY  (nid)\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 */;");
      db_query("CREATE TABLE {simple_access_profiles} (\n        pid int(10) NOT NULL default '0',\n        name varchar(50) NOT NULL default '',\n        weight int(3) NOT NULL default '0',\n        PRIMARY KEY  (`pid`)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {simple_access_profiles_access} (\n        pid int(10) unsigned NOT NULL default '0',\n        gid int(10) unsigned NOT NULL default '0',\n        sa_view tinyint(3) unsigned NOT NULL default '0',\n        sa_update tinyint(3) unsigned NOT NULL default '0',\n        sa_delete tinyint(3) unsigned NOT NULL default '0',\n        PRIMARY KEY  (pid,gid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {simple_access_profiles_node} (\n        nid int(10) NOT NULL,\n        pid int(10) NOT NULL,\n        PRIMARY KEY  (nid,pid)\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        sa_view integer unsigned NOT NULL default '0',\n        sa_update integer unsigned NOT NULL default '0',\n        sa_delete integer unsigned NOT NULL default '0',\n      );");
      db_query("CREATE TABLE {simple_access_owner} (\n        nid integer unsigned NOT NULL default '0',\n        sa_view integer unsigned NOT NULL default '0',\n        sa_update integer unsigned NOT NULL default '0',\n        sa_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      );");
      db_query("CREATE TABLE {simple_access_profiles} (\n        pid int(10) NOT NULL default '0',\n        name varchar(50) NOT NULL default '',\n        weight int(3) NOT NULL default '0'\n      );");
      db_query("CREATE TABLE {simple_access_profiles_access} (\n        pid int(10) unsigned NOT NULL default '0',\n        gid int(10) unsigned NOT NULL default '0',\n        sa_view int(3) unsigned NOT NULL default '0',\n        sa_update int(3) unsigned NOT NULL default '0',\n        sa_delete int(3) unsigned NOT NULL default '0'\n      );");
      db_query("CREATE TABLE {simple_access_profiles_node} (\n        nid int(10) NOT NULL,\n        pid int(10) NOT NULL\n      );");
      break;
  }
  drupal_set_message(t('simple access has created the required tables.'));
}

/** 
 * Implementation of hook_uninstall()
 */
function simple_access_uninstall() {
  db_query('DROP TABLE {simple_access_groups}');
  db_query('DROP TABLE {simple_access_owner}');
  db_query('DROP TABLE {simple_access_roles}');
  db_query('DROP TABLE {simple_access_node}');
  db_query('DROP TABLE {simple_access_profiles}');
  db_query('DROP TABLE {simple_access_profiles_access}');
  db_query('DROP TABLE {simple_access_profiles_node}');
  variable_del('sa_display');
  variable_del('sa_showgroups');
  drupal_set_message(t('simple access has been uninstalled'));
}

/**
 * Implementation of hook_enable
 */
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'),
  )));
}

/**
 * Implementation of hook_disable()
 */
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'),
  )));
}

/**
 * Updates
 */
function simple_access_update_4() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      update_sql("CREATE TABLE {simple_access_profiles} (\n        pid int(10) NOT NULL default '0',\n        name varchar(50) NOT NULL default '',\n        weight int(3) NOT NULL default '0',\n        PRIMARY KEY  (`pid`)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      update_sql("CREATE TABLE {simple_access_profiles_access} (\n        pid int(10) unsigned NOT NULL default '0',\n        gid int(10) unsigned NOT NULL default '0',\n        `view` tinyint(3) unsigned NOT NULL default '0',\n        `update` tinyint(3) unsigned NOT NULL default '0',\n        `delete` tinyint(3) unsigned NOT NULL default '0',\n        PRIMARY KEY  (`pid`,`gid`)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      update_sql("CREATE TABLE {simple_access_profiles_node} (\n        nid int(10) NOT NULL,\n        pid int(10) NOT NULL,\n        PRIMARY KEY  (`nid`,`pid`)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      update_sql("CREATE TABLE {simple_access_profiles} (\n        pid int(10) NOT NULL default '0',\n        name varchar(50) NOT NULL default '',\n        weight int(3) NOT NULL default '0'\n      );");
      update_sql("CREATE TABLE {simple_access_profiles_access} (\n        pid int(10) unsigned NOT NULL default '0',\n        gid int(10) unsigned NOT NULL default '0',\n        view tinyint(3) unsigned NOT NULL default '0',\n        update tinyint(3) unsigned NOT NULL default '0',\n        delete tinyint(3) unsigned NOT NULL default '0'\n      );");
      update_sql("CREATE TABLE {simple_access_profiles_node} (\n        nid int(10) NOT NULL,\n        pid int(10) NOT NULL\n      );");
      break;
  }
  return array();
}
function simple_access_update_5() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {simple_access_owner} (\n        nid 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)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {simple_access_owner} (\n        nid 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      );");
      break;
  }
  $ret[] = update_sql('INSERT INTO {simple_access_owner} SELECT nid, 1, 1, 1 FROM {node};');
  return $ret;
}

/**
 * Rename all the fields named view, update, delete to sa_view, sa_update,
 * sa_delete
 */
function simple_access_update_6() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {simple_access_node} \n        CHANGE `view` sa_view tinyint unsigned default '0',\n        CHANGE `update` sa_update tinyint unsigned default '0',\n        CHANGE `delete` sa_delete tinyint unsigned default '0' \n      ");
      $ret[] = update_sql("ALTER TABLE {simple_access_profiles_access} \n        CHANGE `view` sa_view tinyint unsigned default '0',\n        CHANGE `update` sa_update tinyint unsigned default '0',\n        CHANGE `delete` sa_delete tinyint unsigned default '0' \n      ");
      $ret[] = update_sql("ALTER TABLE {simple_access_owner} \n        CHANGE `view` sa_view tinyint unsigned default '0',\n        CHANGE `update` sa_update tinyint unsigned default '0',\n        CHANGE `delete` sa_delete tinyint unsigned default '0' \n      ");
      break;
    case 'pgsql':
      db_change_column($ret, 'simple_access_node', 'view', 'sa_view', 'int');
      db_change_column($ret, 'simple_access_node', 'update', 'sa_update', 'int');
      db_change_column($ret, 'simple_access_node', 'delete', 'sa_delete', 'int');
      db_change_column($ret, 'simple_access_profiles_access', 'view', 'sa_view', 'int');
      db_change_column($ret, 'simple_access_profiles_access', 'update', 'sa_update', 'int');
      db_change_column($ret, 'simple_access_profiles_access', 'delete', 'sa_delete', 'int');
      db_change_column($ret, 'simple_access_owner', 'view', 'sa_view', 'int');
      db_change_column($ret, 'simple_access_owner', 'update', 'sa_update', 'int');
      db_change_column($ret, 'simple_access_owner', 'delete', 'sa_delete', 'int');
      break;
  }
  return $ret;
}

Functions

Namesort descending Description
simple_access_disable Implementation of hook_disable()
simple_access_enable Implementation of hook_enable
simple_access_install Implementation of hook_install()
simple_access_uninstall Implementation of hook_uninstall()
simple_access_update_4 Updates
simple_access_update_5
simple_access_update_6 Rename all the fields named view, update, delete to sa_view, sa_update, sa_delete