當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。