From a3eef256af39b36c8f705e2bba8400beaf591170 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 25 Aug 2007 20:18:56 +0000 Subject: [PATCH] Fix for restore of image data where oldimage rows hadn't contained the various new metadata fields. When missing on restore, metadata is re-fetched from the file and inserted into the new record in place of the empty fields. --- includes/filerepo/LocalFile.php | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 6edc034f41..1e5fc44952 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -1430,6 +1430,21 @@ class LocalFileRestoreBatch { if ( strlen( $sha1 ) == 32 && $sha1[0] == '0' ) { $sha1 = substr( $sha1, 1 ); } + + if( is_null( $row->fa_major_mime ) || $row->fa_major_mime == 'unknown' + || is_null( $row->fa_minor_mime ) || $row->fa_minor_mime == 'unknown' + || is_null( $row->fa_media_type ) || $row->fa_media_type == 'UNKNOWN' + || is_null( $row->fa_metadata ) ) { + // Refresh our metadata + // Required for a new current revision; nice for older ones too. :) + $props = RepoGroup::singleton()->getFileProps( $deletedUrl ); + } else { + $props = array( + 'minor_mime' => $row->fa_minor_mime, + 'major_mime' => $row->fa_major_mime, + 'media_type' => $row->fa_media_type, + 'metadata' => $row->fa_metadata ); + } if ( $first && !$exists ) { // This revision will be published as the new current version @@ -1439,11 +1454,11 @@ class LocalFileRestoreBatch { 'img_size' => $row->fa_size, 'img_width' => $row->fa_width, 'img_height' => $row->fa_height, - 'img_metadata' => $row->fa_metadata, + 'img_metadata' => $props['metadata'], 'img_bits' => $row->fa_bits, - 'img_media_type' => $row->fa_media_type, - 'img_major_mime' => $row->fa_major_mime, - 'img_minor_mime' => $row->fa_minor_mime, + 'img_media_type' => $props['media_type'], + 'img_major_mime' => $props['major_mime'], + 'img_minor_mime' => $props['minor_mime'], 'img_description' => $row->fa_description, 'img_user' => $row->fa_user, 'img_user_text' => $row->fa_user_text, @@ -1474,10 +1489,10 @@ class LocalFileRestoreBatch { 'oi_user' => $row->fa_user, 'oi_user_text' => $row->fa_user_text, 'oi_timestamp' => $row->fa_timestamp, - 'oi_metadata' => is_null($row->fa_metadata) ? '' : $row->fa_metadata, - 'oi_media_type' => $row->fa_media_type, - 'oi_major_mime' => $row->fa_major_mime, - 'oi_minor_mime' => $row->fa_minor_mime, + 'oi_metadata' => $props['metadata'], + 'oi_media_type' => $props['media_type'], + 'oi_major_mime' => $props['major_mime'], + 'oi_minor_mime' => $props['minor_mime'], 'oi_deleted' => $row->fa_deleted, 'oi_sha1' => $sha1 ); } -- 2.20.1