(Bug 20744) - Wiki forgets about an uploaded file
authorPlatonides <platonides@users.mediawiki.org>
Tue, 31 Aug 2010 11:12:33 +0000 (11:12 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Tue, 31 Aug 2010 11:12:33 +0000 (11:12 +0000)
(Bug 24978) - "A file disappeared" thread on Commons:VP
Only save the LocalFile to memcache after the db entry has been commited.
Otherwise, when the transaction fails, the file apparently succeeded, but
after a week (memcached expiry) it disappears.
Fixes bug 20744 and bug 24978. Found by the Great Domas.

The correlation with db problems is probably just that in such case there are more transactions get rollbacked.

RELEASE-NOTES
includes/filerepo/LocalFile.php

index 4d539eb..9053274 100644 (file)
@@ -309,6 +309,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Disable multithreaded behaviour in recent ImageMagick, to avoid a deadlock
   when a resource limit such as $wgMaxShellMemory is hit.
 * (bug 24981) Allow extensions to access SpecialUpload variables again
+* (bug 20744) Wiki forgets about an uploaded file
 
 === API changes in 1.17 ===
 * (bug 22738) Allow filtering by action type on query=logevent.
index ac8b161..fce4373 100644 (file)
@@ -807,12 +807,12 @@ class LocalFile extends File {
                $props['timestamp'] = wfTimestamp( TS_MW );
                $this->setProps( $props );
 
-               // Delete thumbnails and refresh the metadata cache
+               # Delete thumbnails
                $this->purgeThumbnails();
-               $this->saveToCache();
+               # The file is already on its final location, remove it from the squid cache
                SquidUpdate::purge( array( $this->getURL() ) );
 
-               // Fail now if the file isn't there
+               # Fail now if the file isn't there
                if ( !$this->fileExists ) {
                        wfDebug( __METHOD__ . ": File " . $this->getPath() . " went missing!\n" );
                        return false;
@@ -922,8 +922,9 @@ class LocalFile extends File {
                        $descTitle->invalidateCache();
                        $descTitle->purgeSquid();
                } else {
-                       // New file; create the description page.
-                       // There's already a log entry, so don't make a second RC entry
+                       # New file; create the description page.
+                       # There's already a log entry, so don't make a second RC entry
+                       # Squid and file cache for the description page are purged by doEdit.
                        $article->doEdit( $pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC );
                }
 
@@ -934,6 +935,12 @@ class LocalFile extends File {
                # The most important thing is that files don't get lost, especially archives
                $dbw->commit();
 
+               # Save to cache and purge the squid
+               # We shall not saveToCache before the commit since otherwise
+               # in case of a rollback there is an usable file from memcached
+               # which in fact doesn't really exist (bug 24978)
+               $this->saveToCache();
+               
                # Invalidate cache for all pages using this file
                $update = new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' );
                $update->doUpdate();