Exemple #1
0
 public function deleteProfile(int $profileId) : Profile
 {
     $profile = $this->getProfileById($profileId);
     $account = $profile->getAccount();
     if ($account->getProfiles()->count() === 1) {
         throw new LastProfileException('This is your last profile. Sorry you need at least one profile per account.');
     }
     $this->getEventEmitter()->emit(self::EVENT_PROFILE_DELETE, [$profile]);
     $this->profileRepository->deleteProfile($profile);
     $account->getProfiles()->removeElement($profile);
     if ($profile->isCurrent()) {
         $firstProfile = $account->getProfiles()->first();
         /** @var Profile $firstProfile */
         $this->accountService->switchToProfile($account, $firstProfile->getId());
     }
     $this->getEventEmitter()->emit(self::EVENT_PROFILE_DELETED, [$profile]);
     return $account->getCurrentProfile();
 }