Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / Revision / RevisionStoreFactory.php
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * Attribution notice: when this file was created, much of its content was taken
20 * from the Revision.php file as present in release 1.30. Refer to the history
21 * of that file for original authorship.
22 *
23 * @file
24 */
25
26 namespace MediaWiki\Revision;
27
28 use ActorMigration;
29 use CommentStore;
30 use MediaWiki\Logger\Spi as LoggerSpi;
31 use MediaWiki\Storage\BlobStoreFactory;
32 use MediaWiki\Storage\NameTableStoreFactory;
33 use WANObjectCache;
34 use Wikimedia\Assert\Assert;
35 use Wikimedia\Rdbms\ILBFactory;
36
37 /**
38 * Factory service for RevisionStore instances. This allows RevisionStores to be created for
39 * cross-wiki access.
40 *
41 * @warning Beware compatibility issues with schema migration in the context of cross-wiki access!
42 * This class assumes that all wikis are at compatible migration stages for all relevant schemas.
43 * Relevant schemas are: revision storage (MCR), the revision comment table, and the actor table.
44 * Migration stages are compatible as long as a) there are no wikis in the cluster that only write
45 * the old schema or b) there are no wikis that read only the new schema.
46 *
47 * @since 1.32
48 */
49 class RevisionStoreFactory {
50
51 /** @var BlobStoreFactory */
52 private $blobStoreFactory;
53 /** @var ILBFactory */
54 private $dbLoadBalancerFactory;
55 /** @var WANObjectCache */
56 private $cache;
57 /** @var LoggerSpi */
58 private $loggerProvider;
59
60 /** @var CommentStore */
61 private $commentStore;
62 /** @var ActorMigration */
63 private $actorMigration;
64 /** @var int One of the MIGRATION_* constants */
65 private $mcrMigrationStage;
66 /**
67 * @var bool
68 * @see $wgContentHandlerUseDB
69 */
70 private $contentHandlerUseDB;
71
72 /** @var NameTableStoreFactory */
73 private $nameTables;
74
75 /** @var SlotRoleRegistry */
76 private $slotRoleRegistry;
77
78 /**
79 * @param ILBFactory $dbLoadBalancerFactory
80 * @param BlobStoreFactory $blobStoreFactory
81 * @param NameTableStoreFactory $nameTables
82 * @param SlotRoleRegistry $slotRoleRegistry
83 * @param WANObjectCache $cache
84 * @param CommentStore $commentStore
85 * @param ActorMigration $actorMigration
86 * @param int $migrationStage
87 * @param LoggerSpi $loggerProvider
88 * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}. Must be the same
89 * for all wikis in the cluster. Will go away after MCR migration.
90 */
91 public function __construct(
92 ILBFactory $dbLoadBalancerFactory,
93 BlobStoreFactory $blobStoreFactory,
94 NameTableStoreFactory $nameTables,
95 SlotRoleRegistry $slotRoleRegistry,
96 WANObjectCache $cache,
97 CommentStore $commentStore,
98 ActorMigration $actorMigration,
99 $migrationStage,
100 LoggerSpi $loggerProvider,
101 $contentHandlerUseDB
102 ) {
103 Assert::parameterType( 'integer', $migrationStage, '$migrationStage' );
104 $this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
105 $this->blobStoreFactory = $blobStoreFactory;
106 $this->slotRoleRegistry = $slotRoleRegistry;
107 $this->nameTables = $nameTables;
108 $this->cache = $cache;
109 $this->commentStore = $commentStore;
110 $this->actorMigration = $actorMigration;
111 $this->mcrMigrationStage = $migrationStage;
112 $this->loggerProvider = $loggerProvider;
113 $this->contentHandlerUseDB = $contentHandlerUseDB;
114 }
115
116 /**
117 * @since 1.32
118 *
119 * @param bool|string $dbDomain DB domain of the relevant wiki or false for the current one
120 *
121 * @return RevisionStore for the given wikiId with all necessary services and a logger
122 */
123 public function getRevisionStore( $dbDomain = false ) {
124 Assert::parameterType( 'string|boolean', $dbDomain, '$dbDomain' );
125
126 $store = new RevisionStore(
127 $this->dbLoadBalancerFactory->getMainLB( $dbDomain ),
128 // @phan-suppress-next-line PhanAccessMethodInternal
129 $this->blobStoreFactory->newSqlBlobStore( $dbDomain ),
130 $this->cache, // Pass local cache instance; Leave cache sharing to RevisionStore.
131 $this->commentStore,
132 $this->nameTables->getContentModels( $dbDomain ),
133 $this->nameTables->getSlotRoles( $dbDomain ),
134 $this->slotRoleRegistry,
135 $this->mcrMigrationStage,
136 $this->actorMigration,
137 $dbDomain
138 );
139
140 $store->setLogger( $this->loggerProvider->getLogger( 'RevisionStore' ) );
141 $store->setContentHandlerUseDB( $this->contentHandlerUseDB );
142
143 return $store;
144 }
145 }