本文整理汇总了PHP中Doctrine\ORM\UnitOfWork::computeChangeSet方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::computeChangeSet方法的具体用法?PHP UnitOfWork::computeChangeSet怎么用?PHP UnitOfWork::computeChangeSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::computeChangeSet方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onFlush
/**
* @param OnFlushEventArgs $args
*/
public function onFlush(OnFlushEventArgs $args)
{
$this->initializeFromEventArgs($args);
$entities = array_merge($this->uow->getScheduledEntityInsertions(), $this->uow->getScheduledEntityDeletions(), $this->uow->getScheduledEntityUpdates());
/** @var Opportunity[] $entities */
$entities = array_filter($entities, function ($entity) {
return 'OroCRM\\Bundle\\SalesBundle\\Entity\\Opportunity' === ClassUtils::getClass($entity);
});
foreach ($entities as $entity) {
if (!$entity->getId() && $this->isValuable($entity)) {
// handle creation, just add to prev lifetime value and recalculate change set
$b2bCustomer = $entity->getCustomer();
$b2bCustomer->setLifetime($b2bCustomer->getLifetime() + $entity->getCloseRevenue());
$this->scheduleUpdate($b2bCustomer);
$this->uow->computeChangeSet($this->em->getClassMetadata(ClassUtils::getClass($b2bCustomer)), $b2bCustomer);
} elseif ($this->uow->isScheduledForDelete($entity) && $this->isValuable($entity)) {
$this->scheduleUpdate($entity->getCustomer());
} elseif ($this->uow->isScheduledForUpdate($entity)) {
// handle update
$changeSet = $this->uow->getEntityChangeSet($entity);
if ($this->isChangeSetValuable($changeSet)) {
if (!empty($changeSet['customer']) && $changeSet['customer'][0] instanceof B2bCustomer && B2bCustomerRepository::VALUABLE_STATUS === $this->getOldStatus($entity, $changeSet)) {
// handle change of b2b customer
$this->scheduleUpdate($changeSet['customer'][0]);
}
if ($this->isValuable($entity, isset($changeSet['closeRevenue'])) || B2bCustomerRepository::VALUABLE_STATUS === $this->getOldStatus($entity, $changeSet) && $entity->getCustomer()) {
$this->scheduleUpdate($entity->getCustomer());
}
}
}
}
}
示例2: deleteOnRelationalModification
/**
* Deletes an entity if it is in relation to another entity
*
* Doctrine is obviously unable to entities detached from the relational entity when merging the relational entity,
* so this had to be implemented.
*
* @param object $relationalEntity
* @param string $fieldName
* @param ClassMetadata $metadata
* @param boolean $recomputeChangeSet
*/
public function deleteOnRelationalModification($relationalEntity, $fieldName, ClassMetadata $metadata, $recomputeChangeSet = true)
{
if ($recomputeChangeSet) {
$this->unitOfWork->computeChangeSet($metadata, $relationalEntity);
}
$changeSet = $this->unitOfWork->getEntityChangeSet($relationalEntity);
if (!isset($changeSet[$fieldName])) {
return;
}
$orgValue = $changeSet[$fieldName][0];
if (null !== $orgValue && $this->entityManager->contains($orgValue)) {
$this->entityManager->remove($orgValue);
}
}
示例3: createCalendar
/**
* @param EntityManager $em
* @param UnitOfWork $uow
* @param User $entity
* @param Organization $organization
*/
protected function createCalendar($em, $uow, $entity, $organization)
{
// create a default calendar for assigned organization
$calendar = new Calendar();
$calendar->setOwner($entity);
$calendar->setOrganization($organization);
// connect the calendar to itself
$calendarConnection = new CalendarConnection($calendar);
$calendar->addConnection($calendarConnection);
$em->persist($calendar);
$em->persist($calendarConnection);
$uow->computeChangeSet($this->getClassMetadata($calendar, $em), $calendar);
$uow->computeChangeSet($this->getClassMetadata($calendarConnection, $em), $calendarConnection);
}
示例4: startAutoReply
/**
* @param Ticket $ticket
*/
protected function startAutoReply(Ticket $ticket)
{
$ticketText = $ticket->getSubject() . ' ' . $ticket->getDescription();
$repository = $this->registry->getManager()->getRepository('DiamanteDeskBundle:Article');
$results = [];
/** @var Article $article */
foreach ($repository->findByStatus(1) as $article) {
$articleText = $article->getTitle() . ' ' . $article->getContent();
$results[$article->getId()] = $this->compare($ticketText, $articleText);
}
$maxResult = max($results);
/**
* TODO: should be configured by admin
*/
if ($maxResult < 3) {
return;
}
$articleId = array_search(max($results), $results);
/**
* TODO: should be extracted from previous call of $repository->getAll()
*/
$article = $repository->find($articleId);
/**
* TODO: should be extracted from configuration???
*/
$user = User::fromString('oro_1');
$content = $this->getAutoReplayNoticeHtml() . $article->getContent();
$comment = new Comment($content, $ticket, $user, false);
$this->registry->getManager()->persist($comment);
$this->uow->computeChangeSet($this->em->getClassMetadata($comment->getClassName()), $comment);
/**
* TODO: should be executed workflowEven?
*/
}
示例5: 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);
}
}
示例6: setTags
/**
* Do the stuff
*
* @param TaggableInterface $entity
* @param boolean $update true if entity is being updated, false otherwise
*/
protected function setTags(TaggableInterface $entity, $update = false)
{
$tagNames = $entity->getTagNames();
if (empty($tagNames)) {
return;
}
// need to clone here, to avoid getting new tags
$oldTags = is_object($entityTags = $entity->getTags()) ? clone $entityTags : $entityTags;
$tagClassMetadata = $this->em->getClassMetadata(get_class($this->tag));
$repository = $this->em->getRepository(get_class($this->tag));
foreach ($tagNames as $tagName) {
$tag = $repository->findOneByName($tagName);
if (empty($tag)) {
// if tag doesn't exist, create it
$tag = clone $this->tag;
$tag->setName($tagName);
$this->em->persist($tag);
// see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#onflush
$this->uow->computeChangeSet($tagClassMetadata, $tag);
}
if (!$entity->hasTag($tag)) {
// add tag only if not already added
$entity->addTag($tag);
}
}
// if updating, need to check if some tags were removed
if ($update) {
foreach ($oldTags as $oldTag) {
if (!in_array($oldTag->getName(), $tagNames)) {
$entity->removeTag($oldTag);
}
}
}
// see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#onflush
$entityClassMetadata = $this->em->getClassMetadata(get_class($entity));
$this->uow->computeChangeSets($entityClassMetadata, $entity);
}
示例7: computeChangeset
/**
* Compute changeset
* @param object $entity
*/
protected function computeChangeset($entity)
{
$this->uow->persist($entity);
$this->uow->computeChangeSet($this->getMetadata($entity), $entity);
}
示例8: updateBusinessPageUrl
/**
* Manage urls.
*
* @param View $page
*
* @return void
*/
protected function updateBusinessPageUrl(BusinessPage $page, EntityManager $em, UnitOfWork $uow)
{
$oldSlug = $page->getSlug();
$staticUrl = $page->getStaticUrl();
$computedPage = $this->businessPageBuilder->generateEntityPageFromTemplate($page->getTemplate(), $page->getBusinessEntity(), $em);
$newSlug = $computedPage->getSlug();
if ($staticUrl) {
$staticUrl = preg_replace('/' . $oldSlug . '/', $newSlug, $staticUrl);
$page->setStaticUrl($staticUrl);
}
$page->setSlug($newSlug);
$meta = $em->getClassMetadata(get_class($page));
$em->persist($page);
$uow->computeChangeSet($meta, $page);
}
示例9: addRouteHistory
/**
* Record the route history of the page
*
* @param WebViewInterface $view
* @param string $initialUrl
*/
protected function addRouteHistory(WebViewInterface $view, $initialUrl, UnitOfWork $uow, EntityManager $entityManager)
{
$route = new Route();
$route->setUrl($initialUrl);
$route->setView($view);
$meta = $entityManager->getClassMetadata(get_class($route));
$entityManager->persist($route);
$uow->computeChangeSet($meta, $route);
//add the route to the page
$view->addRoute($route);
}
示例10: 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);
}
}
}
}
}
}
示例11: createCalendar
/**
* @param EntityManager $em
* @param UnitOfWork $uow
* @param User $user
* @param Organization $organization
*/
protected function createCalendar($em, $uow, $user, $organization)
{
// create default user's calendar
$calendar = new Calendar();
$calendar->setOwner($user)->setOrganization($organization);
$em->persist($calendar);
$uow->computeChangeSet($this->getClassMetadata($calendar, $em), $calendar);
$this->insertedCalendars[] = $calendar;
}
示例12: 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);
}
//.........这里部分代码省略.........