Prechádzať zdrojové kódy

Fix attachment rename processing in upgrade_2-1_mysql.sql

Signed-off-by: Noteworthy Software, Inc <[email protected]>
Noteworthy Software, Inc 10 rokov pred
rodič
commit
37e977b2ba
1 zmenil súbory, kde vykonal 18 pridanie a 7 odobranie
  1. 18 7
      other/upgrade_2-1_mysql.sql

+ 18 - 7
other/upgrade_2-1_mysql.sql

@@ -97,7 +97,6 @@ $is_done = false;
 while (!$is_done)
 {
 	nextSubStep($substep);
-	$fileHash = '';
 
 	$request = upgrade_query("
 		SELECT id_attach, id_member, id_folder, filename, file_hash, mime_type
@@ -114,6 +113,8 @@ while (!$is_done)
 		// The current folder.
 		$currentFolder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
 
+		$fileHash = '';
+
 		// Old School?
 		if (empty($row['file_hash']))
 		{
@@ -134,12 +135,13 @@ while (!$is_done)
 			// Create a nice hash.
 			$fileHash = sha1(md5($row['filename'] . time()) . mt_rand());
 
-			// The old file, we need to know if the filename was encrypted or not.
-			if (file_exists($currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename'])))
-				$oldFile = $currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename']);
-
-			else if (file_exists($currentFolder . '/' . $row['filename']));
+			// Iterate through the possible attachment names until we find the one that exists
+			$oldFile = $currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename']);
+			if (!file_exists($oldFile))
+			{
 				$oldFile = $currentFolder . '/' . $row['filename'];
+				if (!file_exists($oldFile)) $oldFile = false;
+			}
 
 			// Build the new file.
 			$newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $fileHash .'.dat';
@@ -152,17 +154,26 @@ while (!$is_done)
 			$newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'] .'.dat';
 		}
 
+		if (!$oldFile)
+		{
+			// Existing attachment could not be found. Just skip it...
+			continue;
+		}
+
 		// Check if the av is an attachment
 		if ($row['id_member'] != 0)
+		{
 			if (rename($oldFile, $custom_av_dir . '/' . $row['filename']))
 				upgrade_query("
 					UPDATE {$db_prefix}attachments
 					SET file_hash = '', attachment_type = 1
 					WHERE id_attach = $row[id_attach]");
-
+		}
 		// Just a regular attachment.
 		else
+		{
 			rename($oldFile, $newFile);
+		}
 
 		// Only update this if it was successful and the file was using the old system.
 		if (empty($row['file_hash']) && !empty($fileHash) && file_exists($newFile) && !file_exists($oldFile))