Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
RevisionStoreFactory
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
 getRevisionStore
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getRevisionStoreForImport
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getStore
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
1
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 (that file was removed entirely in 1.37,
22 * but its history can still be found in prior versions of MediaWiki).
23 *
24 * @file
25 */
26
27namespace MediaWiki\Revision;
28
29use BagOStuff;
30use MediaWiki\CommentStore\CommentStore;
31use MediaWiki\Content\IContentHandlerFactory;
32use MediaWiki\HookContainer\HookContainer;
33use MediaWiki\Page\PageStoreFactory;
34use MediaWiki\Storage\BlobStoreFactory;
35use MediaWiki\Storage\NameTableStoreFactory;
36use MediaWiki\Title\TitleFactory;
37use MediaWiki\User\ActorStore;
38use MediaWiki\User\ActorStoreFactory;
39use Psr\Log\LoggerInterface;
40use WANObjectCache;
41use Wikimedia\Assert\Assert;
42use Wikimedia\Rdbms\ILBFactory;
43
44/**
45 * Factory service for RevisionStore instances. This allows RevisionStores to be created for
46 * cross-wiki access.
47 *
48 * @warning Beware compatibility issues with schema migration in the context of cross-wiki access!
49 * This class assumes that all wikis are at compatible migration stages for all relevant schemas.
50 * Relevant schemas are: revision storage (MCR), the revision comment table, and the actor table.
51 * Migration stages are compatible as long as a) there are no wikis in the cluster that only write
52 * the old schema or b) there are no wikis that read only the new schema.
53 *
54 * @since 1.32
55 */
56class RevisionStoreFactory {
57
58    /** @var BlobStoreFactory */
59    private $blobStoreFactory;
60    /** @var ILBFactory */
61    private $dbLoadBalancerFactory;
62    /** @var WANObjectCache */
63    private $cache;
64    /** @var BagOStuff */
65    private $localCache;
66    /** @var LoggerInterface */
67    private $logger;
68
69    /** @var CommentStore */
70    private $commentStore;
71    /** @var ActorStoreFactory */
72    private $actorStoreFactory;
73    /** @var NameTableStoreFactory */
74    private $nameTables;
75
76    /** @var SlotRoleRegistry */
77    private $slotRoleRegistry;
78
79    /** @var IContentHandlerFactory */
80    private $contentHandlerFactory;
81
82    /** @var PageStoreFactory */
83    private $pageStoreFactory;
84
85    /** @var TitleFactory */
86    private $titleFactory;
87
88    /** @var HookContainer */
89    private $hookContainer;
90
91    /**
92     * @param ILBFactory $dbLoadBalancerFactory
93     * @param BlobStoreFactory $blobStoreFactory
94     * @param NameTableStoreFactory $nameTables
95     * @param SlotRoleRegistry $slotRoleRegistry
96     * @param WANObjectCache $cache
97     * @param BagOStuff $localCache
98     * @param CommentStore $commentStore
99     * @param ActorStoreFactory $actorStoreFactory
100     * @param LoggerInterface $logger
101     * @param IContentHandlerFactory $contentHandlerFactory
102     * @param PageStoreFactory $pageStoreFactory
103     * @param TitleFactory $titleFactory
104     * @param HookContainer $hookContainer
105     */
106    public function __construct(
107        ILBFactory $dbLoadBalancerFactory,
108        BlobStoreFactory $blobStoreFactory,
109        NameTableStoreFactory $nameTables,
110        SlotRoleRegistry $slotRoleRegistry,
111        WANObjectCache $cache,
112        BagOStuff $localCache,
113        CommentStore $commentStore,
114        ActorStoreFactory $actorStoreFactory,
115        LoggerInterface $logger,
116        IContentHandlerFactory $contentHandlerFactory,
117        PageStoreFactory $pageStoreFactory,
118        TitleFactory $titleFactory,
119        HookContainer $hookContainer
120    ) {
121        $this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
122        $this->blobStoreFactory = $blobStoreFactory;
123        $this->slotRoleRegistry = $slotRoleRegistry;
124        $this->nameTables = $nameTables;
125        $this->cache = $cache;
126        $this->localCache = $localCache;
127        $this->commentStore = $commentStore;
128        $this->actorStoreFactory = $actorStoreFactory;
129        $this->logger = $logger;
130        $this->contentHandlerFactory = $contentHandlerFactory;
131        $this->pageStoreFactory = $pageStoreFactory;
132        $this->titleFactory = $titleFactory;
133        $this->hookContainer = $hookContainer;
134    }
135
136    /**
137     * @since 1.32
138     *
139     * @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
140     *
141     * @return RevisionStore for the given wikiId with all necessary services
142     */
143    public function getRevisionStore( $dbDomain = false ) {
144        return $this->getStore(
145            $dbDomain,
146            $this->actorStoreFactory->getActorStore( $dbDomain )
147        );
148    }
149
150    /**
151     * @since 1.42
152     *
153     * @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
154     *
155     * @return RevisionStore for the given wikiId with all necessary services
156     */
157    public function getRevisionStoreForImport( $dbDomain = false ) {
158        return $this->getStore(
159            $dbDomain,
160            $this->actorStoreFactory->getActorStoreForImport( $dbDomain )
161        );
162    }
163
164    /**
165     * @param false|string $dbDomain
166     * @param ActorStore $actorStore
167     *
168     * @return RevisionStore
169     */
170    private function getStore( $dbDomain, ActorStore $actorStore ) {
171        Assert::parameterType( [ 'string', 'false' ], $dbDomain, '$dbDomain' );
172
173        $store = new RevisionStore(
174            $this->dbLoadBalancerFactory->getMainLB( $dbDomain ),
175            $this->blobStoreFactory->newSqlBlobStore( $dbDomain ),
176            $this->cache, // Pass cache local to wiki; Leave cache sharing to RevisionStore.
177            $this->localCache,
178            $this->commentStore,
179            $this->nameTables->getContentModels( $dbDomain ),
180            $this->nameTables->getSlotRoles( $dbDomain ),
181            $this->slotRoleRegistry,
182            $actorStore,
183            $this->contentHandlerFactory,
184            $this->pageStoreFactory->getPageStore( $dbDomain ),
185            $this->titleFactory,
186            $this->hookContainer,
187            $dbDomain
188        );
189
190        $store->setLogger( $this->logger );
191
192        return $store;
193    }
194}