system_update_7035
- Versions
- 7
system_update_7035()
Migrate upload module files to the new {file} table.
Related topics
Code
modules/system/system.install, line 2511
<?php
function system_update_7035() {
if (!db_table_exists('upload')) {
return;
}
// The old {files} tables still exists. We migrate core data from upload
// module, but any contrib module using it will need to do its own update.
$result = db_query('SELECT fid, uid, filename, filepath AS uri, filemime, filesize, status, timestamp FROM {files} f INNER JOIN {upload} u ON u.fid = f.fid', array(), array('fetch' => PDO::FETCH_ASSOC));
// We will convert filepaths to uri using the default schmeme
// and stripping off the existing file directory path.
$basename = variable_get('file_directory_path', conf_path() . '/files');
$scheme = variable_get('file_default_scheme', 'public') . '://';
$fids = array();
// TODO: does this function need to run in batch mode, or should we use a multi-insert?
foreach ($result as $file) {
$file['uri'] = $scheme . str_replace($basename, '', $file['uri']);
$file['uri'] = file_stream_wrapper_uri_normalize($file['uri']);
db_insert('file')->fields($file)->execute();
$fids[] = $file['fid'];
}
// TODO: delete the found fids from {files}?
}
?>Login or register to post comments 