protected function setUpListener()
 {
     $that = $this;
     $overrider = new OMClassOverrider(PropelExtendingTest::$map);
     EventDispatcherProxy::setDispatcherGetter(function () use($that, $overrider) {
         $c = $that->getContainer();
         $d = new ContainerAwareEventDispatcher($c);
         $d->addListener('om.detect', array($overrider, 'onDetectionRequest'));
         return $d;
     });
     return $overrider;
 }
示例#2
0
 /**
  * The class that the Peer will make instances of.
  *
  *
  * @return string ClassName
  */
 public static function getOMClass($row = 0, $colnum = 0)
 {
     $event = new DetectOMClassEvent(StorePeer::OM_CLASS, $row, $colnum);
     EventDispatcherProxy::trigger('om.detect', $event);
     if ($event->isDetected()) {
         return $event->getDetectedClass();
     }
     return StorePeer::OM_CLASS;
 }
示例#3
0
 /**
  * Code to execute after every UPDATE statement
  *
  * @param     int $affectedRows the number of updated rows
  * @param     PropelPDO $con The connection object used by the query
  */
 protected function basePostUpdate($affectedRows, PropelPDO $con)
 {
     // event behavior
     EventDispatcherProxy::trigger(array('update.post', 'query.update.post'), new QueryEvent($this));
     return $this->postUpdate($affectedRows, $con);
 }
示例#4
0
 /**
  * Persists this object to the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All modified related objects will also be persisted in the doSave()
  * method.  This method wraps all precipitate database operations in a
  * single transaction.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @throws Exception
  * @see        doSave()
  */
 public function save(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("You cannot save an object that has been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(PrincipalArchivePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     $isInsert = $this->isNew();
     try {
         $ret = $this->preSave($con);
         // event behavior
         EventDispatcherProxy::trigger('model.save.pre', new ModelEvent($this));
         if ($isInsert) {
             $ret = $ret && $this->preInsert($con);
             // event behavior
             EventDispatcherProxy::trigger('model.insert.pre', new ModelEvent($this));
         } else {
             $ret = $ret && $this->preUpdate($con);
             // event behavior
             EventDispatcherProxy::trigger(array('update.pre', 'model.update.pre'), new ModelEvent($this));
         }
         if ($ret) {
             $affectedRows = $this->doSave($con);
             if ($isInsert) {
                 $this->postInsert($con);
                 // event behavior
                 EventDispatcherProxy::trigger('model.insert.post', new ModelEvent($this));
             } else {
                 $this->postUpdate($con);
                 // event behavior
                 EventDispatcherProxy::trigger(array('update.post', 'model.update.post'), new ModelEvent($this));
             }
             $this->postSave($con);
             // event behavior
             EventDispatcherProxy::trigger('model.save.post', new ModelEvent($this));
             PrincipalArchivePeer::addInstanceToPool($this);
         } else {
             $affectedRows = 0;
         }
         $con->commit();
         return $affectedRows;
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
示例#5
0
 /**
  * Code to execute after every UPDATE statement
  *
  * @param     int $affectedRows the number of updated rows
  * @param     PropelPDO $con The connection object used by the query
  */
 protected function basePostUpdate($affectedRows, PropelPDO $con)
 {
     // event behavior
     EventDispatcherProxy::trigger(array('update.post', 'query.update.post'), new QueryEvent($this));
     // aggregate_column_relation behavior
     $this->updateRelatedVisitations($con);
     return $this->postUpdate($affectedRows, $con);
 }
 public function __construct($dsn, $username = null, $password = null, $driver_options = array())
 {
     parent::__construct($dsn, $username, $password, $driver_options);
     EventDispatcherProxy::trigger('connection.create', new PropelEvents\ConnectionEvent($this));
 }
示例#7
0
 /**
  * Persists this object to the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All modified related objects will also be persisted in the doSave()
  * method.  This method wraps all precipitate database operations in a
  * single transaction.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @throws Exception
  * @see        doSave()
  */
 public function save(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("You cannot save an object that has been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(StorePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     $isInsert = $this->isNew();
     try {
         $ret = $this->preSave($con);
         // sluggable behavior
         if ($this->isColumnModified(StorePeer::URL) && $this->getUrl()) {
             $this->setUrl($this->makeSlugUnique($this->getUrl()));
         } elseif (!$this->getUrl()) {
             $this->setUrl($this->createSlug());
         }
         // sortable behavior
         $this->processSortableQueries($con);
         // event behavior
         EventDispatcherProxy::trigger('model.save.pre', new ModelEvent($this));
         if ($isInsert) {
             $ret = $ret && $this->preInsert($con);
             // sortable behavior
             if (!$this->isColumnModified(StorePeer::RANK_COL)) {
                 $this->setSortableRank(StoreQuery::create()->getMaxRankArray($con) + 1);
             }
             // timestampable behavior
             if (!$this->isColumnModified(StorePeer::CREATED_AT)) {
                 $this->setCreatedAt(time());
             }
             if (!$this->isColumnModified(StorePeer::UPDATED_AT)) {
                 $this->setUpdatedAt(time());
             }
             // event behavior
             EventDispatcherProxy::trigger('model.insert.pre', new ModelEvent($this));
         } else {
             $ret = $ret && $this->preUpdate($con);
             // timestampable behavior
             if ($this->isModified() && !$this->isColumnModified(StorePeer::UPDATED_AT)) {
                 $this->setUpdatedAt(time());
             }
             // event behavior
             EventDispatcherProxy::trigger(array('update.pre', 'model.update.pre'), new ModelEvent($this));
         }
         if ($ret) {
             $affectedRows = $this->doSave($con);
             if ($isInsert) {
                 $this->postInsert($con);
                 // event behavior
                 EventDispatcherProxy::trigger('model.insert.post', new ModelEvent($this));
             } else {
                 $this->postUpdate($con);
                 // event behavior
                 EventDispatcherProxy::trigger(array('update.post', 'model.update.post'), new ModelEvent($this));
             }
             $this->postSave($con);
             // event behavior
             EventDispatcherProxy::trigger('model.save.post', new ModelEvent($this));
             StorePeer::addInstanceToPool($this);
         } else {
             $affectedRows = 0;
         }
         $con->commit();
         return $affectedRows;
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 public function boot()
 {
     // set callback in proxy dispatcher,
     // so it can later get real dispatcher from container
     EventDispatcherProxy::setDispatcherGetter(array($this->container, 'get'), array('glorpen.propel.event.dispatcher'));
 }
示例#9
0
 /**
  * Persists this object to the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All modified related objects will also be persisted in the doSave()
  * method.  This method wraps all precipitate database operations in a
  * single transaction.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @throws Exception
  * @see        doSave()
  */
 public function save(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("You cannot save an object that has been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(VisitationPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     $isInsert = $this->isNew();
     try {
         $ret = $this->preSave($con);
         // event behavior
         EventDispatcherProxy::trigger('model.save.pre', new ModelEvent($this));
         if ($isInsert) {
             $ret = $ret && $this->preInsert($con);
             // timestampable behavior
             if (!$this->isColumnModified(VisitationPeer::CREATED_AT)) {
                 $this->setCreatedAt(time());
             }
             if (!$this->isColumnModified(VisitationPeer::UPDATED_AT)) {
                 $this->setUpdatedAt(time());
             }
             // event behavior
             EventDispatcherProxy::trigger('model.insert.pre', new ModelEvent($this));
         } else {
             $ret = $ret && $this->preUpdate($con);
             // timestampable behavior
             if ($this->isModified() && !$this->isColumnModified(VisitationPeer::UPDATED_AT)) {
                 $this->setUpdatedAt(time());
             }
             // event behavior
             EventDispatcherProxy::trigger(array('update.pre', 'model.update.pre'), new ModelEvent($this));
         }
         if ($ret) {
             $affectedRows = $this->doSave($con);
             if ($isInsert) {
                 $this->postInsert($con);
                 // event behavior
                 EventDispatcherProxy::trigger('model.insert.post', new ModelEvent($this));
             } else {
                 $this->postUpdate($con);
                 // event behavior
                 EventDispatcherProxy::trigger(array('update.post', 'model.update.post'), new ModelEvent($this));
             }
             $this->postSave($con);
             // aggregate_column behavior
             if (null !== $this->collTransactions) {
                 $this->setTotal($this->computeTotal($con));
                 if ($this->isModified()) {
                     $this->save($con);
                 }
             }
             // event behavior
             EventDispatcherProxy::trigger('model.save.post', new ModelEvent($this));
             VisitationPeer::addInstanceToPool($this);
         } else {
             $affectedRows = 0;
         }
         $con->commit();
         return $affectedRows;
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 public function testPreEventWithSoftDeleteBehavior()
 {
     $that = $this;
     $order = array();
     EventDispatcherProxy::setDispatcherGetter(function () use($that, &$order) {
         $c = $that->getContainer();
         $d = new ContainerAwareEventDispatcher($c);
         $d->addListener('model.delete.pre', function ($e) use($that, &$order) {
             $order[] = 'model.delete.pre';
         });
         $d->addListener('delete.pre', function ($e) use($that, &$order) {
             $order[] = 'delete.pre';
         });
         $d->addListener('query.delete.pre', function ($e) use($that, &$order) {
             $order[] = 'query.delete.pre';
         });
         return $d;
     });
     $m = new SoftdeleteTable();
     $m->save();
     $m->delete();
     $that->assertContains('model.delete.pre', $order, 'Delete model event');
     $that->assertContains('delete.pre', $order, 'Model global delete event');
     $order = array();
     BaseSoftdeleteTableQuery::create()->filterById(1)->delete();
     $that->assertContains('delete.pre', $order, 'Query global delete event');
     $that->assertContains('query.delete.pre', $order, 'Query delete event');
 }