/**
  * Saves the registration
  *
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
  * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator
  *
  * @return void
  */
 public function saveRegistrationAction(Registration $registration, Event $event)
 {
     $autoConfirmation = (bool) $this->settings['registration']['autoConfirmation'];
     $result = RegistrationResult::REGISTRATION_SUCCESSFUL;
     $success = $this->registrationService->checkRegistrationSuccess($event, $registration, $result);
     // Save registration if no errors
     if ($success) {
         $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration($event, $registration->getAmountOfRegistrations());
         $linkValidity = (int) $this->settings['confirmation']['linkValidity'];
         if ($linkValidity === 0) {
             // Use 3600 seconds as default value if not set
             $linkValidity = 3600;
         }
         $confirmationUntil = new \DateTime();
         $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S'));
         $registration->setEvent($event);
         $registration->setPid($event->getPid());
         $registration->setConfirmationUntil($confirmationUntil);
         $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']);
         $registration->setFeUser($this->registrationService->getCurrentFeUserObject());
         $registration->setWaitlist($isWaitlistRegistration);
         $registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid);
         $this->registrationRepository->add($registration);
         // Persist registration, so we have an UID
         $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll();
         // Add new registration (or waitlist registration) to event
         if ($isWaitlistRegistration) {
             $event->addRegistrationWaitlist($registration);
             $messageType = MessageType::REGISTRATION_WAITLIST_NEW;
         } else {
             $event->addRegistration($registration);
             $messageType = MessageType::REGISTRATION_NEW;
         }
         $this->eventRepository->update($event);
         // Send notifications to user and admin if confirmation link should be sent
         if (!$autoConfirmation) {
             $this->notificationService->sendUserMessage($event, $registration, $this->settings, $messageType);
             $this->notificationService->sendAdminMessage($event, $registration, $this->settings, $messageType);
         }
         // Create given amount of registrations if necessary
         if ($registration->getAmountOfRegistrations() > 1) {
             $this->registrationService->createDependingRegistrations($registration);
         }
         // Clear cache for configured pages
         $this->utilityService->clearCacheForConfiguredUids($this->settings);
     }
     if ($autoConfirmation && $success) {
         $this->redirect('confirmRegistration', null, null, ['reguid' => $registration->getUid(), 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid())]);
     } else {
         $this->redirect('saveRegistrationResult', null, null, ['result' => $result]);
     }
 }