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