diff --git a/Classes/Controller/JoblistController.php b/Classes/Controller/JoblistController.php index ce57a9cc67c23e9f8c6923d9011bc2e6aba7eed9..a85531da0045ef0d12d3cca1247f756e9ff926d4 100644 --- a/Classes/Controller/JoblistController.php +++ b/Classes/Controller/JoblistController.php @@ -417,7 +417,7 @@ class JoblistController extends ActionController { } /** - * Moves the application files from temporary to permanent storage + * Writes the application CSV file * * @param JobApplication $applicationData * @param string $folderName @@ -431,7 +431,63 @@ class JoblistController extends ActionController { $storage = $resourceFactory->getStorageObject(1); $applicationFilePath = Environment::getPublicPath() . '/' . $storage->getConfiguration()['basePath'] . 'JobApplication/' . $folderName . '/' . $newName . '.csv'; - $this->writeApplicationFile($applicationData, $applicationFilePath); + + $coverLetter = ''; + $coverLetterObject = $applicationData->getCoverLetter(); + if ($coverLetterObject) { + $coverLetterObject = $coverLetterObject->getOriginalResource(); + if ($coverLetterObject) { + $coverLetter = $coverLetterObject->getPublicUrl(); + } + } + + $cv = ''; + $cvObject = $applicationData->getCv(); + if ($cvObject) { + $cvObject = $cvObject->getOriginalResource(); + if ($cvObject) { + $cv = $cvObject->getPublicUrl(); + } + } + + $certificate = ''; + $certificateObject = $applicationData->getCertificate(); + if ($certificateObject) { + $certificateObject = $certificateObject->getOriginalResource(); + if ($certificateObject) { + $certificate = $certificateObject->getPublicUrl(); + } + } + + $dataToInsertArr = [ + $applicationData->getJobId(), + $applicationData->getFirstName(), + $applicationData->getLastName(), + $applicationData->getGender(), + $applicationData->getCountry(), + $applicationData->getBirthDate(), + $applicationData->getEducation(), + $applicationData->getStreet(), + $applicationData->getZip(), + $applicationData->getCity(), + $applicationData->getNationality(), + $applicationData->getPhone(), + $applicationData->getEmail(), + $coverLetter, + $cv, + $certificate, + $applicationData->getMessage() + ]; + + try { + GeneralUtility::mkdir_deep(\dirname($applicationFilePath)); + $file = \fopen($applicationFilePath, 'wb+'); + \fputcsv($file, $dataToInsertArr); + \fclose($file); + } catch (\RuntimeException $exception) { + $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]); + } + } /** @@ -639,71 +695,6 @@ class JoblistController extends ActionController { ]; } - /** - * Writes the application files - * - * @param JobApplication $data - * @param string $filePath - * @throws StopActionException - */ - protected function writeApplicationFile(JobApplication $data, string $filePath): void { - $coverLetter = ''; - $coverLetterObject = $data->getCoverLetter(); - if ($coverLetterObject) { - $coverLetterObject = $coverLetterObject->getOriginalResource(); - if ($coverLetterObject) { - $coverLetter = $coverLetterObject->getPublicUrl(); - } - } - - $cv = ''; - $cvObject = $data->getCv(); - if ($cvObject) { - $cvObject = $cvObject->getOriginalResource(); - if ($cvObject) { - $cv = $cvObject->getPublicUrl(); - } - } - - $certificate = ''; - $certificateObject = $data->getCertificate(); - if ($certificateObject) { - $certificateObject = $certificateObject->getOriginalResource(); - if ($certificateObject) { - $certificate = $certificateObject->getPublicUrl(); - } - } - - $dataToInsertArr = [ - $data->getJobId(), - $data->getFirstName(), - $data->getLastName(), - $data->getGender(), - $data->getCountry(), - $data->getBirthDate(), - $data->getEducation(), - $data->getStreet(), - $data->getZip(), - $data->getCity(), - $data->getNationality(), - $data->getPhone(), - $data->getEmail(), - $coverLetter, - $cv, - $certificate, - $data->getMessage() - ]; - - try { - GeneralUtility::mkdir_deep(\dirname($filePath)); - $file = \fopen($filePath, 'wb+'); - \fputcsv($file, $dataToInsertArr); - \fclose($file); - } catch (\RuntimeException $exception) { - $this->redirect('applyForm', NULL, NULL, ['error' => $exception->getMessage()]); - } - } - /** * Move the temp folder to its proper location * @@ -722,7 +713,7 @@ class JoblistController extends ActionController { /** @var ResourceFactory $resourceFactory */ $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); - $storage = $resourceFactory->getStorageObject(1); + $storage = $resourceFactory->getStorageObject(1); // fileadmin $newFolder = $tempFolder = NULL; $folder = $storage->getFolder(UploadController::JOB_APPLICATION_FOLDER); @@ -774,7 +765,7 @@ class JoblistController extends ActionController { } $usableFile = $storage->copyFile($usableFile, $newFolder, $newFilename); } elseif (!$newFolder->hasFile($newFilename)) { - // when we reload etc. this image might already be moved. + // when we reload, etc. this image might already be moved. /** @noinspection PhpUnreachableStatementInspection */ $singleFileToMove = $storage->getFileInFolder($basename, $tempFolder); $usableFile = $storage->moveFile($singleFileToMove, $newFolder, $newFilename); @@ -801,7 +792,7 @@ class JoblistController extends ActionController { } /** - * returns currently set allowedFiles + * Returns currently set allowedFiles * * @return mixed */ @@ -822,7 +813,7 @@ class JoblistController extends ActionController { $tempFolder = $storage->getFolder('/JobApplication/' . $folderName); $storage->deleteFolder($tempFolder, TRUE); } catch (\Exception $exception) { - // folder is already deleted for some reason + // the folder is already deleted for some reason } }