summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2015-09-08 00:53:36 -0400
committerDavid Rothstein <drothstein@gmail.com>2015-09-08 00:53:36 -0400
commit4cc037d4dd9b52ee59eecb3bbf1795c75c0ead5a (patch)
treec08a0caee0ac5e015abc54adf4fdf676735a7b81 /modules/system
parent731dfacab8bf39918c135bf4939e56a76dc6ab34 (diff)
downloadbrdo-4cc037d4dd9b52ee59eecb3bbf1795c75c0ead5a.tar.gz
brdo-4cc037d4dd9b52ee59eecb3bbf1795c75c0ead5a.tar.bz2
Issue #1260938 by dawehner, David_Rothstein, flaviovs, Fabianx, pfrenssen, boran, jelo, neclimdul, scorchio, Berdir, vijaycs85: D6 to D7 update can fail on duplicate files in system update #7061
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/system.install20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/system/system.install b/modules/system/system.install
index 64c989a61..dde846969 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -2803,6 +2803,16 @@ function system_update_7061(&$sandbox) {
->from($query)
->execute();
+ // Retrieve a list of duplicate files with the same filepath. Only the
+ // most-recently uploaded of these will be moved to the new {file_managed}
+ // table (and all references will be updated to point to it), since
+ // duplicate file URIs are not allowed in Drupal 7.
+ // Since the Drupal 6 to 7 upgrade path leaves the {files} table behind
+ // after it's done, custom or contributed modules which need to migrate
+ // file references of their own can use a similar query to determine the
+ // file IDs that duplicate filepaths were mapped to.
+ $sandbox['duplicate_filepath_fids_to_use'] = db_query("SELECT filepath, MAX(fid) FROM {files} GROUP BY filepath HAVING COUNT(*) > 1")->fetchAllKeyed();
+
// Initialize batch update information.
$sandbox['progress'] = 0;
$sandbox['last_vid_processed'] = -1;
@@ -2832,6 +2842,16 @@ function system_update_7061(&$sandbox) {
continue;
}
+ // If this file has a duplicate filepath, replace it with the
+ // most-recently uploaded file that has the same filepath.
+ if (isset($sandbox['duplicate_filepath_fids_to_use'][$file['filepath']]) && $record->fid != $sandbox['duplicate_filepath_fids_to_use'][$file['filepath']]) {
+ $file = db_select('files', 'f')
+ ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
+ ->condition('f.fid', $sandbox['duplicate_filepath_fids_to_use'][$file['filepath']])
+ ->execute()
+ ->fetchAssoc();
+ }
+
// Add in the file information from the upload table.
$file['description'] = $record->description;
$file['display'] = $record->list;