Class Phalcon\Mvc\Model\Transaction\Manager

implements Phalcon\Mvc\Model\Transaction\ManagerInterface, Phalcon\Di\InjectionAwareInterface

A transaction acts on a single database connection. If you have multiple class-specific databases, the transaction will not protect interaction among them. This class manages the objects that compose a transaction. A trasaction produces a unique connection that is passed to every object part of the transaction.

  1. <?php
  2. try {
  3. use Phalcon\Mvc\Model\Transaction\Manager as TransactionManager;
  4. $transactionManager = new TransactionManager();
  5. $transaction = $transactionManager->get();
  6. $robot = new Robots();
  7. $robot->setTransaction($transaction);
  8. $robot->name = 'WALL·E';
  9. $robot->created_at = date('Y-m-d');
  10. if($robot->save()==false){
  11. $transaction->rollback("Can't save robot");
  12. }
  13. $robotPart = new RobotParts();
  14. $robotPart->setTransaction($transaction);
  15. $robotPart->type = 'head';
  16. if($robotPart->save()==false){
  17. $transaction->rollback("Can't save robot part");
  18. }
  19. $transaction->commit();
  20. } catch (Phalcon\Mvc\Model\Transaction\Failed $e) {
  21. echo 'Failed, reason: ', $e->getMessage();
  22. }

Methods

public __construct ([unknown $dependencyInjector])

Phalcon\Mvc\Model\Transaction\Manager constructor

public setDI (unknown $dependencyInjector)

Sets the dependency injection container

public Phalcon\DiInterface getDI ()

Returns the dependency injection container

public Phalcon\Mvc\Model\Transaction\Manager setDbService (unknown $service)

Sets the database service used to run the isolated transactions

public string getDbService ()

Returns the database service used to isolate the transaction

public Phalcon\Mvc\Model\Transaction\Manager setRollbackPendent (unknown $rollbackPendent)

Set if the transaction manager must register a shutdown function to clean up pendent transactions

public boolean getRollbackPendent ()

Check if the transaction manager is registering a shutdown function to clean up pendent transactions

public boolean has ()

Checks whether the manager has an active transaction

public Phalcon\Mvc\Model\TransactionInterface get ([unknown $autoBegin])

Returns a new \Phalcon\Mvc\Model\Transaction or an already created once This method registers a shutdown function to rollback active connections

public Phalcon\Mvc\Model\TransactionInterface getOrCreateTransaction ([unknown $autoBegin])

Create/Returns a new transaction or an existing one

public rollbackPendent ()

Rollbacks active transactions within the manager

public commit ()

Commmits active transactions within the manager

public rollback ([unknown $collect])

Rollbacks active transactions within the manager Collect will remove the transaction from the manager

public notifyRollback (unknown $transaction)

Notifies the manager about a rollbacked transaction

public notifyCommit (unknown $transaction)

Notifies the manager about a commited transaction

protected _collectTransaction (unknown $transaction)

Removes transactions from the TransactionManager

public collectTransactions ()

Remove all the transactions from the manager