_active; } /** * Begins a transaction. * @throws InvalidConfigException if [[connection]] is null */ public function begin() { if (!$this->_active) { if ($this->db === null) { throw new InvalidConfigException('Transaction::db must be set.'); } \Yii::trace('Starting transaction', __CLASS__); $this->db->open(); $this->db->createCommand('MULTI')->execute(); $this->_active = true; } } /** * Commits a transaction. * @throws Exception if the transaction or the DB connection is not active. */ public function commit() { if ($this->_active && $this->db && $this->db->isActive) { \Yii::trace('Committing transaction', __CLASS__); $this->db->createCommand('EXEC')->execute(); // TODO handle result of EXEC $this->_active = false; } else { throw new Exception('Failed to commit transaction: transaction was inactive.'); } } /** * Rolls back a transaction. * @throws Exception if the transaction or the DB connection is not active. */ public function rollback() { if ($this->_active && $this->db && $this->db->isActive) { \Yii::trace('Rolling back transaction', __CLASS__); $this->db->pdo->commit(); $this->_active = false; } else { throw new Exception('Failed to roll back transaction: transaction was inactive.'); } } }