You are here

userprotect.install in User protect 5

Same filename and directory in other branches
  1. 8 userprotect.install
  2. 6 userprotect.install
  3. 7 userprotect.install

File

userprotect.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function userprotect_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $query1 = db_query("CREATE TABLE {userprotect} (\n                  uid int(10) unsigned NOT NULL default '0',\n                  up_name int(1) unsigned NOT NULL default '0',\n                  up_mail int(1) unsigned NOT NULL default '0',\n                  up_pass int(1) unsigned NOT NULL default '0',\n                  up_status int(1) unsigned NOT NULL default '0',\n                  up_roles int(1) unsigned NOT NULL default '0',\n                  up_delete int(1) unsigned NOT NULL default '0',\n                  up_edit int(1) unsigned NOT NULL default '0',\n                  up_type char(20) NOT NULL default '',\n                  UNIQUE KEY uid_up_type (uid, up_type)\n                ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      $query1 = db_query("CREATE TABLE {userprotect} (\n                  uid integer NOT NULL default '0',\n                  up_name smallint NOT NULL default '0',\n                  up_mail smallint NOT NULL default '0',\n                  up_pass smallint NOT NULL default '0',\n                  up_status smallint NOT NULL default '0',\n                  up_roles smallint NOT NULL default '0',\n                  up_delete smallint NOT NULL default '0',\n                  up_edit smallint NOT NULL default '0',\n                  up_type char(20) NOT NULL default '',\n                  UNIQUE (uid, up_type)\n                );");
      break;
  }
  if ($query1) {

    // Default settings
    $query2 = db_query("INSERT INTO {userprotect} VALUES (0, 0, 0, 0, 0, 0, 1, 1, 'user')");
    $query3 = db_query("INSERT INTO {userprotect} VALUES (1, 0, 0, 0, 0, 0, 1, 1, 'user')");
    $query4 = db_query("INSERT INTO {userprotect} VALUES (1, 1, 1, 1, 1, 1, 1, 1, 'admin')");
    $query5 = db_result(db_query('SELECT perm FROM {permission} WHERE rid = 2'));
    $query6 = db_query("UPDATE {permission} SET perm = '%s' WHERE rid = 2", $query5 . ', change own e-mail, change own password');
  }
  if ($query1 && $query2 && $query3 && $query4 && $query5 && $query6) {
    drupal_set_message('The User Protect module was installed successfully.');
  }
  else {
    drupal_set_message('There was an error installing the User Protect database tables.', 'error');
  }
}

/**
 * Rebuilds the menu due to code changes.
 */
function userprotect_update_5000() {
  $ret = array();
  menu_rebuild();
  $ret[] = array(
    'success' => TRUE,
    'query' => "Successfully rebuilt menus.",
  );
  return $ret;
}

/**
 * Implementation of hook_uninstall().
 */
function userprotect_uninstall() {
  if (db_table_exists('userprotect')) {
    $query1 = db_query('DROP TABLE {userprotect}');
  }
  variable_del('userprotect_protection_defaults');
  variable_del('userprotect_autoprotect');
  variable_del('userprotect_administrator_bypass_defaults');
  variable_del('userprotect_role_protections');
  if ($query1) {
    drupal_set_message('The User Protect module was uninstalled successfully.');
  }
  else {
    drupal_set_message('There was an error removing the User Protect database tables.', 'error');
  }
}

Functions

Namesort descending Description
userprotect_install Implementation of hook_install().
userprotect_uninstall Implementation of hook_uninstall().
userprotect_update_5000 Rebuilds the menu due to code changes.