Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CacheInvalidator | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| invalidate | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| 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 3 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 |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | namespace MediaWiki\GlobalUserPage; |
| 18 | |
| 19 | use MediaWiki\Config\Config; |
| 20 | use MediaWiki\JobQueue\JobQueueGroup; |
| 21 | use MediaWiki\JobQueue\JobSpecification; |
| 22 | use MediaWiki\MainConfigNames; |
| 23 | |
| 24 | class CacheInvalidator { |
| 25 | /** |
| 26 | * @param JobQueueGroup $jobQueueGroup |
| 27 | * @param Config $mainConfig |
| 28 | * @param string $username Username of the user who's userpage needs to be invalidated |
| 29 | * @param string[] $options Array of string options |
| 30 | */ |
| 31 | public function __construct( |
| 32 | private readonly JobQueueGroup $jobQueueGroup, |
| 33 | private readonly Config $mainConfig, |
| 34 | private readonly string $username, |
| 35 | private readonly array $options = [], |
| 36 | ) { |
| 37 | } |
| 38 | |
| 39 | public function invalidate(): void { |
| 40 | if ( !$this->mainConfig->get( MainConfigNames::UseCdn ) && |
| 41 | !$this->mainConfig->get( MainConfigNames::UseFileCache ) && |
| 42 | !$this->options |
| 43 | ) { |
| 44 | // No CDN and no options means nothing to do! |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | $this->jobQueueGroup->push( new JobSpecification( |
| 49 | 'GlobalUserPageLocalJobSubmitJob', |
| 50 | [ |
| 51 | 'username' => $this->username, |
| 52 | 'touch' => in_array( 'links', $this->options ), |
| 53 | ] |
| 54 | ) ); |
| 55 | } |
| 56 | } |