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


PHP EntityManager::commit方法代码示例

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


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

示例1: groupMembershipAction

 public function groupMembershipAction()
 {
     /** @var AccountInterface $account */
     $account = $this->entityManager->getRepository(AccountInterface::class)->find($this->bodyParam('account'));
     if (!$account) {
         return new ApiProblem(404, 'The account could not be found.');
     }
     /** @var Group $group */
     $group = $this->entityManager->getRepository(Group::class)->find($this->bodyParam('group'));
     if (!$group) {
         return new ApiProblem(404, 'The group could not be found.');
     }
     if ($this->getRequest()->getMethod() === 'POST' && !$account->getGroups()->contains($group)) {
         $account->getGroups()->add($group);
     } elseif ($this->getRequest()->getMethod() === 'DELETE' && $account->getGroups()->contains($group)) {
         $account->getGroups()->removeElement($group);
     }
     try {
         $this->entityManager->beginTransaction();
         $this->entityManager->persist($account);
         $this->entityManager->flush();
         $this->entityManager->commit();
     } catch (Exception $e) {
         $this->entityManager->rollback();
         return new ApiProblemResponse(new ApiProblem(500, $e->getMessage(), null, null, ['exception' => $e]));
     }
     return new ViewModel(['group' => $group->getId(), 'account' => $account->getId()]);
 }
开发者ID:zource,项目名称:zource,代码行数:28,代码来源:GroupMembershipController.php

示例2: fillChannelToEntity

 /**
  * @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;
     }
 }
开发者ID:dairdr,项目名称:crm,代码行数:41,代码来源:AbstractDefaultChannelDataFixture.php

示例3: persist

 /**
  * Persists data into DB in single transaction
  *
  * @param string $locale
  * @param array  $data translations strings, format same as MassageCatalog::all() returns
  *
  * @throws \Exception
  */
 public function persist($locale, array $data)
 {
     $writeCount = 0;
     try {
         $this->em->beginTransaction();
         foreach ($data as $domain => $domainData) {
             foreach ($domainData as $key => $translation) {
                 if (strlen($key) > MySqlPlatform::LENGTH_LIMIT_TINYTEXT) {
                     continue;
                 }
                 $writeCount++;
                 $this->toWrite[] = $this->getTranslationObject($key, $locale, $domain, $translation);
                 if (0 === $writeCount % $this->batchSize) {
                     $this->write($this->toWrite);
                     $this->toWrite = [];
                 }
             }
         }
         if (count($this->toWrite) > 0) {
             $this->write($this->toWrite);
         }
         $this->em->commit();
     } catch (\Exception $exception) {
         $this->em->rollback();
         throw $exception;
     }
     // update timestamp in case when persist succeed
     $this->metadataCache->updateTimestamp($locale);
 }
开发者ID:Maksold,项目名称:platform,代码行数:37,代码来源:DatabasePersister.php

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->em = $this->container->getDoctrine()->getManager();
     /* @var $em EntityManager */
     $this->em->beginTransaction();
     $entities = array('CmsAuthentication:User', 'CmsAuthentication:Group', 'Cms:ApplicationLocalizationParameter', 'Cms:BlockPropertyMetadata', 'Cms:ReferencedElement\\ReferencedElementAbstract', 'Cms:BlockProperty', 'Cms:Abstraction\\Block', 'Cms:Abstraction\\PlaceHolder', 'Cms:LocalizationTag', 'Cms:Abstraction\\Localization', 'Cms:Abstraction\\RedirectTarget', 'Cms:PageLocalizationPath', 'Cms:Page', 'Cms:EditLock', 'Cms:TemplateLayout', 'Cms:Template', 'Cms:FileProperty', 'Cms:ImageSize', 'Cms:Image', 'Cms:File', 'Cms:Folder', 'Cms:FilePath');
     if ($input->getOption('clear')) {
         foreach ($entities as $entity) {
             //todo: also clean audit tables here
             $this->em->createQueryBuilder()->delete($entity)->getQuery()->execute();
         }
     }
     $dataFile = $this->container->getParameter('directories.project_root') . DIRECTORY_SEPARATOR . $input->getArgument('filename');
     if (!is_file($dataFile)) {
         throw new \RuntimeException(sprintf('The file [%s] does not exists.', $dataFile));
     }
     $this->dataDir = dirname($dataFile);
     //todo: validate it
     $data = Yaml::parse(file_get_contents($dataFile));
     //we need to maintain creation order
     $sections = array('group', 'user', 'image', 'template', 'page', 'pageLocalization');
     foreach ($sections as $section) {
         foreach ($data[$section] as $name => $definition) {
             $this->createEntity($section, $name, $definition);
         }
     }
     $this->em->flush();
     $this->em->commit();
 }
开发者ID:sitesupra,项目名称:sitesupra,代码行数:29,代码来源:LoadFixturesCommand.php

示例5: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Migrating translations...');
     $this->setEntityManager($this->getContainer()->get('doctrine.orm.entity_manager'));
     /* @var EntityRepository $repo */
     $repo = $this->em->getRepository('KunstmaanTranslatorBundle:Translation');
     /**
      * @var QueryBuilder $qb
      */
     $qb = $repo->createQueryBuilder('t');
     $uniqueTranslations = $qb->select('t.domain,t.keyword')->distinct()->where('t.translationId IS NULL')->getQuery()->getArrayResult();
     $this->em->beginTransaction();
     try {
         foreach ($uniqueTranslations as $uniqueTranslation) {
             // Fetch new unique translation ID & update records
             $newId = $repo->getUniqueTranslationId();
             // Update translations...
             $qb->update()->set('t.translationId', $newId)->where('t.domain = :domain')->andWhere('t.keyword = :keyword')->setParameter('domain', $uniqueTranslation['domain'])->setParameter('keyword', $uniqueTranslation['keyword'])->getQuery()->execute();
         }
         $this->em->commit();
         $output->writeln('<info>' . count($uniqueTranslations) . ' translations have been migrated.</info>');
     } catch (\Exception $e) {
         $this->em->rollback();
         $output->writeln('An error occured while migrating translations : <error>' . $e->getMessage() . '</error>');
     }
 }
开发者ID:rifer,项目名称:KunstmaanBundlesCMS,代码行数:26,代码来源:MigrateTranslationsCommand.php

示例6: stopLogEntry

 public function stopLogEntry(User $user, LogEntry $logEntry)
 {
     $this->em->beginTransaction();
     $this->stopActiveLogEntriesByUser($user);
     $this->logEntryRepository->save($logEntry);
     $this->em->flush();
     $this->em->commit();
 }
开发者ID:klinki,项目名称:timer,代码行数:8,代码来源:LogEntryService.php

示例7: updateReferencesInTransaction

 private function updateReferencesInTransaction()
 {
     $this->entityManager->beginTransaction();
     $this->retrieveCurrentReferencesIds();
     $this->updateBannersProbabilities();
     $this->removeUnusedReferences();
     $this->entityManager->commit();
 }
开发者ID:ragtek,项目名称:AcidAdServer,代码行数:8,代码来源:ReferencesUpdater.php

示例8: setTaskAsDefault

 /**
  * Sets task as users default task
  *
  * @param Task $task
  * @param User $user
  */
 public function setTaskAsDefault(Task $task, User $user)
 {
     $this->em->beginTransaction();
     $defaultTask = $this->taskRepository->findUserDefaultTask($user->getId());
     $defaultTask->setDefault(false);
     $task->setDefault(true);
     $this->taskRepository->update($task);
     $this->em->flush();
     $this->em->commit();
 }
开发者ID:klinki,项目名称:timer,代码行数:16,代码来源:TaskService.php

示例9: executeJob

 /**
  * @param string $jobType
  * @param string $jobName
  * @param array $configuration
  * @return JobResult
  */
 public function executeJob($jobType, $jobName, array $configuration = array())
 {
     // create and persist job instance and job execution
     $jobInstance = new JobInstance(self::CONNECTOR_NAME, $jobType, $jobName);
     $jobInstance->setCode($this->generateJobCode($jobName));
     $jobInstance->setLabel(sprintf('%s.%s', $jobType, $jobName));
     $jobInstance->setRawConfiguration($configuration);
     $jobExecution = new JobExecution();
     $jobExecution->setJobInstance($jobInstance);
     $jobResult = new JobResult();
     $jobResult->setSuccessful(false);
     $this->entityManager->beginTransaction();
     try {
         $job = $this->jobRegistry->getJob($jobInstance);
         if (!$job) {
             throw new RuntimeException(sprintf('Can\'t find job "%s"', $jobName));
         }
         // TODO: Refactor whole logic of job execution to perform actions in transactions
         $job->execute($jobExecution);
         $failureExceptions = $this->collectFailureExceptions($jobExecution);
         if ($jobExecution->getStatus()->getValue() == BatchStatus::COMPLETED && !$failureExceptions) {
             $this->entityManager->commit();
             $jobResult->setSuccessful(true);
         } else {
             $this->entityManager->rollback();
             foreach ($failureExceptions as $failureException) {
                 $jobResult->addFailureException($failureException);
             }
         }
     } catch (\Exception $exception) {
         $this->entityManager->rollback();
         $jobExecution->addFailureException($exception);
         $jobResult->addFailureException($exception->getMessage());
     }
     // save job instance
     $this->entityManager->persist($jobInstance);
     $this->entityManager->flush($jobInstance);
     // set data to JobResult
     $jobResult->setJobId($jobInstance->getId());
     $jobResult->setJobCode($jobInstance->getCode());
     /** @var JobExecution $jobExecution */
     $jobExecution = $jobInstance->getJobExecutions()->first();
     if ($jobExecution) {
         $stepExecution = $jobExecution->getStepExecutions()->first();
         if ($stepExecution) {
             $context = $this->contextRegistry->getByStepExecution($stepExecution);
             $jobResult->setContext($context);
         }
     }
     return $jobResult;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:57,代码来源:JobExecutor.php

示例10: testReset

 public function testReset()
 {
     $randomConfigElement = new Config();
     $randomConfigElement->setValue("AnValueWhichNotExists");
     $randomConfigElement->setName("ThisNameIsUsedForTesting!");
     $this->em->persist($randomConfigElement);
     $this->em->commit();
     //        $this->em->beginTransaction();
     //        $this->repo->resetConfiguration();
     //        $q=$this->repo->createQueryBuilder('c')->where("c.name = ?1")->setParameter(1,$randomConfigElement->getName())->getQuery();
     //        $q->useResultCache(false);
     //        $r = $q->getArrayResult();
     //        $this->assertEmpty($r);
 }
开发者ID:PhilippeGeek,项目名称:adhesion,代码行数:14,代码来源:ConfigRepositoryTest.php

示例11: run

 /**
  * Runs all sample data providers.
  *
  * @param callable|null $callback A function that will be called with the name of each provider as a parameter.
  * @return void
  */
 public function run(callable $callback = null)
 {
     $this->em->beginTransaction();
     foreach ($this->providers as $provider) {
         $this->em->clear();
         /** @var $provider \Brick\Sample\SampleDataProvider */
         $provider = $this->injector->instantiate($provider);
         if ($callback) {
             $callback($provider->getName());
         }
         $provider->run();
         $this->em->flush();
     }
     $this->em->commit();
 }
开发者ID:brick,项目名称:brick,代码行数:21,代码来源:SampleDataDispatcher.php

示例12: insertUpdateProcessing

 public function insertUpdateProcessing(EntityManager $em, $data, $id = null)
 {
     $update = !is_null($id);
     try {
         $em->beginTransaction();
         if ($update) {
             $language = $em->find('Model\\Language', $id);
         } else {
             $language = new Language();
         }
         $language->setCode($data['code']);
         $language->setDescription($data['description']);
         $language->setFlagImageURL($data['flagimageurl']);
         $menu = $em->find('Model\\Menu', $data['menuid']);
         $language->setMenu($menu);
         if ($update) {
             $em->merge($language);
         } else {
             $em->persist($language);
         }
         $em->flush();
         $em->commit();
     } catch (\Exception $e) {
         $em->rollback();
         throw $e;
     }
     return $language->getId();
 }
开发者ID:francescocambi,项目名称:FCMS2,代码行数:28,代码来源:EditorController.php

示例13: end

 /**
  * End system, included in benchmark.
  */
 public function end()
 {
     if ($this->requiresFlush) {
         $this->em->flush();
     }
     $this->em->commit();
 }
开发者ID:pkdevbox,项目名称:orm-benchmarking-suite,代码行数:10,代码来源:OrmSystem.php

示例14: doJob

 /**
  * @param JobExecution $jobExecution
  * @param JobInstance $jobInstance
  * @return JobResult
  */
 protected function doJob(JobInstance $jobInstance, JobExecution $jobExecution)
 {
     $jobResult = new JobResult();
     $jobResult->setSuccessful(false);
     $isTransactionRunning = $this->isTransactionRunning();
     if (!$isTransactionRunning) {
         $this->entityManager->beginTransaction();
     }
     try {
         $job = $this->batchJobRegistry->getJob($jobInstance);
         if (!$job) {
             throw new RuntimeException(sprintf('Can\'t find job "%s"', $jobInstance->getAlias()));
         }
         $job->execute($jobExecution);
         $isSuccessful = $this->handleJobResult($jobExecution, $jobResult);
         if (!$isTransactionRunning && $isSuccessful && !$this->validationMode) {
             $this->entityManager->commit();
         } elseif (!$isTransactionRunning) {
             $this->entityManager->rollback();
         }
         // trigger save of JobExecution and JobInstance
         $this->batchJobRepository->getJobManager()->flush();
         if (!$this->isClearSkipped($jobExecution)) {
             $this->batchJobRepository->getJobManager()->clear();
         }
     } catch (\Exception $exception) {
         if (!$isTransactionRunning) {
             $this->entityManager->rollback();
         }
         $jobExecution->addFailureException($exception);
         $jobResult->addFailureException($exception->getMessage());
         $this->saveFailedJobExecution($jobExecution);
     }
     return $jobResult;
 }
开发者ID:antrampa,项目名称:platform,代码行数:40,代码来源:JobExecutor.php

示例15: doJob

 /**
  * @param JobExecution $jobExecution
  * @param JobInstance $jobInstance
  * @return JobResult
  */
 protected function doJob(JobInstance $jobInstance, JobExecution $jobExecution)
 {
     $jobResult = new JobResult();
     $jobResult->setSuccessful(false);
     $this->entityManager->beginTransaction();
     try {
         $job = $this->batchJobRegistry->getJob($jobInstance);
         if (!$job) {
             throw new RuntimeException(sprintf('Can\'t find job "%s"', $jobInstance->getAlias()));
         }
         $job->execute($jobExecution);
         $failureExceptions = $this->collectFailureExceptions($jobExecution);
         if ($jobExecution->getStatus()->getValue() == BatchStatus::COMPLETED && !$failureExceptions) {
             $this->entityManager->commit();
             $jobResult->setSuccessful(true);
         } else {
             $this->entityManager->rollback();
             foreach ($failureExceptions as $failureException) {
                 $jobResult->addFailureException($failureException);
             }
         }
     } catch (\Exception $exception) {
         $this->entityManager->rollback();
         $jobExecution->addFailureException($exception);
         $jobResult->addFailureException($exception->getMessage());
     }
     return $jobResult;
 }
开发者ID:xamin123,项目名称:platform,代码行数:33,代码来源:JobExecutor.php


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