[UPDATE] Use proper transaction ID boundaries
This commit is contained in:
parent
b0cdbd54bc
commit
78ae3174d8
@ -34,12 +34,14 @@ class Transaction extends Base {
|
|||||||
* @param bool boolean True or False
|
* @param bool boolean True or False
|
||||||
**/
|
**/
|
||||||
public function setArchived($account_id, $txid) {
|
public function setArchived($account_id, $txid) {
|
||||||
$stmt = $this->mysqli->prepare("
|
// Fetch last archived transaction for user
|
||||||
UPDATE $this->table AS t
|
$stmt = $this->mysqli->prepare("SELECT IFNULL(MAX(id), 0) AS id FROM $this->table WHERE archived = 1 AND account_id = ?");
|
||||||
SET t.archived = 1
|
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result())
|
||||||
WHERE archived = 0 AND t.account_id = ? AND t.id <= ?
|
$last_id = $result->fetch_object()->id;
|
||||||
");
|
$this->debug->append('Found last archived transaction: ' . $last_id);
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $txid) && $stmt->execute())
|
// Update all transactions, mark as archived for user previous to $txid and higher than last archived transaction
|
||||||
|
$stmt = $this->mysqli->prepare("UPDATE $this->table SET archived = 1 WHERE archived = 0 AND account_id = ? AND id <= ? AND id > ?");
|
||||||
|
if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $account_id, $txid, $last_id) && $stmt->execute())
|
||||||
return true;
|
return true;
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user