Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MessageBundleDependencyPurger | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
purge | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\MessageBundleTranslation; |
5 | |
6 | use MediaWiki\Extension\Translate\MessageGroupProcessing\TranslatableBundleFactory; |
7 | use MediaWiki\Title\Title; |
8 | |
9 | /** |
10 | * Purges titles dependent on a particular message bundle |
11 | * @author Abijeet Patro |
12 | * @license GPL-2.0-or-later |
13 | * @since 2024.10 |
14 | */ |
15 | class MessageBundleDependencyPurger { |
16 | private TranslatableBundleFactory $bundleFactory; |
17 | |
18 | public function __construct( TranslatableBundleFactory $bundleFactory ) { |
19 | $this->bundleFactory = $bundleFactory; |
20 | } |
21 | |
22 | public function purge( Title $messageBundleTitle ): void { |
23 | // Ensure we are dealing with valid message bundle |
24 | $messageBundle = $this->bundleFactory->getValidBundle( $messageBundleTitle ); |
25 | $offset = 0; |
26 | |
27 | do { |
28 | $titlesWithThisMessageBundle = $messageBundle->getTitle()->getTemplateLinksTo( |
29 | [ 'LIMIT' => 500, 'OFFSET' => $offset ] |
30 | ); |
31 | |
32 | foreach ( $titlesWithThisMessageBundle as $title ) { |
33 | $title->invalidateCache(); |
34 | } |
35 | |
36 | $offset += 500; |
37 | } while ( count( $titlesWithThisMessageBundle ) === 500 ); |
38 | } |
39 | } |