Doctrine\ORM\EntityManager::rollback PHP Method

rollback() public method

Performs a rollback on the underlying database connection.
Deprecation: Use {@link getConnection}.rollback().
public rollback ( )
    public function rollback()
    {
        $this->conn->rollback();
    }

Usage Example

コード例 #1
1
 /**
  * @param Channel $channel
  * @param string  $entity
  *
  * @throws \Exception
  */
 protected function fillChannelToEntity(Channel $channel, $entity)
 {
     $interfaces = class_implements($entity) ?: [];
     if (!in_array('OroCRM\\Bundle\\ChannelBundle\\Model\\ChannelAwareInterface', $interfaces)) {
         return;
     }
     /** @var QueryBuilder $qb */
     $qb = $this->em->getRepository($entity)->createQueryBuilder('e');
     $iterator = new BufferedQueryResultIterator($qb);
     $writeCount = 0;
     $toWrite = [];
     try {
         $this->em->beginTransaction();
         /** @var ChannelAwareInterface $data */
         foreach ($iterator as $data) {
             $writeCount++;
             if (!$data->getDataChannel()) {
                 $channelReference = $this->em->getReference(ClassUtils::getClass($channel), $channel->getId());
                 $data->setDataChannel($channelReference);
                 $toWrite[] = $data;
             }
             if (0 === $writeCount % static::BATCH_SIZE) {
                 $this->write($toWrite);
                 $toWrite = [];
             }
         }
         if (count($toWrite) > 0) {
             $this->write($toWrite);
         }
         $this->em->commit();
     } catch (\Exception $exception) {
         $this->em->rollback();
         throw $exception;
     }
 }
All Usage Examples Of Doctrine\ORM\EntityManager::rollback