summaryrefslogtreecommitdiff
path: root/modules/system/system.install
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-11-13 01:48:14 +0000
committerDries Buytaert <dries@buytaert.net>2010-11-13 01:48:14 +0000
commita160006defd02442cd3fa0f098094385ebb8fcf1 (patch)
tree116520dbd934e99d38affb3790b302ed76e99123 /modules/system/system.install
parentf2e5ed5ce584e79048fcb98e40a05bfb58c3ebdc (diff)
downloadbrdo-a160006defd02442cd3fa0f098094385ebb8fcf1.tar.gz
brdo-a160006defd02442cd3fa0f098094385ebb8fcf1.tar.bz2
- Patch #966238 by cosmicdreams, bfroehle, catch, mfb, carlos8f, marcingy: system_update_7061() stops migrating data if upload.fid is not found in files table, resulting in data loss.
Diffstat (limited to 'modules/system/system.install')
-rw-r--r--modules/system/system.install137
1 files changed, 69 insertions, 68 deletions
diff --git a/modules/system/system.install b/modules/system/system.install
index f56ef4055..94c0bb2ee 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -2772,93 +2772,94 @@ function system_update_7061(&$sandbox) {
$sandbox['max'] = db_query("SELECT COUNT(*) FROM {system_update_7061}")->fetchField();
}
- $node_revisions = array();
-
// Determine vids for this batch.
// Process all files attached to a given revision during the same batch.
- $limit = 100;
+ $limit = variable_get('upload_update_batch_size', 100);
$vids = db_query_range('SELECT vid FROM {system_update_7061} WHERE vid > :lastvid ORDER BY vid', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']))
->fetchCol();
// Retrieve information on all the files attached to these revisions.
- $result = db_query('SELECT u.fid, u.vid, u.list, u.description, n.nid, n.type, u.weight FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid IN (:vids) ORDER BY u.vid, u.weight, u.fid', array(':vids' => $vids));
- foreach ($result as $record) {
- // For each uploaded file, retrieve the corresponding data from the old
- // files table (since upload doesn't know about the new entry in the
- // file_managed table).
- $file = db_select('files', 'f')
- ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
- ->condition('f.fid', $record->fid)
- ->execute()
- ->fetchAssoc();
- if (!$file) {
- continue;
- }
+ if (!empty($vids)) {
+ $node_revisions = array();
+ $result = db_query('SELECT u.fid, u.vid, u.list, u.description, n.nid, n.type, u.weight FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid IN (:vids) ORDER BY u.vid, u.weight, u.fid', array(':vids' => $vids));
+ foreach ($result as $record) {
+ // For each uploaded file, retrieve the corresponding data from the old
+ // files table (since upload doesn't know about the new entry in the
+ // file_managed table).
+ $file = db_select('files', 'f')
+ ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
+ ->condition('f.fid', $record->fid)
+ ->execute()
+ ->fetchAssoc();
+ if (!$file) {
+ continue;
+ }
- // Add in the file information from the upload table.
- $file['description'] = $record->description;
- $file['display'] = $record->list;
+ // Add in the file information from the upload table.
+ $file['description'] = $record->description;
+ $file['display'] = $record->list;
- // Create one record for each revision that contains all the uploaded files.
- $node_revisions[$record->vid]['nid'] = $record->nid;
- $node_revisions[$record->vid]['vid'] = $record->vid;
- $node_revisions[$record->vid]['type'] = $record->type;
- $node_revisions[$record->vid]['file'][LANGUAGE_NONE][] = $file;
- }
+ // Create one record for each revision that contains all the uploaded
+ // files.
+ $node_revisions[$record->vid]['nid'] = $record->nid;
+ $node_revisions[$record->vid]['vid'] = $record->vid;
+ $node_revisions[$record->vid]['type'] = $record->type;
+ $node_revisions[$record->vid]['file'][LANGUAGE_NONE][] = $file;
+ }
- // Now that we know which files belong to which revisions, update the files'
- // database entries, and save a reference to each file in the upload field on
- // their node revisions.
- $basename = variable_get('file_directory_path', conf_path() . '/files');
- $scheme = file_default_scheme() . '://';
- foreach ($node_revisions as $vid => $revision) {
- foreach ($revision['file'][LANGUAGE_NONE] as $delta => $file) {
- // We will convert filepaths to uri using the default scheme
- // and stripping off the existing file directory path.
- $file['uri'] = $scheme . str_replace($basename, '', $file['filepath']);
- $file['uri'] = file_stream_wrapper_uri_normalize($file['uri']);
- unset($file['filepath']);
- // Insert into the file_managed table.
- // Each fid should only be stored once in file_managed.
- db_merge('file_managed')
- ->key(array(
- 'fid' => $file['fid'],
- ))
- ->fields(array(
- 'uid' => $file['uid'],
- 'filename' => $file['filename'],
- 'uri' => $file['uri'],
- 'filemime' => $file['filemime'],
- 'filesize' => $file['filesize'],
- 'status' => $file['status'],
- 'timestamp' => $file['timestamp'],
- ))
- ->execute();
+ // Now that we know which files belong to which revisions, update the
+ // files'// database entries, and save a reference to each file in the
+ // upload field on their node revisions.
+ $basename = variable_get('file_directory_path', conf_path() . '/files');
+ $scheme = file_default_scheme() . '://';
+ foreach ($node_revisions as $vid => $revision) {
+ foreach ($revision['file'][LANGUAGE_NONE] as $delta => $file) {
+ // We will convert filepaths to uri using the default scheme
+ // and stripping off the existing file directory path.
+ $file['uri'] = $scheme . str_replace($basename, '', $file['filepath']);
+ $file['uri'] = file_stream_wrapper_uri_normalize($file['uri']);
+ unset($file['filepath']);
+ // Insert into the file_managed table.
+ // Each fid should only be stored once in file_managed.
+ db_merge('file_managed')
+ ->key(array(
+ 'fid' => $file['fid'],
+ ))
+ ->fields(array(
+ 'uid' => $file['uid'],
+ 'filename' => $file['filename'],
+ 'uri' => $file['uri'],
+ 'filemime' => $file['filemime'],
+ 'filesize' => $file['filesize'],
+ 'status' => $file['status'],
+ 'timestamp' => $file['timestamp'],
+ ))
+ ->execute();
+
+ // Add the usage entry for the file.
+ $file = (object) $file;
+ file_usage_add($file, 'file', 'node', $revision['nid']);
+
+ // Update the node revision's upload file field with the file data.
+ $revision['file'][LANGUAGE_NONE][$delta] = array('fid' => $file->fid, 'display' => $file->display, 'description' => $file->description);
+ }
- // Add the usage entry for the file.
- $file = (object) $file;
- file_usage_add($file, 'file', 'node', $revision['nid']);
+ // Write the revision's upload field data into the field_upload tables.
+ $node = (object) $revision;
+ _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'upload', $node->file);
- // Update the node revision's upload file field with the file data.
- $revision['file'][LANGUAGE_NONE][$delta] = array('fid' => $file->fid, 'display' => $file->display, 'description' => $file->description);
+ // Update our progress information for the batch update.
+ $sandbox['progress']++;
+ $sandbox['last_vid_processed'] = $vid;
}
-
- // Write the revision's upload field data into the field_upload tables.
- $node = (object) $revision;
- _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'upload', $node->file);
-
- // Update our progress information for the batch update.
- $sandbox['progress']++;
- $sandbox['last_vid_processed'] = $vid;
}
// If less than limit node revisions were processed, the update process is
// finished.
- if (count($node_revisions) < $limit) {
+ if (count($vids) < $limit) {
$finished = TRUE;
}
-
// If there's no max value then there's nothing to update and we're finished.
if (empty($sandbox['max']) || isset($finished)) {
db_drop_table('upload');