close() public method

Closes the EntityManager. All entities that are currently managed by this EntityManager become detached. The EntityManager may no longer be used after it is closed.
public close ( )
Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     if ($this->em instanceof \Doctrine\ORM\EntityManager) {
         $this->em->close();
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     if (!is_null($this->em)) {
         $this->em->close();
     }
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     $this->em->close();
     $this->em = null;
     // avoid memory leaks
 }
Ejemplo n.º 4
0
 public function allBooks()
 {
     try {
         $book = $this->em->getRepository('BooksApiBookBundle:BooksEntity')->findAll();
     } catch (\Exception $ex) {
         $this->em->close();
         throw new QueryException('003', 502);
     }
     return $book;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     $this->em->close();
     //cerrar emMod
     /*$this->emMod = static::$kernel->getContainer()
           ->get('doctrine')
           ->getManager();
       $this->emMod->close();*/
 }
Ejemplo n.º 6
0
 /**
  * @after
  */
 protected function tearDownDoctrine()
 {
     $this->doctrine = null;
     if ($this->em) {
         $this->em->close();
         $this->em = null;
     }
     $this->loader = null;
     $this->container = null;
 }
Ejemplo n.º 7
0
 /**
  * close Doctrine Dbal and ORM connection and reset everything to default.
  */
 public function close()
 {
     $this->Conn->close();
     if (is_object($this->EntityManager) && method_exists($this->EntityManager, 'close')) {
         $this->EntityManager->close();
     }
     if (function_exists('gc_collect_cycles')) {
         gc_collect_cycles();
     }
     $this->Conn = '';
     $this->EntityManager = '';
     $this->table_prefix = '';
     $this->table_siteid_prefix = '';
 }
Ejemplo n.º 8
0
 /**
  * @param $title
  * @param $price
  * @param $description
  * @throws QueryException
  */
 public function createBook($title, $price, $description)
 {
     $book = new BooksEntity();
     $book->setTitle($title);
     $book->setPrice($price);
     $book->setDescription($description);
     try {
         $this->em->persist($book);
         $this->em->flush();
         return true;
     } catch (\Exception $ex) {
         $this->em->close();
         throw new QueryException('003', 502);
     }
 }
Ejemplo n.º 9
0
 public function restartDoctrine()
 {
     $enabled_filters = array();
     if (isset($this->entity_manager)) {
         $filters = $this->entity_manager->getFilters();
         foreach ($filters->getEnabledFilters() as $filter_name => $filter) {
             $filter_class = get_class($filter);
             $enabled_filters[$filter_name] = array($filter_class => $filter->__toString());
         }
         @$this->entity_manager->close();
         unset($this->entity_manager);
     }
     $em = $this->getDoctrine();
     foreach ($enabled_filters as $filter_name => $filter) {
         foreach ($filter as $filter_class => $filter_params_string) {
             $em->getConfiguration()->addFilter($filter_name, $filter_class);
             $this_filter = $em->getFilters()->enable($filter_name);
             $filter_params = @unserialize($filter_params_string);
             if ($filter_params) {
                 foreach ($filter_params as $filter_param => $filter_value) {
                     if (isset($filter_value['value'])) {
                         $this_filter->setParameter($filter_param, $filter_value['value']);
                     }
                 }
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     $this->em->remove($this->user);
     $this->em->close();
     //unset($this->user); //
 }
Ejemplo n.º 11
0
 /**
  * @param \Venne\Module\IModule $module
  */
 public function uninstall(IModule $module)
 {
     if (!$this->context->hasService('doctrine') || !$this->context->doctrine->createCheckConnection()) {
         throw new \Exception('Database connection not found!');
     }
     $classes = $this->getClasses($module);
     $metadata = array();
     foreach ($classes as $class) {
         $metadata[] = $this->entityManager->getClassMetadata($class);
     }
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager);
     $this->entityManager->getConnection()->beginTransaction();
     try {
         foreach ($classes as $class) {
             $repository = $this->entityManager->getRepository($class);
             foreach ($repository->findAll() as $entity) {
                 $repository->delete($entity);
             }
         }
         $tool->dropSchema($metadata);
         $this->entityManager->getConnection()->commit();
     } catch (Exception $e) {
         $this->entityManager->getConnection()->rollback();
         $this->entityManager->close();
         throw $e;
     }
     $this->cleanCache();
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function close()
 {
     $evm = $this->getEventManager();
     if ($evm->hasListeners(Events::preClose)) {
         $evm->dispatchEvent(Events::preClose, new PreCloseEventArgs($this));
     }
     parent::close();
 }
Ejemplo n.º 13
0
 /**
  * {@inheritDoc}
  * 
  * @see PHPUnit_Framework_TestCase::tearDownAfterClass()
  * 
  * @uses KernelTestCase::ensureKernelShutdown()
  */
 public static function tearDownAfterClass()
 {
     parent::ensureKernelShutdown();
     static::$em->close();
     static::$em = null;
     // avoid memory leaks
     static::$repository->clear();
     static::$repository = null;
 }
Ejemplo n.º 14
0
 /**
  * Drop the entity manager
  * @return void
  */
 public function dropEntityManager()
 {
     if ($this->entityManager != null) {
         $this->entityManager->getConnection()->close();
         $this->entityManager->close();
     }
     unset($this->entityManager);
     unset($this->fixtureReferenceRepo);
 }
Ejemplo n.º 15
0
 /**
  * вывести деньги
  *
  * @ApiDoc(
  *     section="Billing API",
  *     input="Vifeed\PaymentBundle\Form\WithdrawalType",
  *     output={
  *          "class"="Vifeed\PaymentBundle\Entity\Withdrawal",
  *          "groups"={"default"}
  *     },
  *     resource=true,
  *     statusCodes={
  *         201="Returned when successful",
  *         400="Returned when something is wrong",
  *         403="Returned when the user is not authorized to use this method"
  *     }
  * )
  *
  * @return Response
  */
 public function putWithdrawalAction()
 {
     $form = $this->createForm(new WithdrawalType());
     $form->submit($this->get('request'));
     if ($form->isValid()) {
         /** @var Withdrawal $withdrawal */
         $withdrawal = $form->getData();
         if ($withdrawal->getWallet()->getUser() != $this->getUser()) {
             throw new AccessDeniedHttpException('Можно вывести только на свой кошелёк');
         }
         if ($withdrawal->getAmount() > $this->getUser()->getBalance()) {
             $form->get('amount')->addError(new FormError('Недостаточно денег на балансе'));
         } else {
             $userRepo = $this->em->getRepository('VifeedUserBundle:User');
             $this->em->beginTransaction();
             $this->em->lock($this->getUser(), LockMode::PESSIMISTIC_WRITE);
             try {
                 $withdrawal->setUser($this->getUser())->setStatus(Withdrawal::STATUS_CREATED);
                 $this->em->persist($withdrawal);
                 $userRepo->updateBalance($this->getUser(), -$withdrawal->getAmount());
                 $this->em->flush();
                 $this->em->commit();
             } catch (\Exception $e) {
                 $this->em->rollback();
                 $this->em->close();
                 throw $e;
             }
             $mailer = $this->get('vifeed.mailer');
             $message = $mailer->renderMessage('VifeedPaymentBundle:Email:withdrawal.html.twig', ['withdrawal' => $withdrawal]);
             $mailer->sendMessage('Запрос на вывод средств', $message, $this->container->getParameter('withdrawal.notification.email'));
             $context = new SerializationContext();
             $context->setGroups(array('default'));
             $view = new View($withdrawal, 201);
             $view->setSerializationContext($context);
         }
     }
     if (!$form->isValid()) {
         $view = new View($form, 400);
     }
     return $this->handleView($view);
 }
 /**
  * {@inheritdoc}
  */
 public function close()
 {
     return $this->wrapped->close();
 }
 /**
  * {@inheritDoc}
  */
 public static function tearDownAfterClass()
 {
     self::$em->close();
     parent::tearDownAfterClass();
 }
Ejemplo n.º 18
0
 /**
  * @inheritdoc
  */
 public function stop()
 {
     parent::stop();
     $this->entityManager->flush();
     $this->entityManager->close();
 }
 /**
  * Cleans up the environment after running a test.
  */
 protected function tearDown()
 {
     parent::tearDown();
     $this->em->close();
     $this->registryRepository = null;
 }
Ejemplo n.º 20
0
 protected function tearDown()
 {
     $this->em->close();
     unset($this->client, $this->em);
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     $this->em->close();
     unset($this->em, $this->container, $this->client, $this->encoder);
 }
Ejemplo n.º 22
0
 /**
  * tear down
  */
 public function tearDown()
 {
     parent::tearDown();
     $this->em->close();
 }
 public function onDestroy(Event $event)
 {
     if ($this->_entityManager) {
         $this->_entityManager->close();
     }
 }
Ejemplo n.º 24
0
 public static function tearDownAfterClass()
 {
     self::$tool->dropSchema(self::$userClasses);
     self::$em->close();
 }
Ejemplo n.º 25
0
 /**
  * {@inheritDoc}
  *
  * @static 
  */
 public static function close()
 {
     return \Doctrine\ORM\EntityManager::close();
 }
Ejemplo n.º 26
0
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     $this->em->rollback();
     parent::tearDown();
     $this->em->close();
 }
Ejemplo n.º 27
0
 /**
  * Commits the UnitOfWork, executing all operations that have been postponed
  * up to this point. The state of all managed entities will be synchronized with
  * the database.
  *
  * The operations are executed in the following order:
  *
  * 1) All entity insertions
  * 2) All entity updates
  * 3) All collection deletions
  * 4) All collection updates
  * 5) All entity deletions
  *
  * @param null|object|array $entity
  *
  * @return void
  *
  * @throws \Exception
  */
 public function commit($entity = null)
 {
     // Raise preFlush
     if ($this->evm->hasListeners(Events::preFlush)) {
         $this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em));
     }
     // Compute changes done since last commit.
     if ($entity === null) {
         $this->computeChangeSets();
     } elseif (is_object($entity)) {
         $this->computeSingleEntityChangeSet($entity);
     } elseif (is_array($entity)) {
         foreach ($entity as $object) {
             $this->computeSingleEntityChangeSet($object);
         }
     }
     if (!($this->entityInsertions || $this->entityDeletions || $this->entityUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals)) {
         $this->dispatchOnFlushEvent();
         $this->dispatchPostFlushEvent();
         return;
         // Nothing to do.
     }
     if ($this->orphanRemovals) {
         foreach ($this->orphanRemovals as $orphan) {
             $this->remove($orphan);
         }
     }
     $this->dispatchOnFlushEvent();
     // Now we need a commit order to maintain referential integrity
     $commitOrder = $this->getCommitOrder();
     $conn = $this->em->getConnection();
     $conn->beginTransaction();
     try {
         if ($this->entityInsertions) {
             foreach ($commitOrder as $class) {
                 $this->executeInserts($class);
             }
         }
         if ($this->entityUpdates) {
             foreach ($commitOrder as $class) {
                 $this->executeUpdates($class);
             }
         }
         // Extra updates that were requested by persisters.
         if ($this->extraUpdates) {
             $this->executeExtraUpdates();
         }
         // Collection deletions (deletions of complete collections)
         foreach ($this->collectionDeletions as $collectionToDelete) {
             $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete);
         }
         // Collection updates (deleteRows, updateRows, insertRows)
         foreach ($this->collectionUpdates as $collectionToUpdate) {
             $this->getCollectionPersister($collectionToUpdate->getMapping())->update($collectionToUpdate);
         }
         // Entity deletions come last and need to be in reverse commit order
         if ($this->entityDeletions) {
             for ($count = count($commitOrder), $i = $count - 1; $i >= 0 && $this->entityDeletions; --$i) {
                 $this->executeDeletions($commitOrder[$i]);
             }
         }
         $conn->commit();
     } catch (Exception $e) {
         $this->em->close();
         $conn->rollback();
         $this->afterTransactionRolledBack();
         throw $e;
     }
     $this->afterTransactionComplete();
     // Take new snapshots from visited collections
     foreach ($this->visitedCollections as $coll) {
         $coll->takeSnapshot();
     }
     $this->dispatchPostFlushEvent();
     // Clear up
     $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = $this->extraUpdates = $this->entityChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForDirtyCheck = $this->orphanRemovals = array();
 }
Ejemplo n.º 28
0
 public function close()
 {
     if ($this->panel) {
         $this->panel->snapshotUnitOfWork($this);
     }
     parent::close();
 }
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     $this->em->close();
 }
Ejemplo n.º 30
0
 /**
  * Destroy
  */
 public function tearDown()
 {
     $tool = new SchemaTool($this->entityManager);
     $this->dropSchema($tool);
     $this->entityManager->close();
 }