Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.97% |
32 / 33 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
DatabaseBlockStoreFactory | |
96.97% |
32 / 33 |
|
50.00% |
1 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
getDatabaseBlockStore | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
5 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Block; |
22 | |
23 | use MediaWiki\CommentStore\CommentStore; |
24 | use MediaWiki\Config\ServiceOptions; |
25 | use MediaWiki\HookContainer\HookContainer; |
26 | use MediaWiki\User\ActorStoreFactory; |
27 | use MediaWiki\User\TempUser\TempUserConfig; |
28 | use MediaWiki\User\UserFactory; |
29 | use Psr\Log\LoggerInterface; |
30 | use Wikimedia\Rdbms\LBFactory; |
31 | use Wikimedia\Rdbms\ReadOnlyMode; |
32 | |
33 | /** |
34 | * @author Zabe |
35 | * |
36 | * @since 1.40 |
37 | */ |
38 | class DatabaseBlockStoreFactory { |
39 | /** |
40 | * @internal For use by ServiceWiring |
41 | */ |
42 | public const CONSTRUCTOR_OPTIONS = DatabaseBlockStore::CONSTRUCTOR_OPTIONS; |
43 | |
44 | private ServiceOptions $options; |
45 | private LoggerInterface $logger; |
46 | private ActorStoreFactory $actorStoreFactory; |
47 | private BlockRestrictionStoreFactory $blockRestrictionStoreFactory; |
48 | private CommentStore $commentStore; |
49 | private HookContainer $hookContainer; |
50 | private LBFactory $loadBalancerFactory; |
51 | private ReadOnlyMode $readOnlyMode; |
52 | private UserFactory $userFactory; |
53 | private TempUserConfig $tempUserConfig; |
54 | private CrossWikiBlockTargetFactory $crossWikiBlockTargetFactory; |
55 | private AutoblockExemptionList $autoblockExemptionList; |
56 | |
57 | /** @var DatabaseBlockStore[] */ |
58 | private array $storeCache = []; |
59 | |
60 | public function __construct( |
61 | ServiceOptions $options, |
62 | LoggerInterface $logger, |
63 | ActorStoreFactory $actorStoreFactory, |
64 | BlockRestrictionStoreFactory $blockRestrictionStoreFactory, |
65 | CommentStore $commentStore, |
66 | HookContainer $hookContainer, |
67 | LBFactory $loadBalancerFactory, |
68 | ReadOnlyMode $readOnlyMode, |
69 | UserFactory $userFactory, |
70 | TempUserConfig $tempUserConfig, |
71 | CrossWikiBlockTargetFactory $crossWikiBlockTargetFactory, |
72 | AutoblockExemptionList $autoblockExemptionList |
73 | ) { |
74 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
75 | |
76 | $this->options = $options; |
77 | $this->logger = $logger; |
78 | $this->actorStoreFactory = $actorStoreFactory; |
79 | $this->blockRestrictionStoreFactory = $blockRestrictionStoreFactory; |
80 | $this->commentStore = $commentStore; |
81 | $this->hookContainer = $hookContainer; |
82 | $this->loadBalancerFactory = $loadBalancerFactory; |
83 | $this->readOnlyMode = $readOnlyMode; |
84 | $this->userFactory = $userFactory; |
85 | $this->tempUserConfig = $tempUserConfig; |
86 | $this->crossWikiBlockTargetFactory = $crossWikiBlockTargetFactory; |
87 | $this->autoblockExemptionList = $autoblockExemptionList; |
88 | } |
89 | |
90 | /** |
91 | * @param string|false $wikiId |
92 | * @return DatabaseBlockStore |
93 | */ |
94 | public function getDatabaseBlockStore( $wikiId = DatabaseBlock::LOCAL ): DatabaseBlockStore { |
95 | if ( is_string( $wikiId ) && $this->loadBalancerFactory->getLocalDomainID() === $wikiId ) { |
96 | $wikiId = DatabaseBlock::LOCAL; |
97 | } |
98 | |
99 | $storeCacheKey = $wikiId === DatabaseBlock::LOCAL ? 'LOCAL' : 'crosswikistore-' . $wikiId; |
100 | if ( !isset( $this->storeCache[$storeCacheKey] ) ) { |
101 | $this->storeCache[$storeCacheKey] = new DatabaseBlockStore( |
102 | $this->options, |
103 | $this->logger, |
104 | $this->actorStoreFactory, |
105 | $this->blockRestrictionStoreFactory->getBlockRestrictionStore( $wikiId ), |
106 | $this->commentStore, |
107 | $this->hookContainer, |
108 | $this->loadBalancerFactory, |
109 | $this->readOnlyMode, |
110 | $this->userFactory, |
111 | $this->tempUserConfig, |
112 | $this->crossWikiBlockTargetFactory->getFactory( $wikiId ), |
113 | $this->autoblockExemptionList, |
114 | $wikiId |
115 | ); |
116 | } |
117 | return $this->storeCache[$storeCacheKey]; |
118 | } |
119 | } |