View source
<?php
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;
}
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;
}
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}');
}