Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ziaratban committed Dec 15, 2024
1 parent b834c39 commit adc750c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();

Expand Down
10 changes: 8 additions & 2 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit adc750c

Please sign in to comment.