MediaWiki REL1_31
AutoCommitUpdate.php
Go to the documentation of this file.
1<?php
2
4
11 private $dbw;
13 private $fname;
15 private $callback;
16
22 public function __construct( IDatabase $dbw, $fname, callable $callback ) {
23 $this->dbw = $dbw;
24 $this->fname = $fname;
25 $this->callback = $callback;
26
27 if ( $this->dbw->trxLevel() ) {
28 $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
29 }
30 }
31
32 public function doUpdate() {
33 if ( !$this->callback ) {
34 return;
35 }
36
37 $autoTrx = $this->dbw->getFlag( DBO_TRX );
38 $this->dbw->clearFlag( DBO_TRX );
39 try {
41 $e = null;
42 call_user_func_array( $this->callback, [ $this->dbw, $this->fname ] );
43 } catch ( Exception $e ) {
44 }
45 if ( $autoTrx ) {
46 $this->dbw->setFlag( DBO_TRX );
47 }
48 if ( $e ) {
49 throw $e;
50 }
51 }
52
53 public function cancelOnRollback( $trigger ) {
54 if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
55 $this->callback = null;
56 }
57 }
58
59 public function getOrigin() {
60 return $this->fname;
61 }
62}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Deferrable Update for closure/callback updates that should use auto-commit mode.
__construct(IDatabase $dbw, $fname, callable $callback)
callable null $callback
doUpdate()
Perform the actual work.
cancelOnRollback( $trigger)
returning false will NOT prevent logging $e
Definition hooks.txt:2176
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
Definition injection.txt:37
Callback wrapper that has an originating method.
Interface that deferrable updates should implement.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback as soon as the current transaction commits or rolls back.
const DBO_TRX
Definition defines.php:12