30ffc997ef50e3860760e5b1171272a8a5ce31f3
[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 /**
76 * @param ILBFactory $dbLoadBalancerFactory
77 * @param BlobStoreFactory $blobStoreFactory
78 * @param NameTableStoreFactory $nameTables
79 * @param WANObjectCache $cache
80 * @param CommentStore $commentStore
81 * @param ActorMigration $actorMigration
82 * @param int $migrationStage
83 * @param LoggerSpi $loggerProvider
84 * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}. Must be the same
85 * for all wikis in the cluster. Will go away after MCR migration.
86 */
87 public function __construct(
88 ILBFactory $dbLoadBalancerFactory,
89 BlobStoreFactory $blobStoreFactory,
90 NameTableStoreFactory $nameTables,
91 WANObjectCache $cache,
92 CommentStore $commentStore,
93 ActorMigration $actorMigration,
94 $migrationStage,
95 LoggerSpi $loggerProvider,
96 $contentHandlerUseDB
97 ) {
98 Assert::parameterType( 'integer', $migrationStage, '$migrationStage' );
99 $this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
100 $this->blobStoreFactory = $blobStoreFactory;
101 $this->nameTables = $nameTables;
102 $this->cache = $cache;
103 $this->commentStore = $commentStore;
104 $this->actorMigration = $actorMigration;
105 $this->mcrMigrationStage = $migrationStage;
106 $this->loggerProvider = $loggerProvider;
107 $this->contentHandlerUseDB = $contentHandlerUseDB;
108 }
109
110 /**
111 * @since 1.32
112 *
113 * @param bool|string $wikiId false for the current domain / wikid
114 *
115 * @return RevisionStore for the given wikiId with all necessary services and a logger
116 */
117 public function getRevisionStore( $wikiId = false ) {
118 Assert::parameterType( 'string|boolean', $wikiId, '$wikiId' );
119
120 $store = new RevisionStore(
121 $this->dbLoadBalancerFactory->getMainLB( $wikiId ),
122 $this->blobStoreFactory->newSqlBlobStore( $wikiId ),
123 $this->cache, // Pass local cache instance; Leave cache sharing to RevisionStore.
124 $this->commentStore,
125 $this->nameTables->getContentModels( $wikiId ),
126 $this->nameTables->getSlotRoles( $wikiId ),
127 $this->mcrMigrationStage,
128 $this->actorMigration,
129 $wikiId
130 );
131
132 $store->setLogger( $this->loggerProvider->getLogger( 'RevisionStore' ) );
133 $store->setContentHandlerUseDB( $this->contentHandlerUseDB );
134
135 return $store;
136 }
137 }