/** * Remove transaction (and all associated contributions) from database * * @param boolean $transaction Activate transaction mode (defaults to true) * * @return boolean */ public function remove($transaction = true) { global $zdb; try { if ($transaction) { $zdb->connection->beginTransaction(); } //remove associated contributions if needeed if ($this->getDispatchedAmount() > 0) { $c = new Contributions(); $clist = $c->getListFromTransaction($this->_id); $cids = array(); foreach ($clist as $cid) { $cids[] = $cid->id; } $rem = $c->removeContributions($cids, false); } //remove transaction itself $delete = $zdb->delete(self::TABLE); $delete->where(self::PK . ' = ' . $this->_id); $zdb->execute($delete); if ($transaction) { $zdb->connection->commit(); } return true; } catch (\Exception $e) { if ($transaction) { $zdb->connection->rollBack(); } Analog::log('An error occured trying to remove transaction #' . $this->_id . ' | ' . $e->getMessage(), Analog::ERROR); return false; } }