You are here

avatar_selection.install in Avatar Selection 5

File

avatar_selection.install
View source
<?php

/**
 * Implementation of hook_install()
 * just give a message
 */
function avatar_selection_install() {
  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        avatar varchar(255) NOT NULL UNIQUE,\n        access varchar(255),\n        og_access varchar(255),\n        PRIMARY KEY (avatar)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {avatar_selection} (\n        avatar varchar(255) NOT NULL UNIQUE,\n        access varchar(255),\n        og_access varchar(255),\n        PRIMARY KEY (avatar)\n      )");
      break;
  }
}

/**
 * Implementation of hook_uninstall().
 */
function avatar_selection_uninstall() {

  // delete the variables we created.
  variable_del('avatar_selection_disable_user_upload');
  variable_del('avatar_selection_force_user_avatar_reg');
  variable_del('avatar_selection_force_user_avatar');
  variable_del('avatar_selection_avatar_per_page');
  variable_del('avatar_selection_set_random_default');

  // delete the images
  $dir = file_create_path('avatar_selection') . '/';
  $listings = file_scan_directory($dir, '.*\\.(gif|GIF|Gif|jpg|JPG|Jpg|jpeg|JPEG|Jpeg|png|PNG|Png)', array(
    '.',
    '..',
    'CVS',
  ), 0, FALSE);
  if ($listings) {
    foreach ($listings as $listing) {
      file_delete($dir . $listing->basename);
    }
  }

  // drop the avatar_selection table
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $deleted = db_query("DROP TABLE IF EXISTS {avatar_selection}");
      break;
    case 'pgsql':
      $deleted = db_query("DROP TABLE {avatar_selection}");
      break;
  }

  // clear the cache tables
  cache_clear_all(null, 'cache');
  cache_clear_all(null, 'cache_filter');
  cache_clear_all(null, 'cache_menu');
  cache_clear_all(null, 'cache_page');
  watchdog('Avatar Selection', 'avatar_selection module removed');
}
function avatar_selection_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("CREATE TABLE if not exists {avatar_selection} (\n        avatar varchar(255) NOT NULL UNIQUE,\n        access varchar(255),\n        PRIMARY KEY (avatar)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {avatar_selection} (\n        avatar varchar(255) NOT NULL UNIQUE,\n        access varchar(255),\n        PRIMARY KEY (avatar)\n      )");
      break;
  }
  return $ret;
}
function avatar_selection_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {avatar_selection} \n        ADD COLUMN og_access varchar(255)");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {avatar_selection} \n        ADD COLUMN og_access varchar(255)");
      break;
  }
  return $ret;
}

Functions