[REVERT] Do not use TX ID boundaries for archiving

This commit is contained in:
Sebastian Grewe 2013-12-02 16:46:42 +01:00
parent 44f4b466a4
commit 7a2e6061ab

View File

@ -34,21 +34,15 @@ class Transaction extends Base {
* @param bool boolean True or False
**/
public function setArchived($account_id, $txid) {
// Fetch last archived transaction for user, we must exclude our Debits though! There might be unarchived/archived
// records before our last payout
$stmt = $this->mysqli->prepare("SELECT IFNULL(MAX(id), 0) AS id FROM $this->table WHERE archived = 1 AND account_id = ? AND type NOT IN ('Debit_MP','Debit_AP','TXFee')");
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result())
$last_id = $result->fetch_object()->id;
$this->debug->append('Found last archived transaction: ' . $last_id);
// Update all transactions, mark as archived for user previous to $txid and higher than last archived transaction
// Update all paid out transactions as archived
$stmt = $this->mysqli->prepare("
UPDATE $this->table AS t
LEFT JOIN " . $this->block->getTableName() . " AS b
ON b.id = t.block_id
SET archived = 1
WHERE t.archived = 0 AND t.account_id = ? AND t.id <= ? AND t.id > ? AND (b.confirmations >= ? OR b.confirmations IS NULL)
");
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $account_id, $txid, $last_id, $this->config['confirmations']) && $stmt->execute())
SET t.archived = 1
WHERE ( t.account_id = ? AND t.id <= ? AND b.confirmations >= ? )
OR ( t.account_id = ? AND t.id <= ? AND t.type IN ( 'Credit_PPS', 'Donation_PPS', 'Fee_PPS', 'TXFee', 'Debit_MP', 'Debit_AP' ) )");
if ($this->checkStmt($stmt) && $stmt->bind_param('iiiii', $account_id, $txid, $this->config['confirmations'], $account_id, $txid) && $stmt->execute())
return true;
return $this->sqlError();
}