15 $update = $this->getMockBuilder( DeferrableUpdate::class )
16 ->setMethods( [
'doUpdate' ] )->getMock();
17 $update->expects( $this->once() )->method(
'doUpdate' );
19 DeferredUpdates::addUpdate( $update );
20 DeferredUpdates::doUpdates();
30 $update1 = $this->getMockBuilder( MergeableUpdate::class )
31 ->setMethods( [
'merge',
'doUpdate' ] )->getMock();
32 $update1->expects( $this->once() )->method(
'merge' );
33 $update1->expects( $this->never() )->method(
'doUpdate' );
35 $update2 = $this->getMockBuilder( MergeableUpdate::class )
36 ->setMethods( [
'merge',
'doUpdate' ] )->getMock();
37 $update2->expects( $this->never() )->method(
'merge' );
38 $update2->expects( $this->never() )->method(
'doUpdate' );
40 DeferredUpdates::addUpdate( $update1 );
41 DeferredUpdates::addUpdate( $update2 );
52 DeferredUpdates::addCallableUpdate(
function ()
use ( &$ran ) {
55 DeferredUpdates::doUpdates();
57 $this->assertSame( 1, $ran,
'Update ran' );
68 $pre = DeferredUpdates::PRESEND;
69 $post = DeferredUpdates::POSTSEND;
70 $all = DeferredUpdates::ALL;
72 $update = $this->getMock( DeferrableUpdate::class );
73 $update->expects( $this->never() )
74 ->method(
'doUpdate' );
76 DeferredUpdates::addUpdate( $update,
$pre );
77 $this->assertCount( 1, DeferredUpdates::getPendingUpdates(
$pre ) );
78 $this->assertCount( 0, DeferredUpdates::getPendingUpdates( $post ) );
79 $this->assertCount( 1, DeferredUpdates::getPendingUpdates( $all ) );
80 $this->assertCount( 1, DeferredUpdates::getPendingUpdates() );
81 DeferredUpdates::clearPendingUpdates();
82 $this->assertCount( 0, DeferredUpdates::getPendingUpdates() );
84 DeferredUpdates::addUpdate( $update, $post );
85 $this->assertCount( 0, DeferredUpdates::getPendingUpdates(
$pre ) );
86 $this->assertCount( 1, DeferredUpdates::getPendingUpdates( $post ) );
87 $this->assertCount( 1, DeferredUpdates::getPendingUpdates( $all ) );
88 $this->assertCount( 1, DeferredUpdates::getPendingUpdates() );
89 DeferredUpdates::clearPendingUpdates();
90 $this->assertCount( 0, DeferredUpdates::getPendingUpdates() );
102 '1' =>
"deferred update 1;\n",
103 '2' =>
"deferred update 2;\n",
104 '2-1' =>
"deferred update 1 within deferred update 2;\n",
105 '2-2' =>
"deferred update 2 within deferred update 2;\n",
106 '3' =>
"deferred update 3;\n",
107 '3-1' =>
"deferred update 1 within deferred update 3;\n",
108 '3-2' =>
"deferred update 2 within deferred update 3;\n",
109 '3-1-1' =>
"deferred update 1 within deferred update 1 within deferred update 3;\n",
110 '3-2-1' =>
"deferred update 1 within deferred update 2 with deferred update 3;\n",
112 DeferredUpdates::addCallableUpdate(
113 function ()
use ( $updates ) {
117 DeferredUpdates::addCallableUpdate(
118 function ()
use ( $updates ) {
120 DeferredUpdates::addCallableUpdate(
121 function ()
use ( $updates ) {
122 echo $updates[
'2-1'];
125 DeferredUpdates::addCallableUpdate(
126 function ()
use ( $updates ) {
127 echo $updates[
'2-2'];
132 DeferredUpdates::addCallableUpdate(
133 function ()
use ( $updates ) {
135 DeferredUpdates::addCallableUpdate(
136 function ()
use ( $updates ) {
137 echo $updates[
'3-1'];
138 DeferredUpdates::addCallableUpdate(
139 function ()
use ( $updates ) {
140 echo $updates[
'3-1-1'];
145 DeferredUpdates::addCallableUpdate(
146 function ()
use ( $updates ) {
147 echo $updates[
'3-2'];
148 DeferredUpdates::addCallableUpdate(
149 function ()
use ( $updates ) {
150 echo $updates[
'3-2-1'];
158 $this->assertEquals( 3, DeferredUpdates::pendingUpdatesCount() );
160 $this->expectOutputString( implode(
'', $updates ) );
162 DeferredUpdates::doUpdates();
166 DeferredUpdates::addCallableUpdate(
167 function ()
use ( &$x ) {
170 DeferredUpdates::PRESEND
172 DeferredUpdates::addCallableUpdate(
173 function ()
use ( &$y ) {
176 DeferredUpdates::POSTSEND
179 $this->assertNull( $x,
"Update not run yet" );
180 $this->assertNull( $y,
"Update not run yet" );
182 DeferredUpdates::doUpdates(
'run', DeferredUpdates::PRESEND );
183 $this->assertEquals(
"Sherity", $x,
"PRESEND update ran" );
184 $this->assertNull( $y,
"POSTSEND update not run yet" );
186 DeferredUpdates::doUpdates(
'run', DeferredUpdates::POSTSEND );
187 $this->assertEquals(
"Marychu", $y,
"POSTSEND update ran" );
198 '1' =>
"deferred update 1;\n",
199 '2' =>
"deferred update 2;\n",
200 '2-1' =>
"deferred update 1 within deferred update 2;\n",
201 '2-2' =>
"deferred update 2 within deferred update 2;\n",
202 '3' =>
"deferred update 3;\n",
203 '3-1' =>
"deferred update 1 within deferred update 3;\n",
204 '3-2' =>
"deferred update 2 within deferred update 3;\n",
205 '3-1-1' =>
"deferred update 1 within deferred update 1 within deferred update 3;\n",
206 '3-2-1' =>
"deferred update 1 within deferred update 2 with deferred update 3;\n",
210 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
211 $lbFactory->commitMasterChanges( __METHOD__ );
213 DeferredUpdates::addCallableUpdate(
214 function ()
use ( $updates ) {
218 DeferredUpdates::addCallableUpdate(
219 function ()
use ( $updates ) {
221 DeferredUpdates::addCallableUpdate(
222 function ()
use ( $updates ) {
223 echo $updates[
'2-1'];
226 DeferredUpdates::addCallableUpdate(
227 function ()
use ( $updates ) {
228 echo $updates[
'2-2'];
233 DeferredUpdates::addCallableUpdate(
234 function ()
use ( $updates ) {
236 DeferredUpdates::addCallableUpdate(
237 function ()
use ( $updates ) {
238 echo $updates[
'3-1'];
239 DeferredUpdates::addCallableUpdate(
240 function ()
use ( $updates ) {
241 echo $updates[
'3-1-1'];
246 DeferredUpdates::addCallableUpdate(
247 function ()
use ( $updates ) {
248 echo $updates[
'3-2'];
249 DeferredUpdates::addCallableUpdate(
250 function ()
use ( $updates ) {
251 echo $updates[
'3-2-1'];
259 $this->expectOutputString( implode(
'', $updates ) );
261 DeferredUpdates::doUpdates();
275 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
276 $lbFactory->commitMasterChanges( __METHOD__ );
278 DeferredUpdates::addCallableUpdate(
279 function ()
use ( &$x, &$y ) {
281 DeferredUpdates::addCallableUpdate(
282 function ()
use ( &$y ) {
285 DeferredUpdates::PRESEND
288 DeferredUpdates::POSTSEND
291 DeferredUpdates::doUpdates();
293 $this->assertTrue( $x,
"Outer POSTSEND update ran" );
294 $this->assertTrue( $y,
"Nested PRESEND update ran" );
303 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
304 $this->assertFalse( $lbFactory->hasTransactionRound(),
'Initial state' );
307 DeferredUpdates::addCallableUpdate(
function ()
use ( &$ran, $lbFactory ) {
309 $this->assertTrue( $lbFactory->hasTransactionRound(),
'Has transaction' );
311 DeferredUpdates::doUpdates();
313 $this->assertSame( 1, $ran,
'Update ran' );
314 $this->assertFalse( $lbFactory->hasTransactionRound(),
'Final state' );
324 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
325 $this->assertFalse( $lbFactory->hasTransactionRound(),
'Initial state' );
329 function ()
use ( &$ran, $lbFactory ) {
331 $this->assertFalse( $lbFactory->hasTransactionRound(),
'No transaction' );
334 DeferredUpdates::doUpdates();
336 $this->assertSame( 1, $ran,
'Update ran' );
344 $callback1 =
function ()
use ( &$calls ) {
347 $callback2 =
function ()
use ( &$calls ) {
351 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
352 $lbFactory->beginMasterChanges( __METHOD__ );
354 DeferredUpdates::addCallableUpdate( $callback1 );
355 $this->assertEquals( [], $calls );
357 DeferredUpdates::tryOpportunisticExecute(
'run' );
358 $this->assertEquals( [], $calls );
361 $dbw->onTransactionCommitOrIdle(
function ()
use ( &$calls, $callback2 ) {
362 DeferredUpdates::addCallableUpdate( $callback2 );
363 $this->assertEquals( [], $calls );
366 $this->assertEquals( 1, $dbw->trxLevel() );
367 $this->assertEquals( [], $calls );
369 $lbFactory->commitMasterChanges( __METHOD__ );
371 $this->assertEquals( [
'oti' ], $calls );
373 DeferredUpdates::tryOpportunisticExecute(
'run' );
374 $this->assertEquals( [
'oti', 1, 2 ], $calls );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
testAddAndRun()
DeferredUpdates::addUpdate DeferredUpdates::push DeferredUpdates::doUpdates DeferredUpdates::execute ...
testRunOuterScopeUpdate()
DeferredUpdates::runUpdate TransactionRoundDefiningUpdate::getOrigin.
testGetPendingUpdates()
DeferredUpdates::getPendingUpdates DeferredUpdates::clearPendingUpdates.
testPresendAddOnPostsendRun()
DeferredUpdates::doUpdates DeferredUpdates::execute DeferredUpdates::addUpdate.
testRunUpdateTransactionScope()
DeferredUpdates::runUpdate.
testDoUpdatesCLI()
DeferredUpdates::doUpdates DeferredUpdates::execute DeferredUpdates::addUpdate.
testTryOpportunisticExecute()
DeferredUpdates::tryOpportunisticExecute.
testAddCallableUpdate()
DeferredUpdates::addCallableUpdate MWCallableUpdate::getOrigin.
testAddMergeable()
DeferredUpdates::addUpdate DeferredUpdates::push.
testDoUpdatesWeb()
DeferredUpdates::doUpdates DeferredUpdates::execute DeferredUpdates::addUpdate.
Deferrable update that must run outside of any explicit LBFactory transaction round.
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped $pre
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php