function comment_upload_update_2 in Comment Upload 6
Same name and namespace in other branches
- 5 comment_upload.install \comment_upload_update_2()
Move previously saved data from {files}, {file_revisions} and {comment_files} into {comment_upload_files}.
Implementation of hook_update_N().
File
- ./
comment_upload.install, line 115 - The install file that defines the tables in use by comment_upload.
Code
function comment_upload_update_2() {
$ret = array();
$ret[] = update_sql("CREATE TABLE {comment_upload_files} (\n `fid` int(10) unsigned NOT NULL default '0',\n `nid` int(10) unsigned NOT NULL default '0',\n `cid` int NOT NULL default '0',\n `filename` varchar(255) NOT NULL default '',\n `filepath` varchar(255) NOT NULL default '',\n `filemime` varchar(255) NOT NULL default '',\n `filesize` int(10) unsigned NOT NULL default '0',\n description varchar(255) NOT NULL default '',\n list tinyint(1) unsigned NOT NULL default 0,\n PRIMARY KEY (`fid`)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$max_fid = db_result(db_query("SELECT MAX(fid) FROM {comment_files}"));
$results = db_query("SELECT f.fid, cf.nid, cf.cid, cf.cid, f.filename, f.filepath, f.filemime, f.filesize, r.list, r.description FROM {files} f INNER JOIN {file_revisions} r ON f.fid = r.fid INNER JOIN {comment_files} cf ON f.fid = cf.fid WHERE f.nid = 0");
while ($c = db_fetch_object($results)) {
db_query("INSERT INTO {comment_upload_files} (fid, nid, cid, filename, filepath, filemime, filesize, description, list) VALUES(%d, %d, %d, '%s', '%s', '%s', %d, '%s', %d)", $c->fid, $c->nid, $c->cid, $c->filename, $c->filepath, $c->filemime, $c->filesize, $c->description, $c->list);
db_query("DELETE FROM {files} WHERE fid = %d", $c->fid);
db_query("DELETE FROM {file_revisions} WHERE fid = %d", $c->fid);
}
if ($max_fid) {
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES('" . db_prefix_tables('{comment_upload_files}') . "_fid', {$max_fid})");
}
$ret[] = update_sql("DROP TABLE {comment_files}");
return $ret;
}