diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 34979cdbb..7dc819dde 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -916,7 +916,7 @@ public static function flushBatchDelete($scope = ''){ * @return ActiveRecord|null the locked document. * Returns instance of ActiveRecord. Null will be returned if the query does not have a result. */ - public static function lockDocument($idOrWhere, $lockFieldNames, $modifyOptions = [], $db = null) + public static function lockDocument($idOrWhere, $lockFieldNames = '_lock', $modifyOptions = [], $db = null) { $db = $db ? $db : static::getDb(); $db->transactionReady('lock document'); @@ -963,7 +963,7 @@ public static function lockDocument($idOrWhere, $lockFieldNames, $modifyOptions * Returns instance of ActiveRecord. Null will be returned if the query does not have a result. * When the total number of attempts to lock the document passes `try`, conflict error will be thrown */ - public static function LockDocumentStubbornly($id, $lockFieldName, $options = [], $db = null) + public static function LockDocumentStubbornly($id, $lockFieldName = '_lock', $options = [], $db = null) { $db = $db ? $db : static::getDb(); diff --git a/src/Transaction.php b/src/Transaction.php index 242fb01c6..adfdeb2f1 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -193,13 +193,19 @@ public function safeRollBack(&$exception = null) } } - public function run($query, $throw = false, $log = false){ + public function run($query, $throw = false, $log = false, $commit = false){ $lastMongoSession = $this->clientSession->db->getSession(); try { if(!$this->clientSession->getInTransaction()) $this->start(); $this->clientSession->db->setSession($this->clientSession); - return $query(); + if($query()) { + if($commit) { + return $this->safeCommit(); + } + return true; + } + return false; } catch(\Throwable $e) { $this->lastRunError = $e;