You are here

user_import.install in User Import 5

File

user_import.install
View source
<?php

/**
 * Implementation of hook_install()
 *
 * This will automatically install the database tables for the user import module for both the MySQL and PostgreSQL databases.
 *
 * If you are using another database, you will have to install the tables by hand, using the queries below as a reference.
 *
 * Note that the curly braces around table names are a drupal-specific feature to allow for automatic database table prefixing,
 * and will need to be removed.
 */
function user_import_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $query1 = db_query("CREATE TABLE IF NOT EXISTS {user_import} (\n                        import_id int(10) unsigned NOT NULL auto_increment,\n                        name varchar(25) NOT NULL default '',\n                        filename varchar(50) NOT NULL default '',\n                        oldfilename varchar(50) NOT NULL default '',\n                        filepath tinytext NOT NULL,\n                        started int(11) NOT NULL default '0',\n                        pointer int(10) NOT NULL default '0',\n                        processed int(10) NOT NULL default '0',\n                        valid int(10) NOT NULL default '0',\n                        first_line_skip int(1) NOT NULL default '0',\n                        contact int(1) NOT NULL default '0',\n                        username_space int(1) NOT NULL default '0',\n                        send_email int(1) NOT NULL default '0',\n                        field_match longtext NOT NULL,\n                        roles varchar(255) NOT NULL default '',\n                        options longtext NOT NULL,\n                        setting varchar(10) NOT NULL default '',\n                        PRIMARY KEY  (import_id)\n                        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $query2 = db_query("CREATE TABLE IF NOT EXISTS {user_import_errors} (\n                        import_id int(10) NOT NULL default '0',\n                        data longtext NOT NULL,\n                        errors longtext NOT NULL,\n                        KEY import_id (import_id)\n                        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      if ($query1 && $query2) {
        $created = TRUE;
      }
      break;
    case 'pgsql':
      $query1 = db_query("CREATE TABLE {user_import} (\n\t                        import_id serial,\n\t                        name varchar(25) NOT NULL default '',\n\t                        filename varchar(50) NOT NULL default '',\n\t                        oldfilename varchar(50) NOT NULL default '',\n\t                        filepath varchar NOT NULL,\n\t                        started int NOT NULL default '0',\n\t                        pointer int NOT NULL default '0',\n\t                        processed int NOT NULL default '0',\n\t                        valid int NOT NULL default '0',\n\t                        first_line_skip int NOT NULL default '0',\n\t                        contact int NOT NULL default '0',\n\t                        username_space int NOT NULL default '0',\n\t                        send_email int NOT NULL default '0',\n\t                        field_match text NOT NULL,\n\t                        roles varchar(255) NOT NULL default '',\n\t                        options text NOT NULL,\n\t                        setting varchar(10) NOT NULL default '',\n\t                        PRIMARY KEY (import_id)\n\t                        );");
      $query2 = db_query("CREATE TABLE  {user_import_errors} (\n\t                        import_id int NOT NULL default '0',\n\t                        data text NOT NULL,\n\t                        errors varchar(255) NOT NULL default '',\n\t                        PRIMARY KEY (import_id)\n\t                        );");
      break;
  }
  if ($created) {
    drupal_set_message(t('User Import module installed successfully.'));
  }
  else {
    drupal_set_message(t('Table installation for the User Import module was unsuccessful. The tables may need to be installed by hand. See user_import.install file for a list of the installation queries.'), 'error');
  }
  return;
}
function user_import_update_1() {
  _system_update_utf8(array(
    'user_import',
    'user_import_errors',
  ));
  return;
}
function user_import_update_2() {
  $ret = array();
  db_add_column($ret, 'user_import', 'options', 'longtext');
  return $ret;
}
function user_import_update_3() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {user_import} CHANGE iid import_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  $ret[] = update_sql("ALTER TABLE {user_import} CHANGE first_line first_line_skip INT(10) UNSIGNED NOT NULL default '0'");
  $ret[] = update_sql("ALTER TABLE {user_import_errors} CHANGE iid import_id INT(10) UNSIGNED NOT NULL default '0'");
  return $ret;
}
function user_import_update_4() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {user_import_errors} CHANGE error errors longtext NOT NULL");
  return $ret;
}
function user_import_update_5() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {user_import_errors} CHANGE errors errors longtext NOT NULL");
  return $ret;
}

/**
* Implementation of hook_uninstall().
*/
function user_import_uninstall() {
  db_query('DROP TABLE {user_import}');
  db_query('DROP TABLE {user_import_errors}');
  variable_del('user_import_settings');
  variable_del('user_import_max');
  variable_del('user_import_line_max');
  variable_del('user_export_checked_usernames');
}