Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
46.67% |
7 / 15 |
|
30.00% |
3 / 10 |
CRAP | |
0.00% |
0 / 1 |
| DeferredUpdatesScopeStack | |
50.00% |
7 / 14 |
|
30.00% |
3 / 10 |
26.12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| current | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| descend | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| ascend | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| getRecursiveDepth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| allowOpportunisticUpdates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| queueDataUpdate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onRunUpdateStart | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onRunUpdateEnd | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onRunUpdateFailed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Deferred; |
| 8 | |
| 9 | use LogicException; |
| 10 | |
| 11 | /** |
| 12 | * DeferredUpdates helper class for tracking DeferrableUpdate::doUpdate() nesting levels |
| 13 | * caused by nested calls to DeferredUpdates::doUpdates() |
| 14 | * |
| 15 | * @internal For use by DeferredUpdates only |
| 16 | * @since 1.36 |
| 17 | */ |
| 18 | class DeferredUpdatesScopeStack { |
| 19 | /** @var DeferredUpdatesScope[] Stack of root scope and any recursive scopes */ |
| 20 | private $stack; |
| 21 | |
| 22 | public function __construct() { |
| 23 | $this->stack = [ DeferredUpdatesScope::newRootScope() ]; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return DeferredUpdatesScope The innermost scope |
| 28 | */ |
| 29 | public function current() { |
| 30 | return $this->stack[count( $this->stack ) - 1]; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Make a new child scope, push it onto the stack, and return it |
| 35 | * |
| 36 | * @param int $activeStage The in-progress stage; one of DeferredUpdates::STAGES |
| 37 | * @param DeferrableUpdate $update The deferred update that owns this scope |
| 38 | * @return DeferredUpdatesScope Scope for the case of an in-progress deferred update |
| 39 | */ |
| 40 | public function descend( $activeStage, DeferrableUpdate $update ) { |
| 41 | $scope = DeferredUpdatesScope::newChildScope( $activeStage, $update, $this->current() ); |
| 42 | $this->stack[count( $this->stack )] = $scope; |
| 43 | |
| 44 | return $scope; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Pop the innermost scope from the stack |
| 49 | * |
| 50 | * @return DeferredUpdatesScope |
| 51 | */ |
| 52 | public function ascend() { |
| 53 | if ( count( $this->stack ) <= 1 ) { |
| 54 | throw new LogicException( "Cannot pop root stack scope; something is out of sync" ); |
| 55 | } |
| 56 | |
| 57 | return array_pop( $this->stack ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get the depth of the scope stack below the root scope |
| 62 | * |
| 63 | * @return int |
| 64 | */ |
| 65 | public function getRecursiveDepth() { |
| 66 | return count( $this->stack ) - 1; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Whether DeferredUpdates::addUpdate() may run the update right away |
| 71 | */ |
| 72 | public function allowOpportunisticUpdates(): bool { |
| 73 | // Overridden in DeferredUpdatesScopeMediaWikiStack::allowOpportunisticUpdates |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Queue an EnqueueableDataUpdate as a job instead |
| 79 | * |
| 80 | * @see JobQueueGroup::push |
| 81 | * @param EnqueueableDataUpdate $update |
| 82 | */ |
| 83 | public function queueDataUpdate( EnqueueableDataUpdate $update ): void { |
| 84 | throw new LogicException( 'Cannot queue jobs from DeferredUpdates in standalone mode' ); |
| 85 | } |
| 86 | |
| 87 | public function onRunUpdateStart( DeferrableUpdate $update ): void { |
| 88 | // No-op |
| 89 | // Overridden in DeferredUpdatesScopeMediaWikiStack::onRunUpdateStart |
| 90 | } |
| 91 | |
| 92 | public function onRunUpdateEnd( DeferrableUpdate $update ): void { |
| 93 | // No-op |
| 94 | // Overridden in DeferredUpdatesScopeMediaWikiStack::onRunUpdateEnd |
| 95 | } |
| 96 | |
| 97 | public function onRunUpdateFailed( DeferrableUpdate $update ): void { |
| 98 | // No-op |
| 99 | // Overridden in DeferredUpdatesScopeMediaWikiStack::onRunUpdateFailed |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** @deprecated class alias since 1.42 */ |
| 104 | class_alias( DeferredUpdatesScopeStack::class, 'DeferredUpdatesScopeStack' ); |