MediaWiki REL1_33
SavepointPostgres.php
Go to the documentation of this file.
1<?php
22namespace Wikimedia\Rdbms;
23
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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)
For a write query
Definition database.txt:26