You are here

asset.install in Asset 5

Same filename and directory in other branches
  1. 5.2 asset.install
  2. 6 asset.install
  3. 7 asset.install

File

asset.install
View source
<?php

/**
 * Implementation of hook_install()
 */
function asset_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {asset} (\n        aid int(10) unsigned NOT NULL,\n        type varchar(32) NOT NULL default '',\n        dirname varchar(128) NOT NULL default '',\n        extension varchar(128) NOT NULL default '',\n        filename varchar(255) NOT NULL default '',\n        filesize int(11) NOT NULL default '0',\n        uid int(10) unsigned NOT NULL,\n        status tinyint unsigned NOT NULL, \n        author varchar(128) NOT NULL default '',\n        title varchar(128) NOT NULL default '',\n        description text NOT NULL,\n        PRIMARY KEY  (aid)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {asset_node} (\n        aid int(10) unsigned NOT NULL,\n        nid int(10) unsigned NOT NULL,\n        refs int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (aid,nid)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {asset_role} (\n        aid int(10) unsigned NOT NULL,\n        rid int(10) unsigned NOT NULL,\n        status tinyint unsigned NOT NULL default '0',\n        PRIMARY KEY  (aid,rid)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {asset} (\n        aid SERIAL,\n        type varchar(32) NOT NULL default '',\n        dirname varchar(128) NOT NULL default '',\n        extension varchar(128) NOT NULL default '',\n        filename varchar(255) NOT NULL default '',\n        filesize bigint NOT NULL default '0',\n        uid integer NOT NULL,\n        status smallint NOT NULL, \n        author varchar(128) NOT NULL default '',\n        title varchar(128) NOT NULL default '',\n        description text NOT NULL,\n        PRIMARY KEY (aid)\n      )");
      db_query("CREATE TABLE {asset_node} (\n        aid integer NOT NULL,\n        nid integer NOT NULL,\n        refs integer NOT NULL default '0',\n        PRIMARY KEY (aid,nid)\n      )");
      db_query("CREATE TABLE {asset_role} (\n        aid integer NOT NULL,\n        rid integer NOT NULL,\n        status smallint NOT NULL default '0',\n        PRIMARY KEY (aid,rid)\n      )");
      break;
  }
  drupal_set_message(t('Asset tables have been configured.'));
}
function asset_update_1() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {asset} ADD COLUMN type varchar(32) NOT NULL default ''");
      $ret[] = update_sql("UPDATE {asset} SET type='local'");
      break;
  }
  return $ret;
}
function asset_update_2() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
    case 'pgsql':
      $ret[] = update_sql("UPDATE {asset} SET dirname = TRIM('/' FROM REPLACE(dirname,'sites/default/files',''))");
      break;
  }
  return $ret;
}

/*
 * Add asset_role table
 */
function asset_update_3() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {asset_role} (\n        aid int(10) unsigned NOT NULL,\n        rid int(10) unsigned NOT NULL,\n        status tinyint unsigned NOT NULL default '0',\n        PRIMARY KEY  (aid,rid)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {asset_role} (\n        aid integer NOT NULL,\n        rid integer NOT NULL,\n        status smallint NOT NULL default '0',\n        PRIMARY KEY  (aid,rid)\n      )");
      break;
  }
  return $ret;
}

/**
 * Give directories their own asset type.
 */
function asset_update_4() {
  $ret[] = update_sql("UPDATE {asset} SET type='directory' WHERE type='local' AND extension=''");
  $dir = 'PUBLIC';
  if (asset_check_directory($dir, FILE_CREATE_DIRECTORY)) {
    drupal_set_message('Created PUBLIC asset directory');
    db_query("UPDATE {asset} SET status=1 WHERE type='directory' AND dirname='' AND filename='PUBLIC'");
  }
  return $ret;
}
function asset_uninstall() {
  db_query('DROP TABLE {asset}');
  db_query('DROP TABLE {asset_node}');
  db_query('DROP TABLE {asset_role}');
}

Functions

Namesort descending Description
asset_install Implementation of hook_install()
asset_uninstall
asset_update_1
asset_update_2
asset_update_3
asset_update_4 Give directories their own asset type.