Pre update event listener.

@param PreUpdateEventArgs $eventArgs The pre update event args.

@return $this Self object
192936
public function preUpdate(PreUpdateEventArgs $eventArgs)
    {
        $entity = $eventArgs->getEntity();
        if ($entity instanceof CategoryInterface) {
            $this->removeParentCategoryForRootCategory($entity);
        }

        return $this;
    }
372328
public function preUpdate($eventArgs)
    {
        $entity = $eventArgs->getEntity();
        $changeset = $eventArgs->getEntityChangeSet();

        foreach ($this->metadata->getManagedFields($entity) as $field) {
            if (isset($changeset[$field])) {
                list($old, $new) = $changeset[$field];

                if ($old) {
                    $tempFilePath = $this->fileManager->getFilePath($entity, $field, $old);

                    if ($new && ((string)$new) && (string)$new == $tempFilePath) {
                        /** @var File $new */
                        // in this case the file was wrapped in a file object, but not actually changed.
                        // We "unwrap" the value here.
                        $new = $new->getBasename();
                    } else {
                        $filepath = $this->fileManager->getFilePath($entity, $field, $old);
                        $this->unitOfWork[spl_object_hash($entity)][$field]['delete'] =
                            function (FileManager $fm) use ($filepath) {
                                $fm->delete($filepath);
                            };
                    }
                }

                if (is_string($new)) {
                    $eventArgs->setNewValue($field, $new);
                } else {
                    if (null !== $new) {
                        $eventArgs->setNewValue($field, $this->scheduleForUpload($new, $entity, $field));
                    }
                }
            }
        }
    }
204773
public function preUpdate(PageTranslationInterface $translation, PreUpdateEventArgs $eventArgs)
    {
        if ($eventArgs->hasChangedField('path')) {
            $em = $eventArgs->getEntityManager();
            $uow = $em->getUnitOfWork();

            $locale = $translation->getLocale();
            $from = $eventArgs->getOldValue('path');
            $to   = $eventArgs->getNewValue('path');

            if (0 < strlen($from) && 0 < strlen($to) && $from != $to) {
                // TODO use url generator or i18n routing prefix strategy
                $localePrefix = $locale != 'fr' ? '/' . $locale : '';
                $this->redirections[] = array(
                    'from' => $localePrefix . $from,
                    'to'   => $localePrefix . $to,
                );
            }

            /** @var \Ekyna\Bundle\CmsBundle\Model\PageInterface $page */
            $page = $translation->getTranslatable();
            // Update the children pages translations paths.
            if ($page->hasChildren()) {
                $metadata = $em->getClassMetadata(get_class($translation));
                $this->updateChildrenPageTranslationPath(
                    $page, $uow, $metadata, $from, $to, $locale
                );
            }
        }
    }
340986
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
	{
		$reflection = $eventArgs->getClassMetadata()
				->getReflectionClass();
		
		if (empty($reflection)) {
			return;
		}

		$reader = $this->getAnnotationReader();
		
		$annotation = $reader->getClassAnnotation($reflection, DetachedDiscriminatorValue::CN());

		if ($annotation instanceof DetachedDiscriminatorValue) {
			$this->handleDetachedDisciminatorValue($eventArgs, $annotation);
		} 

		$annotation = $reader->getClassAnnotation($reflection, DetachedDiscriminators::CN());

		if ($annotation instanceof DetachedDiscriminators) {
			$this->handleDetachedDiscriminators($eventArgs);
		} 
	}
307197
public function preRemove(LifecycleEventArgs $eventArgs)
    {
        $entity = $eventArgs->getEntity();

        //if we remove a BP we need to replace by a VBP ref
        if ($entity instanceof BusinessPage) {
            //remove BP ref
            $event = new ViewReferenceEvent($entity);
            $this->dispatcher->dispatch(ViewReferenceEvents::REMOVE_VIEW_REFERENCE, $event);
            $em = $eventArgs->getEntityManager();
            $businessTemplate = $entity->getTemplate();
            $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
                $businessTemplate,
                $entity->getBusinessEntity(),
                $em
            );
            //create VBP ref
            //TODO :: dont rebuild if businessEntity or businessTemplate doesn't exist
            $event = new ViewReferenceEvent($page);
            $this->dispatcher->dispatch(ViewReferenceEvents::UPDATE_VIEW_REFERENCE, $event);
        }

        //if it's a businessEntity, we need to remove all BP and VBP ref
        if ($businessEntity = $this->businessEntityHelper->findByEntityInstance($entity)) {
            $em = $eventArgs->getEntityManager();
            $businessTemplates = $em->getRepository('VictoireBusinessPageBundle:BusinessTemplate')->findPagePatternByBusinessEntity($businessEntity);
            foreach ($businessTemplates as $businessTemplate) {

                // Generate a viewReference for each BT translation
                foreach ($businessTemplate->getTranslations() as $translation) {
                    $businessTemplate->setCurrentLocale($translation->getLocale());
                    if ($page = $em->getRepository('Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage')->findPageByBusinessEntityAndPattern($businessTemplate, $entity, $businessEntity)) {
                        $event = new ViewReferenceEvent($page);
                        $this->dispatcher->dispatch(ViewReferenceEvents::REMOVE_VIEW_REFERENCE, $event);
                    } else {
                        $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
                            $businessTemplate,
                            $entity,
                            $em
                        );
                        $event = new ViewReferenceEvent($page);
                        $this->dispatcher->dispatch(ViewReferenceEvents::REMOVE_VIEW_REFERENCE, $event);
                    }
                }
            }
        }
        //if we remove a businessTemplate remove all VBT ref (BP cascade remove)
        if ($entity instanceof BusinessTemplate) {
            $em = $eventArgs->getEntityManager();
            $entities = $this->businessPageHelper->getEntitiesAllowed($entity, $em);

            // Generate a viewReference for each BT translation
            foreach ($entity->getTranslations() as $translation) {
                $entity->setCurrentLocale($translation->getLocale());
                foreach ($entities as $be) {
                    $page = $this->businessPageBuilder->generateEntityPageFromTemplate(
                        $entity,
                        $be,
                        $em
                    );
                    $event = new ViewReferenceEvent($page);
                    $this->dispatcher->dispatch(ViewReferenceEvents::REMOVE_VIEW_REFERENCE, $event);
                }
            }
        }
    }
69932
public function trigger($events, $args = [])
    {
        $args[] = $this;
        if (!is_array($events)) {
            $events = [$events];
        }

        foreach ($events as $event) {
            dispatcher()->trigger(static::class . '.' . $event, $args);
            dispatcher()->trigger(Record::class . '.' . $event, $args);
        }

        return $this;
    }
454018
public function dispatchEvent(EventArgs $eventArgs)
    {
        if ($eventArgs->sender === null) {
            $eventArgs->sender = $this;
        }
        // 标记开始传播
        $eventArgs->propagationStopped = false;
        $eventClass = get_class($eventArgs);
        if (isset($this->eventListenerMap[$eventClass])) {
            $eventHandlers = $this->eventListenerMap[$eventClass];
            // 依次调用注册的事件处理器
            foreach ($eventHandlers as $handler) {
                if ($eventArgs->propagationStopped) {
                    return;
                }
                call_user_func($handler, $eventArgs);
            }
        }
    }
795399
protected function getEventAdapter(EventArgs $args)
    {
        $class = get_class($args);
        if (preg_match('@Doctrine\\\([^\\\]+)@', $class, $m) && in_array($m[1], ['ODM', 'ORM'])) {
            if (!isset($this->adapters[$m[1]])) {
                $adapterClass = 'Gedmo\\Mapping\\Event\\Adapter\\' . $m[1];
                $this->adapters[$m[1]] = new $adapterClass();
            }

            $this->adapters[$m[1]]->setEventArgs($args);
            return $this->adapters[$m[1]];
        }

        throw new \InvalidArgumentException('Session continaer does not support event arg class: ' . $class);
    }
2498
public function preUpdate(LifecycleEventArgs $args) : void
    {
        $entity = $args->getEntity();

        if ($entity instanceof UpdatedInterface) {
            $entity->setUpdatedAt(new \DateTime());
        }
    }
1284218
public function onClear($eventArgs)
    {
        parent::onClear($eventArgs);

        $aliases             = array_keys($this->identifierMap);
        $this->identifierMap = array();

        foreach ($aliases as $alias) {
            $this->identifierMap[$alias] = array();
        }
    }
1261075
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $classMetadata = $eventArgs->getClassMetadata();
        $reflClass = $classMetadata->reflClass;

        if (!$reflClass) {
            return;
        }

        if ($reflClass->implementsInterface('Prezent\Doctrine\Translatable\TranslatableInterface')) {
            $this->mapTranslatable($classMetadata);
        }

        if ($reflClass->implementsInterface('Prezent\Doctrine\Translatable\TranslationInterface')) {
            $this->mapTranslation($classMetadata);
        }
    }
1161541
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        /** @var ClassMetadata $classMetadata */
        $classMetadata = $eventArgs->getClassMetadata();

        if (null === $classMetadata->getReflectionClass() ||
            false == $this->isModular($classMetadata) ||
            'Harmony\Component\ModularRouting\StaticModule' == $this->getModuleClass() ||
            $classMetadata->hasField('module') || $classMetadata->hasAssociation('module')) {

            return;
        }

        $classMetadata->mapManyToOne([
            'targetEntity' => $this->getModuleClass(),
            'fieldName'    => 'module',
            'joinColumns'  => [
                [
                    'name'                 => 'module_id',
                    'referencedColumnName' => 'id',
                ],
            ],
        ]);
    }
753603
public function postRemove(EventArgs $eventArgs)
    {
        if (method_exists($eventArgs, 'getEntity')) {
            $this->_triggerEvent(Events::postRemove, $eventArgs->getEntity(), $eventArgs);
        }
    }
293368
protected function updateScriptEvents()
    {
        if (!$this->control || !ScriptLabel::isEventLabel($this->labelName)) {
            return $this;
        }
        if ($this->control instanceof Scriptable) {
            $this->control->setScriptEvents(true);
        }
        return $this;
    }
675225
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $this->eventQueue->setOpened(true);

        $uow = $eventArgs->getEntityManager()->getUnitOfWork();

        foreach ($uow->getScheduledEntityInsertions() as $entity) {
            if ($entity instanceof ResourceInterface) {
                $this->eventQueue->scheduleInsert($entity);
            }
        }

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            if ($entity instanceof ResourceInterface) {
                $this->eventQueue->scheduleUpdate($entity);
            }
        }

        // TODO move collections before update ?
        foreach ($uow->getScheduledCollectionDeletions() as $col) {
            foreach ($col as $c) {
                foreach ($c as $entity) {
                    if ($entity instanceof ResourceInterface) {
                        $this->eventQueue->scheduleDelete($entity);
                    }
                }
            }
        }
        foreach ($uow->getScheduledCollectionUpdates() as $col) {
            foreach ($col as $c) {
                foreach ($c as $entity) {
                    if ($entity instanceof ResourceInterface) {
                        if ($entity->getId()) {
                            $this->eventQueue->scheduleUpdate($entity);
                        } else {
                            $this->eventQueue->scheduleInsert($entity);
                        }
                    }
                }
            }
        }

        foreach ($uow->getScheduledEntityDeletions() as $entity) {
            if ($entity instanceof ResourceInterface) {
                $this->eventQueue->scheduleDelete($entity);
            }
        }

        $this->eventQueue->flush();

        $this->eventQueue->setOpened(false);
    }
500692
public function preFlush(PreFlushEventArgs $eventArgs)
    {
        $entityManager = $eventArgs->getEntityManager();
        $unitOfWork = $entityManager->getUnitOfWork();

        foreach ($unitOfWork->getIdentityMap() as $entities) {
            foreach ($entities as $object) {
                $uploadableMeta = $this->getObjectExtendedMetadata($entityManager, $object);
                if (!$uploadableMeta->hasUploadableProperties()) {
                    continue;
                }
                $this->updateFiles($entityManager, $object, $uploadableMeta);
            }
        }
    }
974758
public function logChangeSet(LifecycleEventArgs $eventArgs)
    {
        $em            = $eventArgs->getEntityManager();
        $uow           = $em->getUnitOfWork();
        $entity        = $eventArgs->getEntity();
        $classMetadata = $em->getClassMetadata(get_class($entity));

        if ($this->isEntitySupported($classMetadata->reflClass)) {
            $uow->computeChangeSet($classMetadata, $entity);
            $changeSet = $uow->getEntityChangeSet($entity);

            $message = $entity->getUpdateLogMessage($changeSet);
            $loggerCallable = $this->loggerCallable;
            $loggerCallable($message);
        }
    }