Merge "Add some LocalRepo integration tests"
[lhc/web/wiklou.git] / includes / filerepo / LocalRepo.php
index c889e56..5ed937f 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 use MediaWiki\MediaWikiServices;
-use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\IResultWrapper;
 use Wikimedia\Rdbms\Database;
 use Wikimedia\Rdbms\IDatabase;
 
@@ -201,7 +201,7 @@ class LocalRepo extends FileRepo {
                }
 
                $method = __METHOD__;
-               $redirDbKey = MediaWikiServices::getInstance()->getMainWANObjectCache()->getWithSetCallback(
+               $redirDbKey = $this->wanCache->getWithSetCallback(
                        $memcKey,
                        $expiry,
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $method, $title ) {
@@ -209,20 +209,16 @@ class LocalRepo extends FileRepo {
 
                                $setOpts += Database::getCacheSetOptions( $dbr );
 
-                               if ( $title instanceof Title ) {
-                                       $row = $dbr->selectRow(
-                                               [ 'page', 'redirect' ],
-                                               [ 'rd_namespace', 'rd_title' ],
-                                               [
-                                                       'page_namespace' => $title->getNamespace(),
-                                                       'page_title' => $title->getDBkey(),
-                                                       'rd_from = page_id'
-                                               ],
-                                               $method
-                                       );
-                               } else {
-                                       $row = false;
-                               }
+                               $row = $dbr->selectRow(
+                                       [ 'page', 'redirect' ],
+                                       [ 'rd_namespace', 'rd_title' ],
+                                       [
+                                               'page_namespace' => $title->getNamespace(),
+                                               'page_title' => $title->getDBkey(),
+                                               'rd_from = page_id'
+                                       ],
+                                       $method
+                               );
 
                                return ( $row && $row->rd_namespace == NS_FILE )
                                        ? Title::makeTitle( $row->rd_namespace, $row->rd_title )->getDBkey()
@@ -275,7 +271,7 @@ class LocalRepo extends FileRepo {
                        );
                };
 
-               $applyMatchingFiles = function ( ResultWrapper $res, &$searchSet, &$finalFiles )
+               $applyMatchingFiles = function ( IResultWrapper $res, &$searchSet, &$finalFiles )
                        use ( $fileMatchesSearch, $flags )
                {
                        $contLang = MediaWikiServices::getInstance()->getContentLanguage();
@@ -405,7 +401,7 @@ class LocalRepo extends FileRepo {
         * @return array[] An Array of arrays or iterators of file objects and the hash as key
         */
        function findBySha1s( array $hashes ) {
-               if ( !count( $hashes ) ) {
+               if ( $hashes === [] ) {
                        return []; // empty parameter
                }
 
@@ -500,14 +496,14 @@ class LocalRepo extends FileRepo {
        /**
         * Get a key on the primary cache for this repository.
         * Returns false if the repository's cache is not accessible at this site.
-        * The parameters are the parts of the key, as for wfMemcKey().
+        * The parameters are the parts of the key.
         *
         * @return string
         */
        function getSharedCacheKey( /*...*/ ) {
                $args = func_get_args();
 
-               return wfMemcKey( ...$args );
+               return $this->wanCache->makeKey( ...$args );
        }
 
        /**
@@ -521,7 +517,7 @@ class LocalRepo extends FileRepo {
                if ( $key ) {
                        $this->getMasterDB()->onTransactionPreCommitOrIdle(
                                function () use ( $key ) {
-                                       MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
+                                       $this->wanCache->delete( $key );
                                },
                                __METHOD__
                        );