@DI\Observe("crud_pre_delete_object_claroline_corebundle_entity_user")

@param DeleteEvent $event
516946
public function preDelete(DeleteEvent $event)
    {
        /** @var User $user */
        $user = $event->getObject();
        $userRole = $this->roleManager->getUserRole($user->getUsername());

        //soft delete~
        $user->setIsRemoved(true);
        $user->setEmail('email#'.$user->getId());
        $user->setFirstName('firstname#'.$user->getId());
        $user->setLastName('lastname#'.$user->getId());
        $user->setPlainPassword(uniqid());
        $user->setUsername('username#'.$user->getId());
        $user->setPublicUrl('removed#'.$user->getId());
        $user->setAdministrativeCode('code#'.$user->getId());
        $user->setIsEnabled(false);

        // keeping the user's workspace with its original code
        // would prevent creating a user with the same username
        // todo: workspace deletion should be an option
        $ws = $user->getPersonalWorkspace();

        if ($ws) {
            $ws->setCode($ws->getCode().'#deleted_user#'.$user->getId());
            $ws->setDisplayable(false);
            $this->om->persist($ws);
        }

        if ($userRole) {
            $this->om->remove($userRole);
        }
        $this->om->persist($user);
        $this->om->flush();

        //dispatch some events but they should be listening the same as we are imo.
        //something should be done for event listeners
        $this->dispatcher->dispatch('claroline_users_delete', 'GenericData', [[$user]]);
        $this->dispatcher->dispatch('log', 'Log\LogUserDelete', [$user]);
        $this->dispatcher->dispatch('delete_user', 'DeleteUser', [$user]);
    }
582804
public function postCreate(CreateEvent $event)
    {
        if (in_array(Options::USER_SELF_LOG, $event->getOptions())) {
            $this->userManager->logUser($event->getObject());
        }
    }
287508
public function deleteMetadata(EventInterface $event) {
        $request = $event->getRequest();

        $event->getDatabase()->deleteMetadata(
            $request->getUser(),
            $request->getImageIdentifier()
        );

        $event->getDatabase()->setLastModifiedNow(
            $request->getUser(),
            $request->getImageIdentifier()
        );
    }
1293347
public function delete(CategoryDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $category = CategoryQuery::create()->findPk($event->getCategoryId())) {
            $con = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME);
            $con->beginTransaction();

            try {
                $fileList = ['images' => [], 'documentList' => []];

                // Get category's files to delete after category deletion
                $fileList['images']['list'] = CategoryImageQuery::create()
                    ->findByCategoryId($event->getCategoryId());
                $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;

                $fileList['documentList']['list'] = CategoryDocumentQuery::create()
                    ->findByCategoryId($event->getCategoryId());
                $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;

                // Delete category
                $category
                    ->setDispatcher($dispatcher)
                    ->delete($con);

                $event->setCategory($category);

                // Dispatch delete category's files event
                foreach ($fileList as $fileTypeList) {
                    foreach ($fileTypeList['list'] as $fileToDelete) {
                        $fileDeleteEvent = new FileDeleteEvent($fileToDelete);
                        $dispatcher->dispatch($fileTypeList['type'], $fileDeleteEvent);
                    }
                }

                $con->commit();
            } catch (\Exception $e) {
                $con->rollback();
                throw $e;
            }
        }
    }
504187
public function preCreate(CreateEvent $event)
    {
        $subject = $event->getObject();
        $forum = $subject->getForum();

        //create user if not here
        $user = $this->om->getRepository('ClarolineForumBundle:Validation\User')->findOneBy([
          'user' => $subject->getCreator(),
          'forum' => $forum,
        ]);

        if (!$user) {
            $user = new User();
            $user->setForum($forum);
            $user->setUser($subject->getCreator());
        }

        $messages = $subject->getMessages();
        $first = $messages && isset($messages[0]) ? $messages[0] : null;

        if (!$this->checkPermission('EDIT', $forum->getResourceNode())) {
            if (Forum::VALIDATE_PRIOR_ALL === $forum->getValidationMode()) {
                $subject->setModerated(Forum::VALIDATE_PRIOR_ALL);
                if ($first) {
                    $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
                }
            }

            if (Forum::VALIDATE_PRIOR_ONCE === $forum->getValidationMode()) {
                $subject->setModerated($user->getAccess() ? Forum::VALIDATE_NONE : Forum::VALIDATE_PRIOR_ONCE);
                if ($first) {
                    $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
                }
            }
        } else {
            $subject->setModerated(Forum::VALIDATE_NONE);
            if ($first) {
                $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
            }
        }

        if ($first) {
            $this->om->persist($first);
        }

        return $subject;
    }
185946
public function preUpdate(User $user, PreUpdateEventArgs $event)
    {
        if ($event->hasChangedField('avatarImage')) {
            $oldAvatarImage = $event->getOldValue('avatarImage');
            if (!empty($oldAvatarImage)) {
                $this->userService->deleteAvatar($oldAvatarImage);
            }
        }
    }
1051186
public function onBeforeDeleteUser(UserEvent $event)
    {
        $user = $event->getUser();

        $locks = $this->entityManager->getRepository('PhlexibleElementBundle:ElementLock')
            ->findBy(['userId' => $user->getId()]);

        foreach ($locks as $lock) {
            $this->entityManager->remove($lock);
        }
    }
433996
public function onDeleteUser(LogGenericEvent $event)
    {
        if ($event instanceof LogUserDeleteEvent) {
            $receiver = $event->getReceiver();
            if (null !== $receiver) {
                $this->externalSyncUserManager->deleteExternalUserByUserId($receiver->getId());
            }
        }
    }
877564
public function handleRemove(RemoveEvent $event)
    {
        $document = $event->getDocument();
        if (!($document instanceof CustomUrlBehavior)) {
            return;
        }

        foreach ($this->inspector->getReferrers($document) as $referrer) {
            if ($referrer instanceof RouteBehavior) {
                $this->documentManager->remove($referrer);
            }
        }
    }
1329974
public function onDelete(DeleteResourceEvent $event)
    {
        $this->container->get('icap.website.manager')->deleteWebsite($event->getResource());
        $event->stopPropagation();
    }
384387
public function afterDelete(Event $event, EntityInterface $entity) {
		if ($this->_checkEvent($event)) {
			$event->result = $this->_deleteFile($event);
			$event->stopPropagation();
		}
	}
1085591
public function handleRemove(RemoveEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutableBehavior) {
            return;
        }

        $locales = $this->documentInspector->getLocales($document);
        foreach ($locales as $locale) {
            $localizedDocument = $this->documentManager->find($document->getUuid(), $locale);

            $route = $this->routeRepository->findByEntity(
                $localizedDocument->getClass(),
                $localizedDocument->getUuid(),
                $locale
            );
            if (!$route) {
                continue;
            }

            $this->entityManager->remove($route);

            if ($document instanceof ChildrenBehavior) {
                $this->removeChildRoutes($document, $locale);
            }
        }

        $this->entityManager->flush();
    }
372215
public function preCreate(CreateEvent $event)
    {
        /** @var Group $role */
        $group = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $group->addOrganization($user->getMainOrganization());
        }
    }
301076
public function onSerialize(DecorateUserEvent $event)
    {
        $casUserId = $this->casManager->getCasUserIdByUserId($event->getUser()->getId());

        $event->add('cas_data', [
            'id' => $casUserId,
        ]);
    }
903384
public function onContactClientDelete(ContactClientEvent $event)
    {
        $entity = $event->getContactClient();
        $log    = [
            'bundle'    => 'contactclient',
            'object'    => 'contactclient',
            'objectId'  => $entity->deletedId,
            'action'    => 'delete',
            'details'   => ['name' => $entity->getName()],
            'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
        ];
        $this->auditLogModel->writeToLog($log);
    }
216222
public function handle(UpdatedEvent $event)
    {
        // Delete sessions for user on password update
        if ($this->config->get('session.driver') === 'laranix') {
            Session::where('user_id', $event->user->id)->delete();
        }

        $this->track(Settings::TYPEID_UPDATED, $event->user->id, 50);
    }
50996
public function onDelete(DeleteResourceEvent $event)
    {
        $this->om->remove($event->getResource());
        $event->stopPropagation();
    }