/** * @param OnClearEventArgs $event */ public function onClear(OnClearEventArgs $event) { /** @var SecurityContextInterface $securityContext */ $securityContext = $this->securityContextLink->getService(); $className = $event->getEntityClass(); $token = $securityContext->getToken(); if (!$token) { return; } $user = $token->getUser(); if (is_object($user) && (!$className || $className == ClassUtils::getRealClass($user))) { $user = $this->refreshEntity($user); if ($user) { $token->setUser($user); } else { $securityContext->setToken(null); $token = null; } } if ($token && $token instanceof OrganizationContextTokenInterface) { $organization = $token->getOrganizationContext(); if (is_object($organization) && (!$className || $className == ClassUtils::getRealClass($organization))) { /** @var Organization $organization */ $organization = $this->refreshEntity($organization); if ($organization) { $token->setOrganizationContext($organization); } } } }
/** * @param OnClearEventArgs $args */ public function onClear(OnClearEventArgs $args) { $this->triggers = null; if ($args->clearsAllEntities()) { $this->scheduledProcesses = array(); } else { unset($this->scheduledProcesses[$args->getEntityClass()]); } }
/** * @param OnClearEventArgs $event * @param OrganizationContextTokenInterface $token */ protected function checkOrganization(OnClearEventArgs $event, OrganizationContextTokenInterface $token) { $organization = $token->getOrganizationContext(); if (!is_object($organization)) { return; } $organizationClass = ClassUtils::getClass($organization); if ($event->getEntityClass() && $event->getEntityClass() !== $organizationClass) { return; } $em = $event->getEntityManager(); if ($em !== $this->doctrine->getManagerForClass($organizationClass)) { return; } $organization = $this->refreshEntity($organization, $organizationClass, $em); if (!$organization) { return; } $token->setOrganizationContext($organization); }
/** * Methos which will be called when the event is thrown. * * * @param OnClearEventArgs $eventArgs * * @author Etienne de Longeaux <*****@*****.**> */ public function onClear(OnClearEventArgs $eventArgs) { $entityClass = $eventArgs->getEntityClass(); $object_event = new TriggerEvent($eventArgs, $this->container, $entityClass); $this->container->get('event_dispatcher')->dispatch(TriggerEvents::TRIGGER_EVENT_ONCLEAR, $object_event); }