MediaWiki REL1_28
SavepointPostgres.php
Go to the documentation of this file.
1<?php
21use Psr\Log\LoggerInterface;
22
30 protected $dbw;
32 protected $logger;
34 protected $id;
36 protected $didbegin;
37
43 public function __construct( DatabasePostgres $dbw, $id, LoggerInterface $logger ) {
44 $this->dbw = $dbw;
45 $this->logger = $logger;
46 $this->id = $id;
47 $this->didbegin = false;
48 /* If we are not in a transaction, we need to be for savepoint trickery */
49 if ( !$dbw->trxLevel() ) {
50 $dbw->begin( __CLASS__, DatabasePostgres::TRANSACTION_INTERNAL );
51 $this->didbegin = true;
52 }
53 }
54
55 public function __destruct() {
56 if ( $this->didbegin ) {
57 $this->dbw->rollback();
58 $this->didbegin = false;
59 }
60 }
61
62 public function commit() {
63 if ( $this->didbegin ) {
64 $this->dbw->commit( __CLASS__, DatabasePostgres::FLUSHING_INTERNAL );
65 $this->didbegin = false;
66 }
67 }
68
69 protected function query( $keyword, $msg_ok, $msg_failed ) {
70 if ( $this->dbw->doQuery( $keyword . " " . $this->id ) !== false ) {
71 $this->logger->debug( sprintf( $msg_ok, $this->id ) );
72 } else {
73 $this->logger->debug( sprintf( $msg_failed, $this->id ) );
74 }
75 }
76
77 public function savepoint() {
78 $this->query( "SAVEPOINT",
79 "Transaction state: savepoint \"%s\" established.\n",
80 "Transaction state: establishment of savepoint \"%s\" FAILED.\n"
81 );
82 }
83
84 public function release() {
85 $this->query( "RELEASE",
86 "Transaction state: savepoint \"%s\" released.\n",
87 "Transaction state: release of savepoint \"%s\" FAILED.\n"
88 );
89 }
90
91 public function rollback() {
92 $this->query( "ROLLBACK TO",
93 "Transaction state: savepoint \"%s\" rolled back.\n",
94 "Transaction state: rollback of savepoint \"%s\" FAILED.\n"
95 );
96 }
97
98 public function __toString() {
99 return (string)$this->id;
100 }
101}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
trxLevel()
Gets the current transaction level.
Definition Database.php:440
begin( $fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT)
Begin a transaction.
Manage savepoints within a transaction.
DatabasePostgres $dbw
Establish a savepoint within a transaction.
__construct(DatabasePostgres $dbw, $id, LoggerInterface $logger)
LoggerInterface $logger
query( $keyword, $msg_ok, $msg_failed)
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