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