From 17480be012a9b0f331ff776832ddf865595f13e7 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 18 Apr 2014 12:34:52 -0700 Subject: [PATCH] Avoid image table updates on file upload failure * If the publish() call did not really do anything, then there is no use in saving the page and file DB records. Previously the user would get an error but the description page would be made. bug: 64071 Change-Id: I1959f8c1ef33dbd1b238f6020117d2862d4b0fd3 --- includes/filerepo/file/LocalFile.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index eb55e82095..f9ab7b7209 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1159,16 +1159,19 @@ class LocalFile extends File { // Trim spaces on user supplied text $comment = trim( $comment ); - // truncate nicely or the DB will do it for us + // Truncate nicely or the DB will do it for us // non-nicely (dangling multi-byte chars, non-truncated version in cache). $comment = $wgContLang->truncate( $comment, 255 ); $this->lock(); // begin $status = $this->publish( $srcPath, $flags, $options ); - if ( $status->successCount > 0 ) { - # Essentially we are displacing any existing current file and saving - # a new current file at the old location. If just the first succeeded, - # we still need to displace the current DB entry and put in a new one. + if ( $status->successCount >= 2 ) { + // There will be a copy+(one of move,copy,store). + // The first succeeding does not commit us to updating the DB + // since it simply copied the current version to a timestamped file name. + // It is only *preferable* to avoid leaving such files orphaned. + // Once the second operation goes through, then the current version was + // updated and we must therefore update the DB too. if ( !$this->recordUpload2( $status->value, $comment, $pageText, $props, $timestamp, $user ) ) { $status->fatal( 'filenotfound', $srcPath ); } -- 2.20.1