From: Aaron Schulz Date: Fri, 18 Apr 2014 19:34:52 +0000 (-0700) Subject: Avoid image table updates on file upload failure X-Git-Tag: 1.31.0-rc.0~16128^2 X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28?a=commitdiff_plain;h=17480be012a9b0f331ff776832ddf865595f13e7;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 ); }