Clear findFile() process cache of file moves (issue came up with bug bug 31056)
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 21 Sep 2011 21:32:24 +0000 (21:32 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 21 Sep 2011 21:32:24 +0000 (21:32 +0000)
includes/Title.php
includes/filerepo/RepoGroup.php

index dedb7ac..e31b772 100644 (file)
@@ -3168,8 +3168,8 @@ class Title {
                        return $err;
                }
 
-               // If it is a file, move it first. It is done before all other moving stuff is
-               // done because it's hard to revert
+               // If it is a file, move it first.
+               // It is done before all other moving stuff is done because it's hard to revert.
                $dbw = wfGetDB( DB_MASTER );
                if ( $this->getNamespace() == NS_FILE ) {
                        $file = wfLocalFile( $this );
@@ -3180,6 +3180,9 @@ class Title {
                                }
                        }
                }
+               // Clear RepoGroup process cache
+               RepoGroup::singleton()->clearCache( $this );
+               RepoGroup::singleton()->clearCache( $nt ); # clear false negative cache
 
                $dbw->begin(); # If $file was a LocalFile, its transaction would have closed our own.
                $pageid = $this->getArticleID( self::GAID_FOR_UPDATE );
index 3e59e39..2d83074 100644 (file)
@@ -385,4 +385,19 @@ class RepoGroup {
                        unset( $this->cache[$key] );
                }
        }
+
+       /**
+        * Clear RepoGroup process cache used for finding a file
+        * @param $title Title|null Title of the file or null to clear all files
+        */
+       public function clearCache( Title $title = null ) {
+               if ( $title == null ) {
+                       $this->cache = array();
+               } else {
+                       $dbKey = $title->getDBkey();
+                       if ( isset( $this->cache[$dbKey] ) ) {
+                               unset( $this->cache[$dbKey] );
+                       }
+               }
+       }
 }