Avoid image table updates on file upload failure
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 18 Apr 2014 19:34:52 +0000 (12:34 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 18 Apr 2014 19:36:20 +0000 (12:36 -0700)
* 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

index eb55e82..f9ab7b7 100644 (file)
@@ -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 );
                        }