You are here

function avatar_selection_install in Avatar Selection 5.2

Same name and namespace in other branches
  1. 5 avatar_selection.install \avatar_selection_install()
  2. 6 avatar_selection.install \avatar_selection_install()
  3. 7 avatar_selection.install \avatar_selection_install()

Implementation of hook_install().

Write table structure to the SQL database. If the 'user_picture' option is set to off, a warning will be printed.

File

./avatar_selection.install, line 14
The Avatar Selection module install file.

Code

function avatar_selection_install() {
  $t = get_t();
  if (!variable_get('user_pictures', 0)) {
    drupal_set_message($t('User Pictures option is disabled.  You will need to enable this option before you can use the Avatar Selection module.  You may configure this setting at the <a href="@url">User settings</a> page.', array(
      '@url' => url('admin/user/settings'),
    )));
  }
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE IF NOT exists {avatar_selection} (\n        aid int(10) unsigned NOT NULL,\n        avatar varchar(255) NOT NULL,\n        weight int(10) NOT NULL DEFAULT 0,\n        name varchar(255),\n        PRIMARY KEY (aid),\n        UNIQUE KEY avatar (avatar)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE IF NOT exists {avatar_selection_roles} (\n        aid int(10) unsigned NOT NULL DEFAULT 0,\n        rid int(10) NOT NULL\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("CREATE TABLE IF NOT exists {avatar_selection_og} (\n        aid int(10) unsigned NOT NULL DEFAULT 0,\n        ogid int(10) NOT NULL\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {avatar_selection} (\n        aid serial CHECK (aid >= 0),\n        avatar varchar(255) NOT NULL,\n        weight integer NOT NULL DEFAULT 0,\n        name varchar(255),\n        PRIMARY KEY (aid),\n        UNIQUE (avatar)\n      )");
      db_query("CREATE TABLE {avatar_selection_roles} (\n        aid integer NOT NULL DEFAULT 0,\n        rid integer NOT NULL\n      )");
      db_query("CREATE TABLE {avatar_selection_og} (\n        aid integer NOT NULL DEFAULT 0,\n        ogid integer NOT NULL\n      )");
      break;
  }
}