Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RevertedTagUpdateManager | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
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 | public function __construct( |
| 24 | private readonly EditResultCache $editResultCache, |
| 25 | private readonly JobQueueGroup $jobQueueGroup, |
| 26 | ) { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Enqueue a RevertedTagUpdateJob for the given revision, if needed. Call this when the |
| 31 | * user "approves" the edit. |
| 32 | * |
| 33 | * This method is also called whenever the edit is patrolled or autopatrolled. |
| 34 | * |
| 35 | * @param int $revertRevisionId |
| 36 | * |
| 37 | * @return bool Whether the update was enqueued successfully |
| 38 | */ |
| 39 | public function approveRevertedTagForRevision( int $revertRevisionId ): bool { |
| 40 | $editResult = $this->editResultCache->get( $revertRevisionId ); |
| 41 | if ( $editResult === null || !$editResult->isRevert() ) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | $spec = RevertedTagUpdateJob::newSpec( $revertRevisionId, $editResult ); |
| 46 | $this->jobQueueGroup->lazyPush( $spec ); |
| 47 | return true; |
| 48 | } |
| 49 | } |