public function postFlush(PostFlushEventArgs $eventArgs) { if ($this->needFlush) { $this->needFlush = false; $eventArgs->getEntityManager()->flush(); } }
/** * Save collected changes * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { /** @var $entityManager */ $entityManager = $args->getEntityManager(); $this->activityListManager->processDeletedEntities($this->deletedEntities, $entityManager); $this->deletedEntities = []; if ($this->activityListManager->processInsertEntities($this->insertedEntities, $entityManager)) { $this->insertedEntities = []; $entityManager->flush(); } }
/** * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $entityManager = $args->getEntityManager(); foreach ($entityManager->getUnitOfWork()->getIdentityMap() as $key => $entities) { foreach ($entities as $entityId => $entity) { $changeSet = $entityManager->getUnitOfWork()->getEntityChangeSet($entity); $entityClass = $this->contextService->resolveEntityClass(get_class($entity)); $contexts = $this->contextService->getEntityContexts($entityClass); if (count($contexts) && count($changeSet)) { $queued = $this->contextService->getQueued(); if (count($queued)) { if (isset($queued[$entityClass])) { $currentEntity = $queued[$entityClass]; $contextRepo = $args->getEntityManager()->getRepository('BigfootContextBundle:Context'); /** @var ContextRepository $contextRepo */ $context = $contextRepo->findOneByEntityIdEntityClass($entityId, $entityClass); if (!$context) { $context = $this->createContext($entityId, $entityClass, $currentEntity['context_values']); } $entityManager->persist($context); $this->contextService->clearQueue(); $entityManager->flush(); } } } } } }
/** * Post flush * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $this->manager = $args->getEntityManager(); if (!empty($this->deactivatedLocales)) { $this->onLocalesDeactivated(); } }
/** * Send notification to clank that user have new emails * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $usersWithNewEmails = []; if (!$this->processEmailUsersEntities) { return; } /** @var EmailUser $entity */ foreach ($this->processEmailUsersEntities as $item) { $status = $item['status']; $entity = $item['entity']; $em = $args->getEntityManager(); $ownerIds = $this->determineOwners($entity, $em); foreach ($ownerIds as $ownerId) { if (array_key_exists($ownerId, $usersWithNewEmails) === true) { $new = $usersWithNewEmails[$ownerId]['new']; if ($status === self::ENTITY_STATUS_NEW) { $usersWithNewEmails[$ownerId]['new'] = $new + 1; } } else { $usersWithNewEmails[$ownerId] = ['entity' => $entity, 'new' => $status === self::ENTITY_STATUS_NEW ? 1 : 0]; } } } if ($usersWithNewEmails) { $this->processor->send($usersWithNewEmails); } $this->processEmailUsersEntities = []; }
public function postFlush(PostFlushEventArgs $event) { $em = $event->getEntityManager(); while ($entity = array_shift($this->proxiesStripped)) { $className = get_class($entity); $this->getTranslationMetadata($className, $em)->injectProxies($entity, $this->defaultLocaleProvider); } }
/** * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { if ($this->scheduledEntities) { while ($processJob = array_shift($this->scheduledEntities)) { $this->serialize($processJob); } $args->getEntityManager()->flush(); } }
public function postFlush(PostFlushEventArgs $event) { if (!empty($this->entities)) { $em = $event->getEntityManager(); foreach ($this->entities as $k => $entity) { $em->persist($entity); unset($this->entities[$k]); } $em->flush(); } }
public function postFlush(PostFlushEventArgs $args) { if (count($this->EntidadesRelacionadas) > 0) { $em = $args->getEntityManager(); foreach ($this->EntidadesRelacionadas as $Entidad) { $em->persist($Entidad); } $this->EntidadesRelacionadas = array(); $em->flush(); } }
/** * @param PostFlushEventArgs $args args */ public function postFlush(PostFlushEventArgs $args) { if (count($this->violations) === 0) { return null; } $entityManager = $args->getEntityManager(); foreach ($this->violations as $violation) { $entityManager->persist($violation); } $this->violations = array(); $entityManager->flush(); }
public function postFlush(PostFlushEventArgs $args) { if ($this->_isFlushing || !count($this->_structures)) { return; } $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); foreach ($this->_structures as $structure) { $nodes = $em->getRepository('Chalk\\Core\\Structure\\Node')->all(['structure' => $structure, 'sort' => 'sort']); $root = null; foreach ($nodes as $node) { $node->children->setInitialized(true); $node->children->clear(); if (!isset($node->parent)) { $root = $node; } } foreach ($nodes as $node) { if (isset($node->parent)) { $node->parent->children->add($node); } } $tree = new \RecursiveIteratorIterator(new \Chalk\Core\Structure\Node\Iterator([$root]), \RecursiveIteratorIterator::SELF_FIRST); $j = 0; $stack = []; foreach ($tree as $i => $node) { $slice = array_splice($stack, $tree->getDepth(), count($stack), [$node]); foreach (array_reverse($slice) as $reverse) { $reverse->right = $j++; } $node->left = $j++; $node->sort = $i; $node->depth = $tree->getDepth(); $nodes = $stack; array_shift($nodes); $parts = array_map(function ($node) { return isset($node->slug) ? $node->slug : $node->content->slug; }, $nodes); if (isset($structure->path)) { array_unshift($parts, $structure->path); } $node->path = implode('/', $parts); } foreach (array_reverse($stack) as $reverse) { $reverse->right = $j++; } } $this->_structures = []; $this->_isFlushing = true; $em->flush(); $this->_isFlushing = false; }
public function postFlush(PostFlushEventArgs $args) { if (!count($this->_updates)) { return; } $em = $args->getEntityManager(); $indexes = $em->getRepository('Chalk\\Core\\Index')->entities($this->_updates); foreach ($indexes as $index) { $index->reindex(); } $this->_updates = []; $em->flush(); }
public function postFlush(Event\PostFlushEventArgs $eventArgs) { if ($this->recursionMutex || $this->switchedOff) { return; } foreach ($this->toInvalidate as $territoire) { $this->container->get('repository.cache_info')->invalidate($territoire); } $this->recursionMutex = true; $eventArgs->getEntityManager()->flush(); $this->recursionMutex = false; $this->toInvalidate = array(); }
/** * Handles postFlush event * * @param PostFlushEventArgs $event */ public function handlePostFlush(PostFlushEventArgs $event) { $entityManager = $event->getEntityManager(); if ($this->getQueueThreadUpdate()) { $this->processThreadCreate($entityManager); $this->resetQueueThreadUpdate(); $entityManager->flush(); } if ($this->getQueueHeadUpdate()) { $this->processEmailsHeadSet($entityManager); $this->resetQueueHeadUpdate(); $entityManager->flush(); } }
public function postFlush(PostFlushEventArgs $args) { $arm = $this->getAutoRouteManager(); $arm->handleDefunctRoutes(); if (!$this->postFlushDone) { $om = $args->getEntityManager(); foreach ($this->insertions as $document) { $this->handleInsertOrUpdate($document, $arm, $om); } $this->postFlushDone = true; $om->flush(); } $this->postFlushDone = false; }
/** * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $emailIds = $this->popEmailIds(); if (!$emailIds) { return; } $jobArgs = array_map(function ($id) { return sprintf('--%s=%s', AutoResponseCommand::OPTION_ID, $id); }, $emailIds); $job = new Job(AutoResponseCommand::NAME, $jobArgs); $em = $args->getEntityManager(); $em->persist($job); $em->flush(); }
/** * @param PostFlushEventArgs $event */ public function postFlush(PostFlushEventArgs $event) { if (!empty($this->insertedCalendars)) { $em = $event->getEntityManager(); foreach ($this->insertedCalendars as $calendar) { // connect the calendar to itself $calendarProperty = new CalendarProperty(); $calendarProperty->setTargetCalendar($calendar)->setCalendarAlias(Calendar::CALENDAR_ALIAS)->setCalendar($calendar->getId()); $em->persist($calendarProperty); } $this->insertedCalendars = []; $em->flush(); } }
/** * Updates all returns which have been scheduled for insertion. * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $em = $args->getEntityManager(); $changedReturns = $this->updateReturnNumbers($this->returns); /* * Empty returns array to indicate that all returns have been processed and to prevent loop on flushing. */ $this->returns = []; foreach ($changedReturns as $return) { $em->persist($return); } if (!empty($changedReturns)) { $em->flush($changedReturns); } }
public function postFlush(PostFlushEventArgs $args) { if (static::$disableProcessing) { return; } $this->init(); $em = $args->getEntityManager(); if (count($this->toFlush) > 0) { foreach ($this->toFlush as $num => $item) { $em->persist($item); } $em->flush(); $this->toFlush = array(); } }
/** * Updates all orders which have been scheduled for insertion. * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $em = $args->getEntityManager(); $changedOrders = $this->updateOrderNumbers($this->orders); /* * Empty orders array to indicate that all orders have been process and to prevent loop on flushing. */ $this->orders = []; foreach ($changedOrders as $order) { $em->persist($order); } if (!empty($changedOrders)) { $em->flush($changedOrders); } }
/** * @param PostFlushEventArgs $event */ public function postFlush(PostFlushEventArgs $event) { if (count($this->ordersForUpdate) === 0) { return; } $orders = $this->getChangedOrders($event->getEntityManager()->getUnitOfWork()); foreach ($orders as $order) { // if order was scheduled for update if (!empty($this->ordersForUpdate[$order->getId()])) { $this->channelDoctrineListener->initializeFromEventArgs($event); $this->updateCustomerLifetime($event->getEntityManager(), $order); unset($this->ordersForUpdate[$order->getId()]); } } }
public function postFlush(PostFlushEventArgs $event) { // exit; // if (array_key_exists('form', $_POST) && isset($_POST['form']["seo_slug"])) { $em = $event->getEntityManager(); $uow = $em->getUnitOfWork(); $languages = $em->getRepository('BigfishLanguageBundle:Language')->findAll(); $resourceTable = $em->getClassMetadata("BigfishResourceBundle:Resource")->getTableName(); $translationTable = $em->getClassMetadata("BigfishResourceBundle:ResourceTranslation")->getTableName(); foreach ($languages as $language) { $sql = "UPDATE " . $translationTable . " AS U\n INNER JOIN (\n SELECT core.resource_id, CONCAT_WS('/', dd.slug, cc.slug, bb.slug, aa.slug, core_aa.slug) AS slug\n FROM " . $resourceTable . " AS core JOIN " . $translationTable . " core_aa ON core.resource_id = core_aa.resource_id AND core_aa.language_id = " . $language->getId() . "\n LEFT OUTER JOIN " . $resourceTable . " a ON core.parent_id = a.resource_id LEFT OUTER JOIN " . $translationTable . " aa ON aa.resource_id = a.resource_id AND aa.language_id = " . $language->getId() . "\n LEFT OUTER JOIN " . $resourceTable . " b ON a.parent_id = b.resource_id LEFT OUTER JOIN " . $translationTable . " bb ON bb.resource_id = b.resource_id AND bb.language_id = " . $language->getId() . "\n LEFT OUTER JOIN " . $resourceTable . " c ON b.parent_id = c.resource_id LEFT OUTER JOIN " . $translationTable . " cc ON cc.resource_id = c.resource_id AND cc.language_id = " . $language->getId() . "\n LEFT OUTER JOIN " . $resourceTable . " d ON c.parent_id = d.resource_id LEFT OUTER JOIN " . $translationTable . " dd ON dd.resource_id = d.resource_id AND dd.language_id = " . $language->getId() . "\n\n ) AS Q ON U.resource_id = Q.resource_id SET U.path = Q.slug WHERE U.language_id = " . $language->getId() . "\n "; $query = $em->getConnection()->exec($sql); } } }
public function postFlush(PostFlushEventArgs $args) { if (!count($this->_updates) && !count($this->_deletions)) { return; } $em = $args->getEntityManager(); while (count($this->_updates)) { $entity = array_shift($this->_updates); $entity->entityId = $entity->entityObject->id; $em->persist($entity); } while (count($this->_deletions)) { $entity = array_shift($this->_deletions); $em->remove($entity); } $em->flush(); }
/** * Handles postFlush event * * @param PostFlushEventArgs $event */ public function handlePostFlush(PostFlushEventArgs $event) { $em = $event->getEntityManager(); if ($this->getQueue()) { foreach ($this->getQueue() as $email) { $this->copyContexts($em, $email); // prepare the list of association targets $targets = []; if (count($this->emailActivityListProvider->getTargetEntities($email)) === 0) { $this->addRecipientOwners($targets, $email); } $this->addSenderOwner($targets, $email); // add associations $this->addContextsToThread($em, $email, $targets); } $this->resetQueue(); $em->flush(); } }
/** * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { if (!$this->enabled || !$this->brokenAudits) { return; } $em = $args->getEntityManager(); foreach ($this->brokenAudits as $audit) { $meta = $em->getClassMetadata($audit->getObjectClass()); $deprecatedData = $audit->getDeprecatedData(); foreach ($deprecatedData as $field => $values) { $oldValue = is_array($values['old']) ? $values['old']['value'] : $values['old']; $newValue = is_array($values['new']) ? $values['new']['value'] : $values['new']; $fieldType = $meta->getTypeOfField($field); $audit->createField($field, $fieldType, $newValue, $oldValue); } $audit->setData(null); } $this->brokenAudits = []; $em->flush(); }
public function postFlush(PostFlushEventArgs $args) { if ($this->changeset) { if ($user = $this->changeset->getUser()) { $em = $args->getEntityManager(); $em->persist($this->changeset); $em->flush(); # надо пописать в поле изменения код с разметкой измененных изображений if ($user instanceof Doctor && count($this->imgFields)) { foreach ($this->imgFields as $field => $label) { $method = 'get' . ucfirst($field); if (method_exists($user, $method)) { $imgPath = $user->{$method}()['path']; $em->createQuery("\r\n\t\t\t\t\t\t\tUPDATE EvrikaMainBundle:ProfileChangeset ps\r\n\t\t\t\t\t\t\tSET ps.new = CONCAT(ps.new, '<br/><b>{$label}:</b> <img src=\"{$imgPath}\" />')\r\n\t\t\t\t\t\t\tWHERE ps.id = {$this->changeset->getId()}\r\n\t\t\t\t\t\t")->execute(); } } } $this->changeset = null; $this->imgFields = array(); } } }
public function postFlush(PostFlushEventArgs $args) { $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); $manager = new TagManager($this->managerRegistry); $tags = array(); foreach ($uow->getIdentityMap() as $model) { foreach ($model as $entity) { if ($entity instanceof Tag) { $tags[] = $entity; } if ($entity instanceof Taggable) { $this->entity = $entity; } } } if ($this->entity) { if (!empty($tags)) { $this->entity->setTags($tags); $manager->saveRelation($this->entity); } } }
/** * Listens to the onFlush event. * * @param PostFlushEventArgs $eventArgs */ public function postFlush(PostFlushEventArgs $eventArgs) { // If we got new Metadatable entities if (count($this->entities)) { $em = $eventArgs->getEntityManager(); // Loop through Metadatable entities marked as insertion foreach ($this->entities as $entity) { $classMetadata = $em->getClassMetadata(get_class($entity)); // Set the Meta Title property only if not manually set in the form if (!$classMetadata->getReflectionProperty(self::META_TITLE)->getValue($entity)) { // Get the toString (on the Translatable entity if applicable) if ($classMetadata->reflClass->hasProperty('translatable')) { $name = $entity->getTranslatable()->__toString(); } else { $name = $entity->__toString(); } $classMetadata->getReflectionProperty(self::META_TITLE)->setValue($entity, $name); $em->persist($entity); } } $this->entities = []; $em->flush(); } }
/** * Save collected changes * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $em = $args->getEntityManager(); if (!empty($this->deletedEntities) || !empty($this->updatedEntities)) { $accessor = PropertyAccess::createPropertyAccessor(); /** process deleted entities */ foreach ($this->deletedEntities as $activityData) { foreach ($activityData['targets'] as $targetInfo) { $direction = $targetInfo['direction']; $target = $em->getRepository($targetInfo['class'])->find($targetInfo['id']); $accessor->setValue($target, ActivityScope::CONTACT_COUNT, (int) $accessor->getValue($target, ActivityScope::CONTACT_COUNT) - 1); $directionCountPath = ActivityScope::CONTACT_COUNT_OUT; $contactDatePath = ActivityScope::LAST_CONTACT_DATE_OUT; if ($direction === DirectionProviderInterface::DIRECTION_INCOMING) { $directionCountPath = ActivityScope::CONTACT_COUNT_IN; $contactDatePath = ActivityScope::LAST_CONTACT_DATE_IN; } $accessor->setValue($target, $directionCountPath, (int) $accessor->getValue($target, $directionCountPath) - 1); $activityDate = $this->activityContactProvider->getLastContactActivityDate($em, $target, $direction, $activityData['id'], $activityData['class']); if ($activityDate) { $accessor->setValue($target, ActivityScope::LAST_CONTACT_DATE, $activityDate['all']); $accessor->setValue($target, $contactDatePath, $activityDate['direction']); } $em->persist($target); } } /** process updated entities */ foreach ($this->updatedEntities as $activityData) { foreach ($activityData['targets'] as $targetInfo) { $direction = $targetInfo['direction']; $isDirectionChanged = $targetInfo['is_direction_changed']; $target = $em->getRepository($targetInfo['class'])->find($targetInfo['id']); /** process dates */ if ($direction === DirectionProviderInterface::DIRECTION_INCOMING) { $contactDatePath = ActivityScope::LAST_CONTACT_DATE_IN; $oppositeContactDatePath = ActivityScope::LAST_CONTACT_DATE_OUT; $oppositeDirection = DirectionProviderInterface::DIRECTION_OUTGOING; } else { $contactDatePath = ActivityScope::LAST_CONTACT_DATE_OUT; $oppositeContactDatePath = ActivityScope::LAST_CONTACT_DATE_IN; $oppositeDirection = DirectionProviderInterface::DIRECTION_INCOMING; } $lastActivityDate = $this->activityContactProvider->getLastContactActivityDate($em, $target, $direction); if ($lastActivityDate) { $accessor->setValue($target, ActivityScope::LAST_CONTACT_DATE, $lastActivityDate['all']); $accessor->setValue($target, $contactDatePath, $lastActivityDate['direction']); $accessor->setValue($target, $oppositeContactDatePath, $this->activityContactProvider->getLastContactActivityDate($em, $target, $oppositeDirection)['direction']); } /** process counts (in case direction was changed) */ if ($isDirectionChanged) { $increment = ActivityScope::CONTACT_COUNT_OUT; $decrement = ActivityScope::CONTACT_COUNT_IN; if ($direction === DirectionProviderInterface::DIRECTION_INCOMING) { $increment = ActivityScope::CONTACT_COUNT_IN; $decrement = ActivityScope::CONTACT_COUNT_OUT; } $accessor->setValue($target, $increment, (int) $accessor->getValue($target, $increment) + 1); $accessor->setValue($target, $decrement, (int) $accessor->getValue($target, $decrement) - 1); } $em->persist($target); } } $this->deletedEntities = []; $this->updatedEntities = []; $em->flush(); } }
/** * PostUpdate doctrine event - updates the nodetranslation urls if needed * * @param PostFlushEventArgs $args */ public function postFlush(PostFlushEventArgs $args) { $em = $args->getEntityManager(); foreach ($this->nodeTranslations as $entity) { /** @var $entity NodeTranslation */ if ($entity instanceof NodeTranslation) { $publicNodeVersion = $entity->getPublicNodeVersion(); /** @var $publicNodeVersion NodeVersion */ $publicNode = $publicNodeVersion->getRef($em); /** Do nothing for StructureNode objects, skip */ if ($publicNode instanceof HasNodeInterface && $publicNode->isStructureNode()) { continue; } $entity = $this->updateUrl($entity, $em); if ($entity !== false) { $em->persist($entity); $em->flush($entity); $this->updateNodeChildren($entity, $em); } } } }