Skip to content
Snippets Groups Projects
Commit ff8dff63 authored by Sergiu-Lucian Petrica's avatar Sergiu-Lucian Petrica
Browse files

Implemented redirection to form when exception is thrown, with a generic error...

Implemented redirection to form when exception is thrown, with a generic error showing to the user + logging error message
parent 79a04105
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ namespace SGalinski\SgJobs\Controller; ...@@ -28,7 +28,7 @@ namespace SGalinski\SgJobs\Controller;
use SGalinski\SgJobs\Domain\Model\JobApplication; use SGalinski\SgJobs\Domain\Model\JobApplication;
use SGalinski\SgMail\Service\MailTemplateService; use SGalinski\SgMail\Service\MailTemplateService;
use TYPO3\CMS\Core\Messaging\FlashMessage; use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Resource\DuplicationBehavior; use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility; use TYPO3\CMS\Core\Utility\File\ExtendedFileUtility;
...@@ -92,13 +92,20 @@ class JoblistController extends ActionController { ...@@ -92,13 +92,20 @@ class JoblistController extends ActionController {
* Renders the application form with an optional job * Renders the application form with an optional job
* *
* @param JobApplication $applyData * @param JobApplication $applyData
* @param string $error
*/ */
public function applyFormAction(JobApplication $applyData = NULL) { public function applyFormAction(JobApplication $applyData = NULL, $error = NULL) {
if ($this->request->getOriginalRequest()) { if ($this->request->getOriginalRequest()) {
$uploadedFiles = $this->request->getOriginalRequest()->getArguments()['uploadedFiles']; $uploadedFiles = $this->request->getOriginalRequest()->getArguments()['uploadedFiles'];
$this->view->assign('uploadedFiles', $uploadedFiles); $this->view->assign('uploadedFiles', $uploadedFiles);
} }
if ($error !== NULL) {
$logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
$logger->log(LogLevel::ALERT, $error, $applyData);
$this->view->assign('error', 1);
}
$jobId = $this->request->getArguments()['jobData']['uid']; $jobId = $this->request->getArguments()['jobData']['uid'];
if (!empty($jobId)) { if (!empty($jobId)) {
$jobData = $this->jobRepository->findByUid($jobId); $jobData = $this->jobRepository->findByUid($jobId);
...@@ -146,11 +153,9 @@ class JoblistController extends ActionController { ...@@ -146,11 +153,9 @@ class JoblistController extends ActionController {
->setTargetPageUid($redirectPageId) ->setTargetPageUid($redirectPageId)
->build(); ->build();
$this->redirectToUri($uri); $this->redirectToUri($uri);
} catch (\Exception $exception) { } catch (\Exception $exception) {
// possible errors, because of wrong mails (maybe log that somewhere? Does this makes sense?) // possible errors, because of wrong mails (maybe log that somewhere? Does this makes sense?)
GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage()); $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
$this->redirect('applyFormAction');
} }
} }
...@@ -178,8 +183,7 @@ class JoblistController extends ActionController { ...@@ -178,8 +183,7 @@ class JoblistController extends ActionController {
$this->handleFileUpload('certificates', $uniqueFolderName); $this->handleFileUpload('certificates', $uniqueFolderName);
} catch (\Exception $exception) { } catch (\Exception $exception) {
// possible errors, because of wrong mails // possible errors, because of wrong mails
GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage()); $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
$this->redirect('applyFormAction');
} }
$propertyMappingConfiguration = $this->arguments->getArgument('applyData')->getPropertyMappingConfiguration(); $propertyMappingConfiguration = $this->arguments->getArgument('applyData')->getPropertyMappingConfiguration();
$propertyMappingConfiguration->forProperty('coverLetter')->allowAllProperties(); $propertyMappingConfiguration->forProperty('coverLetter')->allowAllProperties();
...@@ -363,8 +367,7 @@ class JoblistController extends ActionController { ...@@ -363,8 +367,7 @@ class JoblistController extends ActionController {
fputcsv($file, $dataToInsertArr); fputcsv($file, $dataToInsertArr);
fclose($file); fclose($file);
} catch (\RuntimeException $exception) { } catch (\RuntimeException $exception) {
GeneralUtility::makeInstance(FlashMessage::class, $exception->getMessage()); $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]);
$this->redirect('applyFormAction');
} }
} }
......
...@@ -210,6 +210,10 @@ ...@@ -210,6 +210,10 @@
<source>Female</source> <source>Female</source>
<target>Weiblich</target> <target>Weiblich</target>
</trans-unit> </trans-unit>
<trans-unit id="frontend.apply.error.general" approved="yes">
<source>An error has occured</source>
<target>Ein Fehler ist aufgetreten</target>
</trans-unit>
<trans-unit id="frontend.applyNow" approved="yes"> <trans-unit id="frontend.applyNow" approved="yes">
<source>Apply online now</source> <source>Apply online now</source>
<target>Jetzt online bewerben</target> <target>Jetzt online bewerben</target>
......
...@@ -159,6 +159,9 @@ ...@@ -159,6 +159,9 @@
<trans-unit id="frontend.apply.gender.female"> <trans-unit id="frontend.apply.gender.female">
<source>Female</source> <source>Female</source>
</trans-unit> </trans-unit>
<trans-unit id="frontend.apply.error.general">
<source>An error has occured</source>
</trans-unit>
<trans-unit id="frontend.applyNow"> <trans-unit id="frontend.applyNow">
<source>Apply online now</source> <source>Apply online now</source>
</trans-unit> </trans-unit>
......
<f:layout name="Default" /> <f:layout name="Default" />
<f:section name="main"> <f:section name="main">
<f:flashMessages />
<f:form action="apply" controller="Joblist" method="post" objectName="applyData" object="{applyData}" enctype="multipart/form-data"> <f:form action="apply" controller="Joblist" method="post" objectName="applyData" object="{applyData}" enctype="multipart/form-data">
<f:if condition="{error}">
<div class="errormessage">
<f:translate key="frontend.apply.error.general" />
</div>
</f:if>
<f:if condition="{job}"> <f:if condition="{job}">
<f:form.hidden value="{job.jobId}" property="jobId" /> <f:form.hidden value="{job.jobId}" property="jobId" />
<label for="apply-title"><f:translate key="frontend.apply.title" /></label> <label for="apply-title"><f:translate key="frontend.apply.title" /></label>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment