Skip to content

Commit 782a9d5

Browse files
committed
match with enableLogging and enableProfiling
1 parent 96a6d4d commit 782a9d5

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/Transaction.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,30 @@ public function getIsActive(){
5353
*/
5454
public function start($transactionOptions = []){
5555
Command::prepareCPOptions($transactionOptions);
56-
Yii::debug('Starting mongodb transaction ...', __METHOD__);
56+
if($this->clientSession->db->enableLogging)
57+
Yii::debug('Starting mongodb transaction ...', __METHOD__);
5758
if($this->clientSession->getInTransaction())
5859
throw new Exception('Nested transaction not supported');
5960
$this->clientSession->db->trigger(Connection::EVENT_START_TRANSACTION);
60-
if($this->clientSession->db->enableLogging)
61+
if($this->clientSession->db->enableProfiling)
6162
Yii::beginProfile('mongodb > start transaction(session id => '.$this->clientSession->getId().')');
6263
$this->clientSession->mongoSession->startTransaction($transactionOptions);
63-
Yii::debug('MongoDB transaction started.', __METHOD__);
64+
if($this->clientSession->db->enableLogging)
65+
Yii::debug('MongoDB transaction started.', __METHOD__);
6466
}
6567

6668
/**
6769
* Commit a transaction.
6870
* @see https://www.php.net/manual/en/mongodb-driver-session.committransaction.php
6971
*/
7072
public function commit(){
71-
Yii::debug('Committing mongodb transaction ...', __METHOD__);
72-
$this->clientSession->mongoSession->commitTransaction();
7373
if($this->clientSession->db->enableLogging)
74+
Yii::debug('Committing mongodb transaction ...', __METHOD__);
75+
$this->clientSession->mongoSession->commitTransaction();
76+
if($this->clientSession->db->enableProfiling)
7477
Yii::endProfile('mongodb > start transaction(session id => '.$this->clientSession->getId().')');
75-
Yii::debug('Commit mongodb transaction.', __METHOD__);
78+
if($this->clientSession->db->enableLogging)
79+
Yii::debug('Commit mongodb transaction.', __METHOD__);
7680
$this->clientSession->db->trigger(Connection::EVENT_COMMIT_TRANSACTION);
7781
}
7882

@@ -81,11 +85,13 @@ public function commit(){
8185
* @see https://www.php.net/manual/en/mongodb-driver-session.aborttransaction.php
8286
*/
8387
public function rollBack(){
84-
Yii::debug('Rolling back mongodb transaction ...', __METHOD__);
85-
$this->clientSession->mongoSession->abortTransaction();
8688
if($this->clientSession->db->enableLogging)
89+
Yii::debug('Rolling back mongodb transaction ...', __METHOD__);
90+
$this->clientSession->mongoSession->abortTransaction();
91+
if($this->clientSession->db->enableProfiling)
8792
Yii::endProfile('mongodb > start transaction(session id => '.$this->clientSession->getId().')');
88-
Yii::debug('Roll back mongodb transaction.', __METHOD__);
93+
if($this->clientSession->db->enableLogging)
94+
Yii::debug('Roll back mongodb transaction.', __METHOD__);
8995
$this->clientSession->db->trigger(Connection::EVENT_ROLLBACK_TRANSACTION);
9096
}
9197
}

0 commit comments

Comments
 (0)