Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
87.50% covered (warning)
87.50%
7 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
PageUpdateStatus
92.86% covered (success)
92.86%
13 / 14
87.50% covered (warning)
87.50%
7 / 8
13.06
0.00% covered (danger)
0.00%
0 / 1
 newEmpty
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 setNewRevision
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNewRevision
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 wasRevisionCreated
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 wasPageCreated
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 failedBecausePageExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 failedBecausePageMissing
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 failedBecauseOfConflict
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
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\Revision\RevisionRecord;
24use MediaWiki\Status\Status;
25
26/**
27 * Status object representing the outcome of a page update.
28 *
29 * @see PageUpdater
30 *
31 * @since 1.40
32 * @ingroup Page
33 * @author Daniel Kinzler
34 */
35class PageUpdateStatus extends Status {
36
37    /**
38     * @internal for use by PageUpdater only
39     * @param bool $newPage
40     *
41     * @return PageUpdateStatus
42     */
43    public static function newEmpty( bool $newPage ): PageUpdateStatus {
44        return static::newGood( [
45            'new' => $newPage,
46            'revision-record' => null
47        ] );
48    }
49
50    /**
51     * @internal for use by PageUpdater only
52     * @param RevisionRecord $rev
53     */
54    public function setNewRevision( RevisionRecord $rev ) {
55        $this->value['revision-record'] = $rev;
56    }
57
58    /**
59     * The revision created by PageUpdater::saveRevision().
60     *
61     * Will return null if no revision was created because there was an error,
62     * or because the content didn't change (null edit or derived slot update).
63     *
64     * Call isOK() to distinguish these cases.
65     */
66    public function getNewRevision(): ?RevisionRecord {
67        if ( !$this->isOK() ) {
68            return null;
69        }
70
71        return $this->value['revision-record'] ?? null;
72    }
73
74    /**
75     * Whether the update created a revision.
76     * If this returns false even though isOK() returns true, this means that
77     * no new revision was created because the content didn't change,
78     * including updates to derived slots.
79     */
80    public function wasRevisionCreated(): bool {
81        return $this->getNewRevision() !== null;
82    }
83
84    /**
85     * Whether the update created the page.
86     */
87    public function wasPageCreated(): bool {
88        return $this->wasRevisionCreated()
89            && ( $this->value['new'] ?? false );
90    }
91
92    /**
93     * Whether the update failed because page creation was required, but the page already exists.
94     */
95    public function failedBecausePageExists(): bool {
96        return !$this->isOK() && $this->hasMessage( 'edit-already-exists' );
97    }
98
99    /**
100     * Whether the update failed because page modification was required, but the page does not exist.
101     */
102    public function failedBecausePageMissing(): bool {
103        return !$this->isOK() && $this->hasMessage( 'edit-gone-missing' );
104    }
105
106    /**
107     * Whether the update failed because a conflicting update happened concurrently.
108     */
109    public function failedBecauseOfConflict(): bool {
110        return !$this->isOK() && $this->hasMessage( 'edit-conflict' );
111    }
112
113}