/**
  * Executes this finisher
  * @see AbstractFinisher::execute()
  *
  * @return void
  * @throws \TYPO3\Form\Exception\FinisherException
  */
 protected function executeInternal()
 {
     $messageBody = $this->parseOption('messageBody');
     if (!is_string($messageBody)) {
         throw new \TYPO3\Form\Exception\FinisherException(sprintf('The message body must be of type string, "%s" given.', gettype($messageBody)), 1335980069);
     }
     $messageTitle = $this->parseOption('messageTitle');
     $messageArguments = $this->parseOption('messageArguments');
     $messageCode = $this->parseOption('messageCode');
     $severity = $this->parseOption('severity');
     switch ($severity) {
         case Message::SEVERITY_NOTICE:
             $message = new \TYPO3\Flow\Error\Notice($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
         case Message::SEVERITY_WARNING:
             $message = new \TYPO3\Flow\Error\Warning($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
         case Message::SEVERITY_ERROR:
             $message = new \TYPO3\Flow\Error\Error($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
         default:
             $message = new Message($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
     }
     $this->flashMessageContainer->addMessage($message);
 }
 /**
  * Executes this finisher
  * @see AbstractFinisher::execute()
  *
  * @return void
  * @throws \TYPO3\Flow\Mvc\Exception\StopActionException();
  */
 protected function executeInternal()
 {
     /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */
     $formRuntime = $this->finisherContext->getFormRuntime();
     $formValueArray = $formRuntime->getFormState()->getFormValues();
     /** @var \GIB\GradingTool\Domain\Model\Project $project */
     $project = $this->projectRepository->findByIdentifier($formRuntime->getRequest()->getParentRequest()->getArgument('project'));
     // store changes to project
     $project->setProjectData($formValueArray);
     $this->projectRepository->update($project);
     // add a flash message
     $message = new \TYPO3\Flow\Error\Message('The project data for "%s" was successfully edited.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($project->getProjectTitle()));
     $this->flashMessageContainer->addMessage($message);
     $this->persistenceManager->persistAll();
     // redirect to dashboard
     $formRuntime = $this->finisherContext->getFormRuntime();
     $request = $formRuntime->getRequest()->getMainRequest();
     $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
     $uriBuilder->setRequest($request);
     $uriBuilder->reset();
     $uri = $uriBuilder->uriFor('index', NULL, 'Admin');
     $response = $formRuntime->getResponse();
     $mainResponse = $response;
     while ($response = $response->getParentResponse()) {
         $mainResponse = $response;
     }
     $mainResponse->setStatus(303);
     $mainResponse->setHeader('Location', (string) $uri);
     throw new \TYPO3\Flow\Mvc\Exception\StopActionException();
 }
 /**
  * @test
  * @dataProvider renderDataProvider()
  * @param string $expectedResult
  * @param array $flashMessages
  * @param string $class
  * @return void
  */
 public function renderTests($expectedResult, array $flashMessages = array(), $class = NULL)
 {
     $this->mockFlashMessageContainer->expects($this->once())->method('getMessagesAndFlush')->will($this->returnValue($flashMessages));
     $this->mockTagBuilder->expects($this->once())->method('setContent')->with($expectedResult);
     if ($class !== NULL) {
         $this->viewHelper->_set('arguments', array('class' => $class));
     }
     $this->viewHelper->render();
 }
 /**
  * Executes this finisher
  * @see AbstractFinisher::execute()
  *
  * @return void
  * @throws \TYPO3\Flow\Mvc\Exception\StopActionException();
  */
 protected function executeInternal()
 {
     /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */
     $formRuntime = $this->finisherContext->getFormRuntime();
     $formValueArray = $formRuntime->getFormState()->getFormValues();
     if ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'edit') {
         // we need to update the template
         /** @var \GIB\GradingTool\Domain\Model\Template $template */
         $template = $this->templateRepository->findByIdentifier($formRuntime->getRequest()->getParentRequest()->getArgument('template')['__identity']);
         $template->setTemplateIdentifier($formValueArray['templateIdentifier']);
         $template->setContent(serialize($formValueArray));
         //$project->setLastUpdated(new \TYPO3\Flow\Utility\Now);
         $this->templateRepository->update($template);
         // add a flash message
         $message = new \TYPO3\Flow\Error\Message('The template "%s" was successfully edited.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($template->getTemplateIdentifier()));
         $this->flashMessageContainer->addMessage($message);
     } else {
         // we need to add a new template
         /** @var \GIB\GradingTool\Domain\Model\Template $template */
         $template = new \GIB\GradingTool\Domain\Model\Template();
         $template->setTemplateIdentifier($formValueArray['templateIdentifier']);
         // serialize all form content and store it
         $template->setContent(serialize($formValueArray));
         //$project->setCreated(new \TYPO3\Flow\Utility\Now);
         $this->templateRepository->add($template);
         // add a flash message
         $message = new \TYPO3\Flow\Error\Message('The template "%s" was successfully created.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($formValueArray['templateIdentifier']));
         $this->flashMessageContainer->addMessage($message);
     }
     $this->persistenceManager->persistAll();
     // redirect to dashboard
     $formRuntime = $this->finisherContext->getFormRuntime();
     $request = $formRuntime->getRequest()->getMainRequest();
     $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
     $uriBuilder->setRequest($request);
     $uriBuilder->reset();
     $uri = $uriBuilder->uriFor('list', NULL, 'Template');
     $response = $formRuntime->getResponse();
     $mainResponse = $response;
     while ($response = $response->getParentResponse()) {
         $mainResponse = $response;
     }
     $mainResponse->setStatus(303);
     $mainResponse->setHeader('Location', (string) $uri);
     throw new \TYPO3\Flow\Mvc\Exception\StopActionException();
 }
 /**
  * @test
  */
 public function getMessagesAndFlushCanAlsoFilterBySeverity()
 {
     $messages = array(0 => new Notice('This is a test message', 1), 1 => new Warning('This is another test message', 2));
     $this->flashMessageContainer->addMessage($messages[0]);
     $this->flashMessageContainer->addMessage($messages[1]);
     $filteredFlashMessages = $this->flashMessageContainer->getMessagesAndFlush(Message::SEVERITY_NOTICE);
     $this->assertEquals(count($filteredFlashMessages), 1);
     reset($filteredFlashMessages);
     $flashMessage = current($filteredFlashMessages);
     $this->assertEquals($messages[0], $flashMessage);
     $this->assertEquals(array(), $this->flashMessageContainer->getMessages(Message::SEVERITY_NOTICE));
     $this->assertEquals(array($messages[1]), array_values($this->flashMessageContainer->getMessages()));
 }
 /**
  * If Site Packages already exist and are active, we will deactivate them in order to prevent
  * interactions with the newly created or imported package (like Content Dimensions being used).
  *
  * @param string $packageKey
  * @return array
  */
 protected function deactivateOtherSitePackages($packageKey)
 {
     $sitePackagesToDeactivate = $this->packageManager->getFilteredPackages('active', NULL, 'typo3-flow-site');
     $deactivatedSitePackages = array();
     foreach ($sitePackagesToDeactivate as $sitePackageToDeactivate) {
         if ($sitePackageToDeactivate->getPackageKey() !== $packageKey) {
             $this->packageManager->deactivatePackage($sitePackageToDeactivate->getPackageKey());
             $deactivatedSitePackages[] = $sitePackageToDeactivate->getPackageKey();
         }
     }
     if (count($deactivatedSitePackages) >= 1) {
         $this->flashMessageContainer->addMessage(new Message(sprintf('The existing Site Packages "%s" were deactivated, in order to prevent interactions with the newly created package "%s".', implode(', ', $deactivatedSitePackages), $packageKey)));
     }
 }
 /**
  * Executes this finisher
  * @see AbstractFinisher::execute()
  *
  * @return void
  * @throws \TYPO3\Flow\Mvc\Exception\StopActionException();
  */
 protected function executeInternal()
 {
     /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */
     $formRuntime = $this->finisherContext->getFormRuntime();
     // The corresponding project
     $projectIdentifier = $formRuntime->getRequest()->getParentRequest()->getArgument('project');
     /** @var \GIB\GradingTool\Domain\Model\Project $project */
     $project = $this->projectRepository->findByIdentifier($projectIdentifier);
     $sendGradingToProjectManager = FALSE;
     if (is_null($project->getSubmissionLastUpdated())) {
         $sendGradingToProjectManager = TRUE;
     }
     // update the project with the data from the form
     $formValueArray = $formRuntime->getFormState()->getFormValues();
     $project->setSubmissionContent(serialize($formValueArray));
     $project->setSubmissionLastUpdated(new \TYPO3\Flow\Utility\Now());
     $this->projectRepository->update($project);
     $this->persistenceManager->persistAll();
     // add a flash message
     $message = new \TYPO3\Flow\Error\Message('Thank you for submitting the data for your project "%s".', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($project->getProjectTitle()));
     $this->flashMessageContainer->addMessage($message);
     // send notification mail
     $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newSubmissionNotification', $project);
     $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $project->getProjectManager());
     if ($sendGradingToProjectManager) {
         // The grading was completed for the first time, so we send the grading to the project manager
         $this->submissionService->sendGradingToProjectManager($project);
     }
     // redirect to dashboard
     $formRuntime = $this->finisherContext->getFormRuntime();
     $request = $formRuntime->getRequest()->getMainRequest();
     $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
     $uriBuilder->setRequest($request);
     $uriBuilder->reset();
     $uri = $uriBuilder->uriFor('index', NULL, 'Standard');
     $response = $formRuntime->getResponse();
     $mainResponse = $response;
     while ($response = $response->getParentResponse()) {
         $mainResponse = $response;
     }
     $mainResponse->setStatus(303);
     $mainResponse->setHeader('Location', (string) $uri);
     throw new \TYPO3\Flow\Mvc\Exception\StopActionException();
 }
 /**
  * @param string $jobIdentifier
  * @param array $options
  */
 protected function executeJob($jobIdentifier, array $options = [])
 {
     $jobConfiguration = $this->jobConfigurationRepository->findOneByIdentifier($jobIdentifier);
     try {
         $startTime = microtime(true);
         $options = new JobConfigurationOptions($options);
         if ($this->jobRunnerService->execute($jobConfiguration, $options)) {
             if ($jobConfiguration->isAsynchronous()) {
                 $this->flashMessageContainer->addMessage(new Message(sprintf('Job "%s" queued with success', $jobConfiguration->getName())));
             } else {
                 $duration = round(microtime(true) - $startTime, 2);
                 $this->flashMessageContainer->addMessage(new Message(sprintf('Job "%s" exectued with success in %s sec.', $jobConfiguration->getName(), $duration)));
             }
         }
     } catch (\Exception $exception) {
         $this->systemLogger->logException($exception);
         $this->flashMessageContainer->addMessage(new Error(sprintf('Failed to execute job "%s" with message: %s', $jobConfiguration->getName(), $exception->getMessage())));
     }
 }
 /**
  * Creates a Message object and adds it to the FlashMessageContainer.
  *
  * This method should be used to add FlashMessages rather than interacting with the container directly.
  *
  * @param string $messageBody text of the FlashMessage
  * @param string $messageTitle optional header of the FlashMessage
  * @param string $severity severity of the FlashMessage (one of the \TYPO3\Flow\Error\Message::SEVERITY_* constants)
  * @param array $messageArguments arguments to be passed to the FlashMessage
  * @param integer $messageCode
  * @return void
  * @throws \InvalidArgumentException if the message body is no string
  * @see \TYPO3\Flow\Error\Message
  * @api
  */
 public function addFlashMessage($messageBody, $messageTitle = '', $severity = Message::SEVERITY_OK, array $messageArguments = array(), $messageCode = null)
 {
     if (!is_string($messageBody)) {
         throw new \InvalidArgumentException('The message body must be of type string, "' . gettype($messageBody) . '" given.', 1243258395);
     }
     switch ($severity) {
         case Message::SEVERITY_NOTICE:
             $message = new \TYPO3\Flow\Error\Notice($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
         case Message::SEVERITY_WARNING:
             $message = new \TYPO3\Flow\Error\Warning($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
         case Message::SEVERITY_ERROR:
             $message = new \TYPO3\Flow\Error\Error($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
         default:
             $message = new Message($messageBody, $messageCode, $messageArguments, $messageTitle);
             break;
     }
     $this->flashMessageContainer->addMessage($message);
 }
 /**
  * Executes this finisher
  * @see AbstractFinisher::execute()
  *
  * @return void
  * @throws \TYPO3\Flow\Mvc\Exception\StopActionException();
  */
 protected function executeInternal()
 {
     /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */
     $formRuntime = $this->finisherContext->getFormRuntime();
     $formValueArray = $formRuntime->getFormState()->getFormValues();
     if ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'editDataSheet') {
         // we need to update the data sheet, we assume that the person is authenticated because a data sheet can only be edited by a authenticated user
         /** @var \GIB\GradingTool\Domain\Model\Project $project */
         $project = $this->projectRepository->findByIdentifier($formRuntime->getRequest()->getParentRequest()->getArgument('project'));
         // make a HTML representation of a diff of the old and new data
         $diffContent = DiffUtility::arrayDiffRecursive($project->getDataSheetContentArray(), $formValueArray);
         // store changes to project
         $project->setDataSheetContent($formValueArray);
         $project->setLastUpdated(new \TYPO3\Flow\Utility\Now());
         // update e-mail address (could have changed in the data sheet)
         $projectManagerElectronicAddress = new \TYPO3\Party\Domain\Model\ElectronicAddress();
         $projectManagerElectronicAddress->setIdentifier($formValueArray['projectManagerEmail']);
         $projectManagerElectronicAddress->setType(\TYPO3\Party\Domain\Model\ElectronicAddress::TYPE_EMAIL);
         $project->getProjectManager()->setPrimaryElectronicAddress($projectManagerElectronicAddress);
         $this->partyRepository->update($project->getProjectManager());
         $this->projectRepository->update($project);
         $this->persistenceManager->persistAll();
         // send a notification mail to the Administrator containing the changes
         $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('editDataSheetNotification', $project);
         $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, NULL, '', '', $diffContent);
         // add a flash message
         $message = new \TYPO3\Flow\Error\Message('Your data sheet for project "%s" was successfully edited.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($project->getProjectTitle()));
         $this->flashMessageContainer->addMessage($message);
     } else {
         // we need to add a new data sheet
         /** @var \GIB\GradingTool\Domain\Model\Project $project */
         $project = new \GIB\GradingTool\Domain\Model\Project();
         $project->setProjectTitle($formValueArray['projectTitle']);
         $project->setDataSheetFormIdentifier($this->settings['forms']['dataSheet']['default']);
         $project->setSubmissionFormIdentifier($this->settings['forms']['submission']['default']);
         // store identifier=userName and password for later usage
         $identifier = $formValueArray['userName'];
         $password = $formValueArray['password'];
         // remove userName and password from data array so it doesn't get saved unencrypted
         unset($formValueArray['userName']);
         unset($formValueArray['password']);
         $project->setDataSheetContent($formValueArray);
         $project->setCreated(new \TYPO3\Flow\Utility\Now());
         $this->projectRepository->add($project);
         // add a flash message
         $message = new \TYPO3\Flow\Error\Message('Your data sheet for project "%s" was successfully submitted.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($formValueArray['projectTitle']));
         $this->flashMessageContainer->addMessage($message);
         if (!$this->authenticationManager->isAuthenticated() || $this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) {
             // the product manager (supposedly) doesn't have an account yet, so we create one
             $projectManager = new \GIB\GradingTool\Domain\Model\ProjectManager();
             $projectManagerName = new \TYPO3\Party\Domain\Model\PersonName('', $formValueArray['projectManagerFirstName'], '', $formValueArray['projectManagerLastName']);
             $projectManager->setName($projectManagerName);
             $projectManagerElectronicAddress = new \TYPO3\Party\Domain\Model\ElectronicAddress();
             $projectManagerElectronicAddress->setIdentifier($formValueArray['projectManagerEmail']);
             $projectManagerElectronicAddress->setType(\TYPO3\Party\Domain\Model\ElectronicAddress::TYPE_EMAIL);
             $projectManager->addElectronicAddress($projectManagerElectronicAddress);
             $projectManager->setPrimaryElectronicAddress($projectManagerElectronicAddress);
             // add account
             $roles = array('GIB.GradingTool:ProjectManager');
             $authenticationProviderName = 'DefaultProvider';
             $account = $this->accountFactory->createAccountWithPassword($identifier, $password, $roles, $authenticationProviderName);
             $this->accountRepository->add($account);
             // add account to ProjectManager
             $projectManager->addAccount($account);
             // add project to ProjectManager
             $projectManager->addProject($project);
             // finally add the complete ProjectManager
             $this->partyRepository->add($projectManager);
             if (!$this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) {
                 // authenticate user if no Administrator is authenticated
                 $authenticationTokens = $this->securityContext->getAuthenticationTokensOfType('TYPO3\\Flow\\Security\\Authentication\\Token\\UsernamePassword');
                 if (count($authenticationTokens) === 1) {
                     $authenticationTokens[0]->setAccount($account);
                     $authenticationTokens[0]->setAuthenticationStatus(\TYPO3\Flow\Security\Authentication\TokenInterface::AUTHENTICATION_SUCCESSFUL);
                 }
                 // add a flash message
                 $message = new \TYPO3\Flow\Error\Message('The account "%s" was created and you were successfully logged in.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($identifier));
                 $this->flashMessageContainer->addMessage($message);
             }
         } elseif ($this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:ProjectManager')) {
             // a productManager is adding a new project to his account
             /** @var \GIB\GradingTool\Domain\Model\ProjectManager $projectManager */
             $projectManager = $this->authenticationManager->getSecurityContext()->getParty();
             $projectManager->addProject($project);
             $this->partyRepository->update($projectManager);
         }
         $this->persistenceManager->persistAll();
         // send notification mail to project manager (bcc to team)
         $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newDataSheetProjectManagerNotification', $project);
         $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $projectManager, $formValueArray['projectManagerFirstName'] . ' ' . $formValueArray['projectManagerLastName'], $formValueArray['projectManagerEmail']);
         // send notification mail to the GIB team
         $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newDataSheetTeamNotification', $project);
         $dataSheetArray = $this->dataSheetService->getProcessedDataSheet($project);
         $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $projectManager, '', '', $dataSheetArray);
     }
     $this->persistenceManager->persistAll();
     // redirect to dashboard
     $formRuntime = $this->finisherContext->getFormRuntime();
     $request = $formRuntime->getRequest()->getMainRequest();
     $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder();
     $uriBuilder->setRequest($request);
     $uriBuilder->reset();
     $uri = $uriBuilder->uriFor('editDatasheet', array('project' => $project), 'Project');
     $response = $formRuntime->getResponse();
     $mainResponse = $response;
     while ($response = $response->getParentResponse()) {
         $mainResponse = $response;
     }
     $mainResponse->setStatus(303);
     $mainResponse->setHeader('Location', (string) $uri);
     throw new \TYPO3\Flow\Mvc\Exception\StopActionException();
 }