From 423ba71f426a603f50198220f6d2caa3b1cf04e4 Mon Sep 17 00:00:00 2001 From: addshore Date: Mon, 29 Jan 2018 14:25:49 +0000 Subject: [PATCH] DI for CommentStore in RevisionStore Change-Id: I527388514489e79c53b6016a8bd3119ee1750c83 --- includes/ServiceWiring.php | 3 ++- includes/Storage/RevisionStore.php | 18 +++++++++++++----- tests/phpunit/includes/RevisionDbTestBase.php | 3 ++- tests/phpunit/includes/RevisionTest.php | 8 +++++++- .../includes/Storage/RevisionStoreDbTest.php | 1 + .../includes/Storage/RevisionStoreTest.php | 8 +++++--- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 0ab5f6d3d8..3a9474be1d 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -475,7 +475,8 @@ return [ $store = new RevisionStore( $services->getDBLoadBalancer(), $blobStore, - $services->getMainWANObjectCache() + $services->getMainWANObjectCache(), + $services->getCommentStore() ); $store->setLogger( LoggerFactory::getInstance( 'RevisionStore' ) ); diff --git a/includes/Storage/RevisionStore.php b/includes/Storage/RevisionStore.php index bce3ba1729..2140209c42 100644 --- a/includes/Storage/RevisionStore.php +++ b/includes/Storage/RevisionStore.php @@ -92,6 +92,11 @@ class RevisionStore */ private $cache; + /** + * @var CommentStore + */ + private $commentStore; + /** * @var LoggerInterface */ @@ -103,12 +108,14 @@ class RevisionStore * @param LoadBalancer $loadBalancer * @param SqlBlobStore $blobStore * @param WANObjectCache $cache + * @param CommentStore $commentStore * @param bool|string $wikiId */ public function __construct( LoadBalancer $loadBalancer, SqlBlobStore $blobStore, WANObjectCache $cache, + CommentStore $commentStore, $wikiId = false ) { Assert::parameterType( 'string|boolean', $wikiId, '$wikiId' ); @@ -116,6 +123,7 @@ class RevisionStore $this->loadBalancer = $loadBalancer; $this->blobStore = $blobStore; $this->cache = $cache; + $this->commentStore = $commentStore; $this->wikiId = $wikiId; $this->logger = new NullLogger(); } @@ -393,7 +401,7 @@ class RevisionStore } list( $commentFields, $commentCallback ) = - CommentStore::getStore()->insertWithTempTable( $dbw, 'rev_comment', $comment ); + $this->commentStore->insertWithTempTable( $dbw, 'rev_comment', $comment ); $row += $commentFields; if ( $this->contentHandlerUseDB ) { @@ -1069,7 +1077,7 @@ class RevisionStore $user = $this->getUserIdentityFromRowObject( $row, 'ar_' ); - $comment = CommentStore::getStore() + $comment = $this->commentStore // Legacy because $row may have come from self::selectFields() ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), 'ar_comment', $row, true ); @@ -1139,7 +1147,7 @@ class RevisionStore $user = $this->getUserIdentityFromRowObject( $row ); - $comment = CommentStore::getStore() + $comment = $this->commentStore // Legacy because $row may have come from self::selectFields() ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), 'rev_comment', $row, true ); @@ -1614,7 +1622,7 @@ class RevisionStore 'rev_sha1', ] ); - $commentQuery = CommentStore::getStore()->getJoin( 'rev_comment' ); + $commentQuery = $this->commentStore->getJoin( 'rev_comment' ); $ret['tables'] = array_merge( $ret['tables'], $commentQuery['tables'] ); $ret['fields'] = array_merge( $ret['fields'], $commentQuery['fields'] ); $ret['joins'] = array_merge( $ret['joins'], $commentQuery['joins'] ); @@ -1671,7 +1679,7 @@ class RevisionStore * - joins: (array) to include in the `$join_conds` to `IDatabase->select()` */ public function getArchiveQueryInfo() { - $commentQuery = CommentStore::getStore()->getJoin( 'ar_comment' ); + $commentQuery = $this->commentStore->getJoin( 'ar_comment' ); $ret = [ 'tables' => [ 'archive' ] + $commentQuery['tables'], 'fields' => [ diff --git a/tests/phpunit/includes/RevisionDbTestBase.php b/tests/phpunit/includes/RevisionDbTestBase.php index 511b109538..b36fd7dbb4 100644 --- a/tests/phpunit/includes/RevisionDbTestBase.php +++ b/tests/phpunit/includes/RevisionDbTestBase.php @@ -396,7 +396,8 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { $store = new RevisionStore( $services->getDBLoadBalancer(), $services->getService( '_SqlBlobStore' ), - $services->getMainWANObjectCache() + $services->getMainWANObjectCache(), + $services->getCommentStore() ); $store->setContentHandlerUseDB( $this->getContentHandlerUseDB() ); diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index 872a23eb5a..57c0531602 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -1,5 +1,6 @@ getWANObjectCache(); - $blobStore = new RevisionStore( $lb, $this->getBlobStore(), $cache ); + $blobStore = new RevisionStore( + $lb, + $this->getBlobStore(), + $cache, + MediaWikiServices::getInstance()->getCommentStore() + ); return $blobStore; } diff --git a/tests/phpunit/includes/Storage/RevisionStoreDbTest.php b/tests/phpunit/includes/Storage/RevisionStoreDbTest.php index 6c908549ae..d31ca5c395 100644 --- a/tests/phpunit/includes/Storage/RevisionStoreDbTest.php +++ b/tests/phpunit/includes/Storage/RevisionStoreDbTest.php @@ -133,6 +133,7 @@ class RevisionStoreDbTest extends MediaWikiTestCase { $loadBalancer, $blobStore, new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ), + MediaWikiServices::getInstance()->getCommentStore(), $wikiId ); diff --git a/tests/phpunit/includes/Storage/RevisionStoreTest.php b/tests/phpunit/includes/Storage/RevisionStoreTest.php index bee94f3bc6..8e8de6ea31 100644 --- a/tests/phpunit/includes/Storage/RevisionStoreTest.php +++ b/tests/phpunit/includes/Storage/RevisionStoreTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\Tests\Storage; use HashBagOStuff; use Language; +use MediaWiki\MediaWikiServices; use MediaWiki\Storage\RevisionAccessException; use MediaWiki\Storage\RevisionStore; use MediaWiki\Storage\SqlBlobStore; @@ -30,7 +31,8 @@ class RevisionStoreTest extends MediaWikiTestCase { return new RevisionStore( $loadBalancer ? $loadBalancer : $this->getMockLoadBalancer(), $blobStore ? $blobStore : $this->getMockSqlBlobStore(), - $WANObjectCache ? $WANObjectCache : $this->getHashWANObjectCache() + $WANObjectCache ? $WANObjectCache : $this->getHashWANObjectCache(), + MediaWikiServices::getInstance()->getCommentStore() ); } @@ -597,7 +599,7 @@ class RevisionStoreTest extends MediaWikiTestCase { $blobStore = new SqlBlobStore( wfGetLB(), $cache ); $blobStore->setLegacyEncoding( $encoding, Language::factory( $locale ) ); - $store = new RevisionStore( wfGetLB(), $blobStore, $cache ); + $store = $this->getRevisionStore( wfGetLB(), $blobStore, $cache ); $record = $store->newRevisionFromRow( $this->makeRow( $row ), @@ -623,7 +625,7 @@ class RevisionStoreTest extends MediaWikiTestCase { $blobStore = new SqlBlobStore( wfGetLB(), $cache ); $blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) ); - $store = new RevisionStore( wfGetLB(), $blobStore, $cache ); + $store = $this->getRevisionStore( wfGetLB(), $blobStore, $cache ); $record = $store->newRevisionFromRow( $this->makeRow( $row ), -- 2.20.1