You are here

function user_import_install in User Import 5

Same name and namespace in other branches
  1. 5.2 user_import.install \user_import_install()
  2. 6.4 user_import.install \user_import_install()
  3. 6.2 user_import.install \user_import_install()
  4. 7.3 user_import.install \user_import_install()
  5. 7.2 user_import.install \user_import_install()

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.

File

./user_import.install, line 13

Code

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;
}