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