From 4068bb0e851874f91fa3187d4a6f167bed952f70 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 21 Sep 2011 21:32:24 +0000 Subject: [PATCH] Clear findFile() process cache of file moves (issue came up with bug bug 31056) --- includes/Title.php | 7 +++++-- includes/filerepo/RepoGroup.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index dedb7ac024..e31b77275c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ); diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 3e59e39d77..2d83074296 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -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] ); + } + } + } } -- 2.20.1