You are here

function filefield_paths_install in File (Field) Paths 5

Same name and namespace in other branches
  1. 8 filefield_paths.install \filefield_paths_install()
  2. 6.2 filefield_paths.install \filefield_paths_install()
  3. 6 filefield_paths.install \filefield_paths_install()
  4. 7 filefield_paths.install \filefield_paths_install()

Implementation of hook_install().

File

./filefield_paths.install, line 10

Code

function filefield_paths_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {filefield_paths} (\n        type varchar(32) NOT NULL default '',\n        field varchar(32) NOT NULL default '',\n        filename mediumtext NOT NULL,\n        filepath mediumtext NOT NULL\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
      db_query("ALTER TABLE {files} ADD COLUMN origname varchar(255) NOT NULL default ''");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {filefield_paths} (\n        type varchar(32) NOT NULL default '',\n        field varchar(32) NOT NULL default '',\n        filename text NOT NULL,\n        filepath text NOT NULL\n      )");
      db_add_column($ret = array(), 'files', 'origname', 'varchar(255)', array(
        'not null' => TRUE,
        'default' => '',
      ));
      break;
  }
  $result = db_query("SELECT fid, filename FROM {files}");
  while ($file = db_fetch_object($result)) {
    db_query("UPDATE {files} SET origname = '%s' WHERE fid = %d", $file->filename, $file->fid);
  }
  variable_set('filefield_paths_schema_version', 5103);
}