Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RevertedTagUpdateManager | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| approveRevertedTagForRevision | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Storage; |
| 8 | |
| 9 | use MediaWiki\JobQueue\JobQueueGroup; |
| 10 | use MediaWiki\JobQueue\Jobs\RevertedTagUpdateJob; |
| 11 | |
| 12 | /** |
| 13 | * Class for managing delayed RevertedTagUpdateJob waiting for user approval. |
| 14 | * |
| 15 | * This is intended to be used by the patrol subsystem and various content |
| 16 | * management extensions. |
| 17 | * |
| 18 | * @since 1.36 |
| 19 | * @author Ostrzyciel |
| 20 | */ |
| 21 | class RevertedTagUpdateManager { |
| 22 | |
| 23 | /** @var JobQueueGroup */ |
| 24 | private $jobQueueGroup; |
| 25 | |
| 26 | /** @var EditResultCache */ |
| 27 | private $editResultCache; |
| 28 | |
| 29 | public function __construct( |
| 30 | EditResultCache $editResultCache, |
| 31 | JobQueueGroup $jobQueueGroup |
| 32 | ) { |
| 33 | $this->jobQueueGroup = $jobQueueGroup; |
| 34 | $this->editResultCache = $editResultCache; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Enqueue a RevertedTagUpdateJob for the given revision, if needed. Call this when the |
| 39 | * user "approves" the edit. |
| 40 | * |
| 41 | * This method is also called whenever the edit is patrolled or autopatrolled. |
| 42 | * |
| 43 | * @param int $revertRevisionId |
| 44 | * |
| 45 | * @return bool Whether the update was enqueued successfully |
| 46 | */ |
| 47 | public function approveRevertedTagForRevision( int $revertRevisionId ): bool { |
| 48 | $editResult = $this->editResultCache->get( $revertRevisionId ); |
| 49 | if ( $editResult === null || !$editResult->isRevert() ) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | $spec = RevertedTagUpdateJob::newSpec( $revertRevisionId, $editResult ); |
| 54 | $this->jobQueueGroup->lazyPush( $spec ); |
| 55 | return true; |
| 56 | } |
| 57 | } |