当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManager::clear方法代码示例

本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::clear方法的具体用法?PHP EntityManager::clear怎么用?PHP EntityManager::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kdyby\Doctrine\EntityManager的用法示例。


在下文中一共展示了EntityManager::clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: establishListingCopy

 /**
  * @param Listing $listing
  * @param bool $withItems
  * @param array|null $valuesForNewListing
  * @return Listing
  * @throws \Exception
  */
 public function establishListingCopy(Listing $listing, $withItems = true, array $valuesForNewListing = null)
 {
     Validators::assert($withItems, 'boolean');
     $newListing = clone $listing;
     if (isset($valuesForNewListing)) {
         $newListing->setDescription($valuesForNewListing['description']);
         $newListing->setHourlyWage($valuesForNewListing['hourlyWage']);
     }
     $this->em->persist($newListing);
     if ($withItems === true) {
         $copies = $this->getItemsCopies($listing);
         if (!empty($copies)) {
             foreach ($copies as $copy) {
                 $copy->setListing($newListing);
                 $this->em->persist($copy);
             }
         }
     }
     try {
         $this->em->flush();
         $this->em->clear();
     } catch (\Exception $e) {
         $this->onError('establishListingCopy', $e, self::class);
         throw $e;
     }
     return $newListing;
 }
开发者ID:blitzik,项目名称:vycetky-doctrine,代码行数:34,代码来源:ListingsManager.php

示例2: clearDatabase

 public function clearDatabase()
 {
     $connection = $this->em->getConnection();
     $tables = $connection->getSchemaManager()->listTableNames();
     $connection->prepare('SET FOREIGN_KEY_CHECKS = 0')->execute();
     foreach ($tables as $table) {
         if ($table !== 'db_version') {
             $connection->prepare('TRUNCATE TABLE `' . $table . '`')->execute();
         }
     }
     $connection->prepare('SET FOREIGN_KEY_CHECKS = 1')->execute();
     $this->em->clear();
 }
开发者ID:instante,项目名称:php-test-suite,代码行数:13,代码来源:DoctrineTester.php

示例3: stopTransactionWrapper

 private function stopTransactionWrapper()
 {
     if (!$this->isInitialized) {
         return;
     }
     if ($this->isImplicitFlushPrevented) {
         $wrappedConnection = $this->getWrappedPDOConnection();
         $wrappedConnection->unwrap();
     }
     /** @var IWrappedConnection|Connection $connection */
     $connection = $this->entityManager->getConnection();
     $connection->unwrap();
     $this->isInitialized = FALSE;
     $this->entityManager->clear();
 }
开发者ID:damejidlo,项目名称:modular-testcase,代码行数:15,代码来源:TransactionIsolationModule.php

示例4: prepareDatabaseTest

 public function prepareDatabaseTest()
 {
     $this->lock();
     $this->em->clear();
     $migrationConfig = $this->context->getByType(Configuration::class);
     /** @var Configuration $migrationConfig */
     $migration = new Migration($migrationConfig);
     try {
         $migration->migrate();
     } catch (MigrationException $ex) {
         if ($ex->getCode() !== 4) {
             // no migrations found; this should not break tests in early stages of development,
             // the tests will fail when they require a model anyway
             throw $ex;
         }
     }
     $this->clearDatabase();
 }
开发者ID:rhrebecek,项目名称:skeleton,代码行数:18,代码来源:DatabaseTester.php

示例5: createAndUpdate

 protected function createAndUpdate(ORMMetadata $class, EntityRepository $repository)
 {
     $paginator = new Nette\Utils\Paginator();
     $paginator->itemsPerPage = 1000;
     $countQuery = $this->buildCountForUpdateQuery($repository)->getQuery();
     $paginator->itemCount = $countQuery->getSingleScalarResult();
     $this->onIndexStart($this, $paginator, $class);
     if ($paginator->itemCount <= 0) {
         return;
     }
     $qb = $this->buildSelectForUpdateQuery($repository, $class);
     if ($identifier = $class->getSingleIdentifierColumnName()) {
         $qb->orderBy(sprintf('e.%s', $identifier), 'ASC');
     }
     $lastId = NULL;
     $selectQueryBuilder = $qb->setMaxResults($paginator->getLength());
     while (1) {
         if ($lastId !== NULL) {
             $qbCopy = clone $selectQueryBuilder;
             $query = $qbCopy->andWhere(sprintf('e.%s > :lastId', $identifier))->setParameter('lastId', $lastId)->getQuery();
         } else {
             $query = $selectQueryBuilder->getQuery();
             if (!$identifier) {
                 $query->setFirstResult($paginator->getOffset());
             }
         }
         $beginTime = microtime(TRUE);
         $entities = $query->getResult();
         $this->postFetch($entities, $repository, $class);
         $loadedTime = microtime(TRUE);
         $this->doPersistEntities($entities);
         $this->searchManager->flush();
         $this->searchManager->clear();
         try {
             $this->onItemsIndexed($this, $entities);
         } catch (\Exception $e) {
         }
         if ($identifier) {
             $lastIdentifier = $class->getIdentifierValues(end($entities));
             // [id => value]
             $lastId = reset($lastIdentifier);
             if (!is_numeric($lastId)) {
                 trigger_error(E_USER_WARNING, 'Expected numeric identifier');
             }
         }
         $this->entityManager->clear();
         $this->onIndexStats($this, $class, microtime(TRUE) - $loadedTime, $loadedTime - $beginTime);
         if ($paginator->isLast()) {
             break;
         }
         $paginator->page += 1;
     }
 }
开发者ID:rohlikcz,项目名称:DoctrineSearch,代码行数:53,代码来源:DefaultEntityRiver.php

示例6: process

 public function process(AMQPMessage $message) : int
 {
     try {
         if (!($request = Json::decode($message->body, Json::FORCE_ARRAY))) {
             return self::MSG_REJECT;
         }
     } catch (JsonException $e) {
         $this->logger->addError($e->getMessage());
         return self::MSG_REJECT;
     }
     $orderId = $request['orderId'];
     try {
         $conn = $this->em->getConnection();
         if ($conn->ping() === false) {
             $conn->close();
             $conn->connect();
         }
         /** @var Order $order */
         $orders = $this->em->getRepository(Order::class);
         if (!($order = $orders->find($orderId))) {
             $this->logger->addWarning(sprintf('Order %s not found in db', $orderId));
             return self::MSG_REJECT;
         }
         if (!$order->getUser()) {
             $this->logger->addWarning(sprintf('Order %s has no user', $orderId));
             return self::MSG_REJECT;
         }
         $this->user->passwordLessLogin($order->getUser()->getId());
         return $this->processOrder($order, $request['options']);
     } catch (\App\Exception\DatabaseDeadlockException $e) {
         return $this->restartJob($request, $e);
     } catch (\Doctrine\DBAL\Exception\DriverException $e) {
         if ($deadlock = \App\Exception\DatabaseDeadlockException::fromDriverException($e)) {
             $e = $deadlock;
             $message = null;
         } else {
             $this->logger->addError($e->getMessage(), ['exception' => $e]);
             $message = $e->getPrevious() instanceof \Doctrine\DBAL\Driver\PDOException ? $e->getPrevious()->getMessage() : $e->getMessage();
         }
         return $this->restartJob($request, $e, $message);
     } catch (\Exception $e) {
         $this->logger->addError($this->getQueue(), ['exception' => $e]);
         return $this->restartJob($request, $e);
     } finally {
         $this->user->logout(true);
         $this->em->clear();
     }
 }
开发者ID:fprochazka,项目名称:posobota-rabbitmq-workshop-01-2016,代码行数:48,代码来源:BaseSubmitOrderQueue.php

示例7: processEnd

 /**
  * 
  * @param integer $flag IConsumer constant
  * @return integer IConsumer constant
  */
 private function processEnd($flag)
 {
     $status = RmqLogConsumer::STATUS_OK;
     try {
         $this->em->clear();
     } catch (\Exception $e) {
         $status = RmqLogConsumer::STATUS_ERROR;
         // Fatal error during em->clear();
     }
     try {
         return $this->processTermination($flag, $status);
     } catch (\Exception $e) {
         // Fatal error during termination
     }
     return $flag;
 }
开发者ID:miloshavlicek,项目名称:rabbit-mq-consumer,代码行数:21,代码来源:Consumer.php


注:本文中的Kdyby\Doctrine\EntityManager::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。