Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #1289 #1355

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions include/database/MysqliManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ class MysqliManager extends MysqlManager
/**
* @see MysqlManager::query()
*/
public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false)
public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false, $autoCommit = true)
{
if(is_array($sql)) {
return $this->queryArray($sql, $dieOnError, $msg, $suppress);
}


$this->database->autocommit($autoCommit);

if($sugar_config['logger']['level'] == 'debug') {
$autoCommitResult = $this->database->query("SELECT @@AUTOCOMMIT");
$autoCommit = $autoCommitResult->fetch_row()[0];
$autoCommitResult->free();
$GLOBALS['log']->debug("Auto commit state:" . (($autoCommit) ? "on" : "off"));
}

static $queryMD5 = array();

parent::countQuery($sql);
Expand Down Expand Up @@ -160,6 +169,14 @@ public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $

return $result;
}

/**
* Commits all uncommitted queries
*/
public function commit()
{
$this->database->commit();
}

/**
* Returns the number of rows affected by the last query
Expand All @@ -168,7 +185,7 @@ public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $
*/
public function getAffectedRowCount($result)
{
return mysqli_affected_rows($this->getDatabase());
return $this->database->affected_rows;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion modules/EmailMan/EmailManDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@
$lock_query.=" AND (in_queue ='0' OR in_queue IS NULL OR ( in_queue ='1' AND in_queue_date <= " .$db->convert($db->quoted($timedate->fromString("-1 day")->asDb()),"datetime")."))";

//if the query fails to execute.. terminate campaign email process.
$lock_result=$db->query($lock_query,true,'Error acquiring a lock for emailman entry.');
$lock_result=$db->query($lock_query,true,'Error acquiring a lock for emailman entry.',false,false,false);
$lock_count=$db->getAffectedRowCount($lock_result);
if($db->dbtype == "mysql" && $db->variant == "mysqli") {
$db->commit();
}

//do not process the message if unable to acquire lock.
if (!$test && $lock_count!= 1) {
Expand Down