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


PHP UnitOfWork::recomputeSingleEntityChangeSet方法代码示例

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


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

示例1: onFlush

 public function onFlush(OnFlushEventArgs $e)
 {
     $this->init($e);
     foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof RoundedEntityInterface) {
             $entity->setRound($this->round);
             $this->uow->recomputeSingleEntityChangeSet($this->em->getClassMetadata(get_class($entity)), $entity);
         }
     }
     //$this->uow->computeChangeSets();
 }
开发者ID:RinWorld,项目名称:Ponzi-1,代码行数:11,代码来源:RoundListener.php

示例2: computeChangeSet

 /**
  * Computes or re-computes changes of given entity.
  *
  * @param $entity
  *
  * @author Andreas Glaser
  */
 protected function computeChangeSet($entity)
 {
     if ($this->unitOfWork->getEntityChangeSet($entity)) {
         $this->unitOfWork->recomputeSingleEntityChangeSet($this->entityManager->getClassMetadata(get_class($entity)), $entity);
     } else {
         $this->unitOfWork->computeChangeSet($this->entityManager->getClassMetadata(get_class($entity)), $entity);
     }
 }
开发者ID:andreas-glaser,项目名称:dc-event-bundle,代码行数:15,代码来源:DCEventListener.php

示例3: testOnFlush

 /**
  * @param $changeset The changeset for the entity
  * @param $expectedFields List of filds which should be updated/set
  *
  * @dataProvider provideLifecycle
  */
 public function testOnFlush($changeset, $expectedFields)
 {
     $entity = $this->userBlameObject->reveal();
     $this->unitOfWork->getScheduledEntityInsertions()->willReturn([$entity]);
     $this->unitOfWork->getScheduledEntityUpdates()->willReturn([]);
     $this->entityManager->getClassMetadata(get_class($entity))->willReturn($this->classMetadata);
     $this->unitOfWork->getEntityChangeSet($this->userBlameObject->reveal())->willReturn($changeset);
     foreach (['creator', 'changer'] as $field) {
         $prophecy = $this->classMetadata->setFieldValue($this->userBlameObject->reveal(), $field, $this->user->reveal());
         if (in_array($field, $expectedFields)) {
             $prophecy->shouldBeCalled();
             continue;
         }
         $prophecy->shouldNotBeCalled();
     }
     if (count($expectedFields)) {
         $this->unitOfWork->recomputeSingleEntityChangeSet($this->classMetadata->reveal(), $this->userBlameObject->reveal())->shouldBeCalled();
     }
     $this->subscriber->onFlush($this->onFlushEvent->reveal());
 }
开发者ID:Silwereth,项目名称:sulu,代码行数:26,代码来源:UserBlameSubscriberTest.php

示例4: processEntities

 /**
  * @param array $entities
  * @param EntityManagerInterface $entityManager
  */
 private function processEntities($entities, EntityManagerInterface $entityManager, UnitOfWork $unitOfWork)
 {
     foreach ($entities as $customer) {
         if (!$customer instanceof CustomerInterface) {
             continue;
         }
         $user = $customer->getUser();
         if (null === $user) {
             continue;
         }
         if ($customer->getEmail() === $user->getUsername() && $customer->getEmailCanonical() === $user->getUsernameCanonical()) {
             continue;
         }
         $user->setUsername($customer->getEmail());
         $user->setUsernameCanonical($customer->getEmailCanonical());
         /** @var ClassMetadata $userMetadata */
         $userMetadata = $entityManager->getClassMetadata(get_class($user));
         $unitOfWork->recomputeSingleEntityChangeSet($userMetadata, $user);
     }
 }
开发者ID:okwinza,项目名称:Sylius,代码行数:24,代码来源:DefaultUsernameORMListener.php

示例5: buildUrl

 /**
  * Builds the page's url by get all page parents slugs and implode them with "/".
  * Builds the pages children urls with new page slug
  * If page has a custom url, we don't modify it, but we modify children urls
  * @param WebViewInterface $view
  * @param integer $depth
  *
  * @return void
  */
 public function buildUrl(WebViewInterface $view, UnitOfWork $uow, EntityManager $entityManager, $depth = 0)
 {
     $initialUrl = $view->getUrl();
     // build url binded with parents url
     if (method_exists($view, 'isHomepage') && $view->isHomepage()) {
         $url = array('');
     } else {
         $url = array($view->getSlug());
     }
     //get the slug of the parents
     $url = $this->getParentSlugs($view, $url);
     //reorder the list of slugs
     $url = array_reverse($url);
     //build an url based on the slugs
     $url = implode('/', $url);
     //get the next free url
     $url = $this->getNextAvailaibleUrl($url, $entityManager);
     //update url of the view
     $view->setUrl($url);
     //the metadata of the page
     $meta = $entityManager->getClassMetadata(get_class($view));
     if ($depth === 0) {
         $uow->recomputeSingleEntityChangeSet($meta, $view);
     } else {
         $uow->computeChangeSet($meta, $view);
     }
     $this->rebuildChildrenUrl($view, $uow, $entityManager, $depth);
     if ($view->getId()) {
         $this->addRouteHistory($view, $initialUrl, $uow, $entityManager);
     }
 }
开发者ID:Atc-it,项目名称:victoire,代码行数:40,代码来源:ViewUrlHelper.php

示例6: populateMeta

 protected function populateMeta(EntityManager $em, UnitOfWork $uow, ImageInterface $entity)
 {
     $meta = $em->getClassMetadata(get_class($entity));
     $meta->getReflectionProperty('size')->setValue($entity, $this->imageManager->getTemporaryImage($entity)->getSize());
     $uow->recomputeSingleEntityChangeSet($meta, $entity);
 }
开发者ID:thrace-project,项目名称:media-bundle,代码行数:6,代码来源:ImageUploadSubscriber.php

示例7: process


//.........这里部分代码省略.........
         foreach ($url_associations as $key => $association) {
             if ($association['type'] == ClassMetadataInfo::ONE_TO_ONE && $association['orphanRemoval']) {
                 $url_field = $key;
                 break;
             }
         }
         if ($url_field == null) {
             return;
         }
         $settings = $entity->settings();
         $url_settings = isset($settings[$url_field]) ? $settings[$url_field] : array();
         $url_item = $entity->get($url_field);
         if ($new_url = is_null($url_item)) {
             $url_item = new \CMF\Model\URL();
         }
         // Don't run if this is an alias...
         $alias = $url_item->alias;
         if (!is_null($alias) && !empty($alias)) {
             return;
         }
         // Don't run if this is an external link...
         if ($url_item->isExternal()) {
             return;
         }
         $prefix = $this->getPrefix($entity);
         $slug = '';
         if (isset($url_settings['keep_updated']) && !$url_settings['keep_updated']) {
             $slug = \CMF::slug($url_item->slug);
         } else {
             $slug = $entity->urlSlug();
         }
         $url = $prefix . $slug;
         if ($url != '/') {
             $url = rtrim($url, '/');
         }
         $current_url = $url_item->url;
         $entity_id = $entity->id;
         $url_id = $url_item->get('id');
         // Check for duplicates, only if this is an already existing item
         if (!empty($entity_id) && !is_null($entity_id)) {
             // Set data from the entity if the prefix is null
             if (is_null($prefix)) {
                 $prefix = $this->getPrefix($entity);
                 $url = $prefix . $slug;
             }
             // Set data from the entity if the slug is null
             if (is_null($slug)) {
                 $slug = $entity->urlSlug();
                 $url = $prefix . $slug;
             }
             // Set it to the item's ID if empty
             if (is_null($slug)) {
                 $slug = $entity_id . "";
                 $url = $prefix . $slug;
             }
             $slug_orig = $slug;
             $unique = $this->checkUnique($url, $entity_id, $url_id);
             $counter = 2;
             while (!$unique) {
                 $slug = $slug_orig . '-' . $counter;
                 $url = $prefix . $slug;
                 $unique = $this->checkUnique($url, $entity_id, $url_id);
                 $counter++;
             }
             // Add it to the list of saved URLs
             $this->savedUrls[$url] = $entity_id;
         }
         $url_item->set('item_id', $entity->get('id'));
         $url_item->set('prefix', $prefix);
         $url_item->set('slug', $slug);
         $url_item->set('url', $url);
         $url_item->set('type', $metadata->name);
         $entity->set($url_field, $url_item);
         $em->persist($url_item);
         // Skip this if the url hasn't changed
         if (!$new_url && $current_url == $url) {
             return;
         }
         $url_metadata = $em->getClassMetadata('CMF\\Model\\URL');
         $url_changeset = $uow->getEntityChangeSet($url_item);
         if (!empty($url_changeset)) {
             $uow->recomputeSingleEntityChangeSet($url_metadata, $url_item);
         } else {
             $uow->computeChangeSet($url_metadata, $url_item);
         }
         $uow->recomputeSingleEntityChangeSet($metadata, $entity);
         $associations = $metadata->getAssociationMappings();
         foreach ($associations as $association_name => $association) {
             // Only do it if it's the inverse side, to prevent the dreaded infinite recursion
             if (!$association['isOwningSide']) {
                 $items = $entity->{$association_name};
                 if (!empty($items)) {
                     foreach ($items as $item) {
                         $this->process($item, $em, $uow);
                     }
                 }
             }
         }
     }
 }
开发者ID:soundintheory,项目名称:fuel-cmf,代码行数:101,代码来源:URLListener.php

示例8: recomputeChangeSet

 /**
  * @param object $entity Entity to recompute change set
  */
 protected function recomputeChangeSet($entity)
 {
     $this->checkIfInitialized();
     $this->uow->recomputeSingleEntityChangeSet($this->em->getClassMetadata(ClassUtils::getClass($entity)), $entity);
 }
开发者ID:darvinstudio,项目名称:darvin-utils,代码行数:8,代码来源:AbstractOnFlushListener.php

示例9: recomputeSingleObjectChangeSet

 /**
  * Recompute the single object changeset from a UnitOfWork.
  *
  * @param \Doctrine\ORM\UnitOfWork $uow
  * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $meta
  * @param object $object
  * @return null
  */
 public function recomputeSingleObjectChangeSet(UnitOfWork $uow, ClassMetadataInfo $meta, $object)
 {
     $uow->recomputeSingleEntityChangeSet($meta, $object);
 }
开发者ID:norzechowicz,项目名称:doctrine-extensions,代码行数:12,代码来源:ORM.php

示例10: recoumputeChanges

 /**
  * @param $entity
  */
 private function recoumputeChanges($entity)
 {
     if ($this->uow->getEntityChangeSet($entity)) {
         $this->uow->recomputeSingleEntityChangeSet($this->em->getClassMetadata(get_class($entity)), $entity);
     }
 }
开发者ID:RinWorld,项目名称:Ponzi-1,代码行数:9,代码来源:StatsListener.php

示例11: generatePath

 /**
  * Generates new full path and validates its uniqueness
  * @param PageLocalization $pageData
  * @return PageLocalization if changes were made
  */
 protected function generatePath(PageLocalization $pageData, $force = false)
 {
     $page = $pageData->getMaster();
     $oldPath = $pageData->getPath();
     $changes = false;
     $oldPathEntity = $pageData->getPathEntity();
     list($newPath, $active, $limited, $inSitemap) = $this->findPagePath($pageData);
     if (!$page->isRoot()) {
         if (!Path::compare($oldPath, $newPath) || $force) {
             $suffix = null;
             // Check duplicates only if path is not null
             if (!is_null($newPath)) {
                 // Additional check for path length
                 $pathString = $newPath->getPath();
                 if (mb_strlen($pathString) > 255) {
                     throw new Exception\RuntimeException('Overall path length shouldn\'t be more than 255 symbols');
                 }
                 $i = 2;
                 $e = null;
                 $pathPart = $pageData->getPathPart();
                 $pathValid = false;
                 do {
                     try {
                         $this->checkForDuplicates($pageData, $newPath);
                         $pathValid = true;
                     } catch (DuplicatePagePathException $e) {
                         if ($force) {
                             // loop stoper
                             if ($i > 101) {
                                 throw new Exception\RuntimeException("Couldn't find unique path for new page", null, $e);
                             }
                             // Will try adding unique suffix after 100 iterations
                             if ($i > 100) {
                                 $suffix = uniqid();
                             } else {
                                 $suffix = $i;
                             }
                             $pageData->setPathPart($pathPart . '-' . $suffix);
                             list($newPath, $active, $limited, $inSitemap) = $this->findPagePath($pageData);
                             $i++;
                         }
                     }
                 } while ($force && !$pathValid);
                 if ($e instanceof DuplicatePagePathException && !$pathValid) {
                     throw $e;
                 }
             }
             // Validation passed, set the new path
             $pageData->setPathData($newPath, $active, $limited, $inSitemap);
             if (!is_null($suffix)) {
                 $pageData->setTitle($pageData->getTitle() . " ({$suffix})");
             }
             $changes = true;
         }
     } elseif ($page->getLeftValue() == 1) {
         $newPath = new Path('');
         // Root page
         if (!$newPath->equals($oldPath)) {
             $changes = true;
             $pageData->setPathData($newPath, $active, $limited, $inSitemap);
         }
         // Another root page...
     } else {
         $newPath = null;
         $active = false;
         $pageData->setPathData($newPath, $active, $limited, $inSitemap);
     }
     if ($oldPathEntity->isActive() !== $active || $oldPathEntity->isVisibleInSitemap() != $inSitemap) {
         $pageData->setPathData($newPath, $active, $limited, $inSitemap);
         $changes = true;
     }
     if ($changes) {
         $pathEntity = $pageData->getPathEntity();
         $pathMetaData = $this->em->getClassMetadata($pathEntity->CN());
         $localizationMetaData = $this->em->getClassMetadata($pageData->CN());
         if ($this->unitOfWork->getEntityState($pathEntity, UnitOfWork::STATE_NEW) === UnitOfWork::STATE_NEW) {
             $this->em->persist($pathEntity);
             //			} elseif ($this->unitOfWork->getEntityState($pathEntity) === UnitOfWork::STATE_DETACHED) {
             //				$pathEntity = $this->em->merge($pathEntity);
         }
         /*
          * Add the path changes to the changeset, must call different 
          * methods depending on is the entity inside the unit of work
          * changeset
          */
         if ($this->unitOfWork->getEntityChangeSet($pathEntity)) {
             $this->unitOfWork->recomputeSingleEntityChangeSet($pathMetaData, $pathEntity);
         } else {
             $this->unitOfWork->computeChangeSet($pathMetaData, $pathEntity);
         }
         if ($this->unitOfWork->getEntityChangeSet($pageData)) {
             $this->unitOfWork->recomputeSingleEntityChangeSet($localizationMetaData, $pageData);
         } else {
             $this->unitOfWork->computeChangeSet($localizationMetaData, $pageData);
         }
//.........这里部分代码省略.........
开发者ID:sitesupra,项目名称:sitesupra,代码行数:101,代码来源:PagePathGeneratorListener.php

示例12: onFlush

 public function onFlush(OnFlushEventArgs $eventArgs)
 {
     if (!$this->active) {
         return;
     }
     // Clear updateData
     $this->updateData = $this->extraUpdates = array();
     $this->em = $eventArgs->getEntityManager();
     $this->conn = $this->em->getConnection();
     $this->uow = $this->em->getUnitOfWork();
     $this->platform = $this->conn->getDatabasePlatform();
     $this->revisionId = null;
     // reset revision
     $this->draft = false;
     $processedEntities = array();
     foreach ($this->uow->getScheduledEntityDeletions() as $entity) {
         if (!$this->annotationReader->isRevised(get_class($entity), true)) {
             continue;
         }
         //doctrine is fine deleting elements multiple times. We are not.
         $hash = $this->getHash($entity);
         if (in_array($hash, $processedEntities)) {
             continue;
         }
         $processedEntities[] = $hash;
         $this->extraUpdates[spl_object_hash($entity)] = $entity;
         $persister = $this->uow->getEntityPersister(get_class($entity));
         $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
         $entityData = array_merge($this->getOriginalEntityData($entity), $this->uow->getEntityIdentifier($entity));
         $this->saveRevisionEntityData($this->em->getClassMetadata(get_class($entity)), $entityData, 'DEL');
         if ($this->annotationReader->isDraft($entity) && $entity->isDraft()) {
             $this->resetRevisedData($entity);
             $this->setRevisionInfo($entity);
             $persister = $this->uow->getEntityPersister(get_class($entity));
             $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
             $fieldName = 'deletedAt';
             $reflProp = new \ReflectionProperty($entity, $fieldName);
             $reflProp->setAccessible(true);
             $oldValue = $reflProp->getValue($entity);
             $reflProp->setValue($entity, null);
             $this->uow->scheduleExtraUpdate($entity, array($fieldName => array($oldValue, null)));
         }
         if (isset($this->softDeletes[spl_object_hash($entity)])) {
             $this->em->persist($entity);
         }
     }
     foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
         if (!$this->annotationReader->isRevised(get_class($entity), true)) {
             continue;
         }
         $this->setRevisionInfo($entity);
         $this->extraUpdates[spl_object_hash($entity)] = $entity;
         $persister = $this->uow->getEntityPersister(get_class($entity));
         $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
         if ($this->annotationReader->isDraft($entity) && $entity->isDraft()) {
             $this->insertDrafts[spl_object_hash($entity)] = $entity;
             $this->resetRevisedData($entity);
             $this->uow->recomputeSingleEntityChangeSet($this->em->getClassMetadata(get_class($entity)), $entity);
         }
     }
     foreach ($this->uow->getScheduledEntityUpdates() as $entity) {
         if (!$this->annotationReader->isRevised(get_class($entity), true)) {
             continue;
         }
         $this->setRevisionInfo($entity);
         $this->extraUpdates[spl_object_hash($entity)] = $entity;
         $persister = $this->uow->getEntityPersister(get_class($entity));
         $this->updateData[spl_object_hash($entity)] = $this->prepareUpdateData($persister, $entity);
         if ($this->annotationReader->isDraft($entity) && $entity->isDraft()) {
             $this->resetRevisedData($entity);
         }
     }
 }
开发者ID:opifer,项目名称:revisions,代码行数:73,代码来源:RevisionListener.php


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