Merge "Follow-up cdc93a62bf: add serialize/unserialize tests for RedisBagOStuff"
[lhc/web/wiklou.git] / includes / WatchedItemStore.php
index 8ae7932..eb652ce 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Linker\LinkTarget;
 use Wikimedia\Assert\Assert;
 
 /**
@@ -49,11 +51,6 @@ class WatchedItemStore implements StatsdAwareInterface {
         */
        private $stats;
 
-       /**
-        * @var self|null
-        */
-       private static $instance;
-
        /**
         * @param LoadBalancer $loadBalancer
         * @param HashBagOStuff $cache
@@ -124,46 +121,6 @@ class WatchedItemStore implements StatsdAwareInterface {
                } );
        }
 
-       /**
-        * Overrides the default instance of this class
-        * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
-        *
-        * If this method is used it MUST also be called with null after a test to ensure a new
-        * default instance is created next time getDefaultInstance is called.
-        *
-        * @param WatchedItemStore|null $store
-        *
-        * @return ScopedCallback to reset the overridden value
-        * @throws MWException
-        */
-       public static function overrideDefaultInstance( WatchedItemStore $store = null ) {
-               if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
-                       throw new MWException(
-                               'Cannot override ' . __CLASS__ . 'default instance in operation.'
-                       );
-               }
-
-               $previousValue = self::$instance;
-               self::$instance = $store;
-               return new ScopedCallback( function() use ( $previousValue ) {
-                       self::$instance = $previousValue;
-               } );
-       }
-
-       /**
-        * @return self
-        */
-       public static function getDefaultInstance() {
-               if ( !self::$instance ) {
-                       self::$instance = new self(
-                               wfGetLB(),
-                               new HashBagOStuff( [ 'maxKeys' => 100 ] )
-                       );
-                       self::$instance->setStatsdDataFactory( RequestContext::getMain()->getStats() );
-               }
-               return self::$instance;
-       }
-
        private function getCacheKey( User $user, LinkTarget $target ) {
                return $this->cache->makeKey(
                        (string)$target->getNamespace(),
@@ -620,7 +577,7 @@ class WatchedItemStore implements StatsdAwareInterface {
                $this->reuseConnection( $dbr );
 
                foreach ( $res as $row ) {
-                       $timestamps[(int)$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
+                       $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
                }
 
                return $timestamps;
@@ -905,12 +862,8 @@ class WatchedItemStore implements StatsdAwareInterface {
         * @param LinkTarget $newTarget
         */
        public function duplicateAllAssociatedEntries( LinkTarget $oldTarget, LinkTarget $newTarget ) {
-               if ( !$oldTarget instanceof Title ) {
-                       $oldTarget = Title::newFromLinkTarget( $oldTarget );
-               }
-               if ( !$newTarget instanceof Title ) {
-                       $newTarget = Title::newFromLinkTarget( $newTarget );
-               }
+               $oldTarget = Title::newFromLinkTarget( $oldTarget );
+               $newTarget = Title::newFromLinkTarget( $newTarget );
 
                $this->duplicateEntry( $oldTarget->getSubjectPage(), $newTarget->getSubjectPage() );
                $this->duplicateEntry( $oldTarget->getTalkPage(), $newTarget->getTalkPage() );