Revert "Introduce RevisionStoreFactory & Tests"
authorAddshore <addshorewiki@gmail.com>
Tue, 3 Jul 2018 11:49:24 +0000 (11:49 +0000)
committeraddshore <addshorewiki@gmail.com>
Tue, 3 Jul 2018 13:32:44 +0000 (14:32 +0100)
This needs more work, I'll file some tickets with TODOs

This reverts commit eb39d5f945245d65c0f5e44466c6d616b62577f5.

Change-Id: I0678d0c4e4e7496a67dfe826b00246723e9c7d54

includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/Storage/RevisionStoreFactory.php [deleted file]
tests/phpunit/includes/MediaWikiServicesTest.php
tests/phpunit/includes/Storage/RevisionStoreFactoryTest.php [deleted file]

index caaa6b3..ce43f0e 100644 (file)
@@ -21,7 +21,6 @@ use MediaWiki\Storage\NameTableStore;
 use MediaWiki\Storage\RevisionFactory;
 use MediaWiki\Storage\RevisionLookup;
 use MediaWiki\Storage\RevisionStore;
-use MediaWiki\Storage\RevisionStoreFactory;
 use OldRevisionImporter;
 use UploadRevisionImporter;
 use Wikimedia\Rdbms\LBFactory;
@@ -760,14 +759,6 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'RevisionStore' );
        }
 
-       /**
-        * @since 1.32
-        * @return RevisionStoreFactory
-        */
-       public function getRevisionStoreFactory() {
-               return $this->getService( 'RevisionStoreFactory' );
-       }
-
        /**
         * @since 1.31
         * @return RevisionLookup
index ba576d5..425b789 100644 (file)
@@ -46,7 +46,7 @@ use MediaWiki\Preferences\DefaultPreferencesFactory;
 use MediaWiki\Shell\CommandFactory;
 use MediaWiki\Storage\BlobStoreFactory;
 use MediaWiki\Storage\NameTableStore;
-use MediaWiki\Storage\RevisionStoreFactory;
+use MediaWiki\Storage\RevisionStore;
 use MediaWiki\Storage\SqlBlobStore;
 use Wikimedia\ObjectFactory;
 
@@ -463,15 +463,10 @@ return [
        },
 
        'RevisionStore' => function ( MediaWikiServices $services ) {
-               return $services->getRevisionStoreFactory()->getRevisionStore();
-       },
-
-       'RevisionStoreFactory' => function ( MediaWikiServices $services ) {
                /** @var SqlBlobStore $blobStore */
                $blobStore = $services->getService( '_SqlBlobStore' );
-               $config = $services->getMainConfig();
 
-               $store = new RevisionStoreFactory(
+               $store = new RevisionStore(
                        $services->getDBLoadBalancer(),
                        $blobStore,
                        $services->getMainWANObjectCache(),
@@ -479,11 +474,14 @@ return [
                        $services->getContentModelStore(),
                        $services->getSlotRoleStore(),
                        $services->getMainConfig()->get( 'MultiContentRevisionSchemaMigrationStage' ),
-                       $services->getActorMigration(),
-                       LoggerFactory::getInstance( 'RevisionStore' ),
-                       $config->get( 'ContentHandlerUseDB' )
+                       $services->getActorMigration()
                );
 
+               $store->setLogger( LoggerFactory::getInstance( 'RevisionStore' ) );
+
+               $config = $services->getMainConfig();
+               $store->setContentHandlerUseDB( $config->get( 'ContentHandlerUseDB' ) );
+
                return $store;
        },
 
diff --git a/includes/Storage/RevisionStoreFactory.php b/includes/Storage/RevisionStoreFactory.php
deleted file mode 100644 (file)
index 6f8bd99..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-
-/**
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * Attribution notice: when this file was created, much of its content was taken
- * from the Revision.php file as present in release 1.30. Refer to the history
- * of that file for original authorship.
- *
- * @file
- */
-
-namespace MediaWiki\Storage;
-
-use ActorMigration;
-use CommentStore;
-use Psr\Log\LoggerInterface;
-use WANObjectCache;
-use Wikimedia\Assert\Assert;
-use Wikimedia\Rdbms\LoadBalancer;
-
-/**
- * @since 1.32
- */
-class RevisionStoreFactory {
-
-       /** @var SqlBlobStore */
-       private $blobStore;
-
-       /** @var LoadBalancer */
-       private $loadBalancer;
-
-       /** @var WANObjectCache */
-       private $cache;
-
-       /** @var CommentStore */
-       private $commentStore;
-
-       /** @var ActorMigration */
-       private $actorMigration;
-
-       /** @var NameTableStore */
-       private $contentModelStore;
-
-       /** @var NameTableStore */
-       private $slotRoleStore;
-
-       /** @var int One of the MIGRATION_* constants */
-       private $mcrMigrationStage;
-
-       /**
-        * @var bool
-        * @see $wgContentHandlerUseDB
-        */
-       private $contentHandlerUseDB;
-
-       /** @var LoggerInterface */
-       private $logger;
-
-       /**
-        * @todo $blobStore should be allowed to be any BlobStore!
-        *
-        * @param LoadBalancer $loadBalancer
-        * @param SqlBlobStore $blobStore
-        * @param WANObjectCache $cache
-        * @param CommentStore $commentStore
-        * @param NameTableStore $contentModelStore
-        * @param NameTableStore $slotRoleStore
-        * @param int $migrationStage
-        * @param ActorMigration $actorMigration
-        * @param LoggerInterface $logger
-        * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}
-        */
-       public function __construct(
-               LoadBalancer $loadBalancer,
-               SqlBlobStore $blobStore,
-               WANObjectCache $cache,
-               CommentStore $commentStore,
-               NameTableStore $contentModelStore,
-               NameTableStore $slotRoleStore,
-               $migrationStage,
-               ActorMigration $actorMigration,
-               LoggerInterface $logger,
-               $contentHandlerUseDB
-       ) {
-               Assert::parameterType( 'integer', $migrationStage, '$migrationStage' );
-
-               $this->loadBalancer = $loadBalancer;
-               $this->blobStore = $blobStore;
-               $this->cache = $cache;
-               $this->commentStore = $commentStore;
-               $this->contentModelStore = $contentModelStore;
-               $this->slotRoleStore = $slotRoleStore;
-               $this->mcrMigrationStage = $migrationStage;
-               $this->actorMigration = $actorMigration;
-               $this->logger = $logger;
-               $this->contentHandlerUseDB = $contentHandlerUseDB;
-       }
-
-       /**
-        * @since 1.32
-        *
-        * @param bool|string $wikiId false for the current domain / wikid
-        *
-        * @return RevisionStore for the given wikiId with all necessary services and a logger
-        */
-       public function getRevisionStore( $wikiId = false ) {
-               Assert::parameterType( 'string|boolean', $wikiId, '$wikiId' );
-
-               $store = new RevisionStore(
-                       $this->loadBalancer,
-                       $this->blobStore,
-                       $this->cache,
-                       $this->commentStore,
-                       $this->contentModelStore,
-                       $this->slotRoleStore,
-                       $this->mcrMigrationStage,
-                       $this->actorMigration,
-                       $wikiId
-               );
-
-               $store->setLogger( $this->logger );
-               $store->setContentHandlerUseDB( $this->contentHandlerUseDB );
-
-               return $store;
-       }
-
-}
index cf48215..dfee8c3 100644 (file)
@@ -16,7 +16,6 @@ use MediaWiki\Storage\NameTableStore;
 use MediaWiki\Storage\RevisionFactory;
 use MediaWiki\Storage\RevisionLookup;
 use MediaWiki\Storage\RevisionStore;
-use MediaWiki\Storage\RevisionStoreFactory;
 use MediaWiki\Storage\SqlBlobStore;
 
 /**
@@ -347,7 +346,6 @@ class MediaWikiServicesTest extends MediaWikiTestCase {
                        'BlobStore' => [ 'BlobStore', BlobStore::class ],
                        '_SqlBlobStore' => [ '_SqlBlobStore', SqlBlobStore::class ],
                        'RevisionStore' => [ 'RevisionStore', RevisionStore::class ],
-                       'RevisionStoreFactory' => [ 'RevisionStoreFactory', RevisionStoreFactory::class ],
                        'RevisionLookup' => [ 'RevisionLookup', RevisionLookup::class ],
                        'RevisionFactory' => [ 'RevisionFactory', RevisionFactory::class ],
                        'ContentModelStore' => [ 'ContentModelStore', NameTableStore::class ],
diff --git a/tests/phpunit/includes/Storage/RevisionStoreFactoryTest.php b/tests/phpunit/includes/Storage/RevisionStoreFactoryTest.php
deleted file mode 100644 (file)
index a5c18ac..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-
-namespace MediaWiki\Tests\Storage;
-
-use ActorMigration;
-use CommentStore;
-use MediaWiki\Logger\LoggerFactory;
-use MediaWiki\Storage\NameTableStore;
-use MediaWiki\Storage\RevisionStore;
-use MediaWiki\Storage\RevisionStoreFactory;
-use MediaWiki\Storage\SqlBlobStore;
-use MediaWikiTestCase;
-use WANObjectCache;
-use Wikimedia\Rdbms\LoadBalancer;
-use Wikimedia\TestingAccessWrapper;
-
-class RevisionStoreFactoryTest extends MediaWikiTestCase {
-
-       public function testValidConstruction_doesntCauseErrors() {
-               new RevisionStoreFactory(
-                       $this->getMockLoadBalancer(),
-                       $this->getMockSqlBlobStore(),
-                       $this->getHashWANObjectCache(),
-                       $this->getMockCommentStore(),
-                       $this->getMockNameTableStore(),
-                       $this->getMockNameTableStore(),
-                       MIGRATION_OLD,
-                       ActorMigration::newMigration(),
-                       LoggerFactory::getInstance( 'someInstance' ),
-                       true
-               );
-               $this->assertTrue( true );
-       }
-
-       public function provideWikiIds() {
-               yield [ true ];
-               yield [ false ];
-               yield [ 'somewiki' ];
-               yield [ 'somewiki', MIGRATION_OLD , false ];
-               yield [ 'somewiki', MIGRATION_NEW , true ];
-       }
-
-       /**
-        * @dataProvider provideWikiIds
-        */
-       public function testGetRevisionStore(
-               $wikiId,
-               $mcrMigrationStage = MIGRATION_OLD,
-               $contentHandlerUseDb = true
-       ) {
-               $lb = $this->getMockLoadBalancer();
-               $blobStore = $this->getMockSqlBlobStore();
-               $cache = $this->getHashWANObjectCache();
-               $commentStore = $this->getMockCommentStore();
-               $contentModelStore = $this->getMockNameTableStore();
-               $slotRoleStore = $this->getMockNameTableStore();
-               $actorMigration = ActorMigration::newMigration();
-               $logger = LoggerFactory::getInstance( 'someInstance' );
-
-               $factory = new RevisionStoreFactory(
-                       $lb,
-                       $blobStore,
-                       $cache,
-                       $commentStore,
-                       $contentModelStore,
-                       $slotRoleStore,
-                       $mcrMigrationStage,
-                       $actorMigration,
-                       $logger,
-                       $contentHandlerUseDb
-               );
-
-               $store = $factory->getRevisionStore( $wikiId );
-               $wrapper = TestingAccessWrapper::newFromObject( $store );
-
-               // ensure the correct object type is returned
-               $this->assertInstanceOf( RevisionStore::class, $store );
-
-               // ensure the RevisionStore is for the given wikiId
-               $this->assertSame( $wikiId, $wrapper->wikiId );
-
-               // ensure all other required services are correctly set
-               $this->assertSame( $lb, $wrapper->loadBalancer );
-               $this->assertSame( $blobStore, $wrapper->blobStore );
-               $this->assertSame( $cache, $wrapper->cache );
-               $this->assertSame( $commentStore, $wrapper->commentStore );
-               $this->assertSame( $contentModelStore, $wrapper->contentModelStore );
-               $this->assertSame( $slotRoleStore, $wrapper->slotRoleStore );
-               $this->assertSame( $mcrMigrationStage, $wrapper->mcrMigrationStage );
-               $this->assertSame( $actorMigration, $wrapper->actorMigration );
-               $this->assertSame( $logger, $wrapper->logger );
-               $this->assertSame( $contentHandlerUseDb, $store->getContentHandlerUseDB() );
-       }
-
-       /**
-        * @return \PHPUnit_Framework_MockObject_MockObject|NameTableStore
-        */
-       private function getMockNameTableStore() {
-               return $this->getMockBuilder( NameTableStore::class )
-                       ->disableOriginalConstructor()->getMock();
-       }
-
-       /**
-        * @return \PHPUnit_Framework_MockObject_MockObject|LoadBalancer
-        */
-       private function getMockLoadBalancer() {
-               return $this->getMockBuilder( LoadBalancer::class )
-                       ->disableOriginalConstructor()->getMock();
-       }
-
-       /**
-        * @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
-        */
-       private function getMockSqlBlobStore() {
-               return $this->getMockBuilder( SqlBlobStore::class )
-                       ->disableOriginalConstructor()->getMock();
-       }
-
-       /**
-        * @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
-        */
-       private function getMockCommentStore() {
-               return $this->getMockBuilder( CommentStore::class )
-                       ->disableOriginalConstructor()->getMock();
-       }
-
-       private function getHashWANObjectCache() {
-               return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
-       }
-
-}