From a5ef7b3ed5488dde84dd9cc8ec47a1a5a038b991 Mon Sep 17 00:00:00 2001 From: Mathias Bolt Lesniak Date: Tue, 6 Apr 2021 11:55:43 +0200 Subject: [PATCH] [BUGFIX] Fix missing file and installation instructions (#4) --- Classes/Controller/SelectorController.php | 91 +++++++++++++++++++++++ README.md | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Classes/Controller/SelectorController.php diff --git a/Classes/Controller/SelectorController.php b/Classes/Controller/SelectorController.php new file mode 100644 index 0000000..1db2085 --- /dev/null +++ b/Classes/Controller/SelectorController.php @@ -0,0 +1,91 @@ +qbankService = $qbankService; + } + + /** + * Downloads a file to TYPO3's local filesystem (if it doesn't already exist) and returns the file UID. + * + * If the file aleady exists, the UID of the existing file is returned. + * + * @param ServerRequestInterface $request + * @param ResponseInterface $response + * @return ResponseInterface + */ + public function downloadFileAction(ServerRequestInterface $request): JsonResponse + { + $mediaId = (int)$request->getParsedBody()['mediaId']; + + if ($mediaId === 0) { + return $this->getErrorResponse( + LocalizationUtility::translate('download_file.error.zero_media_identifier', 'qbank') + ); + } + + $file = $this->qbankService->createLocalMediaCopy($mediaId); + + $response = $this->getSuccessResponse(['fileUid' => $file->getUid()]); + + return $response; + } + + /** + * Returns an error response object with message set. + * + * @param string $message + * @return JsonResponse + */ + protected function getErrorResponse(string $message): JsonResponse + { + return GeneralUtility::makeInstance(JsonResponse::class) + ->withStatus( + 500, + $message + ) + ->setPayload([ + 'success' => false, + 'message' => $message, + ]); + } + + /** + * Returns a success response object with message set. + * + * @param string $message + * @return JsonResponse + */ + protected function getSuccessResponse(array $data): JsonResponse + { + $data['success'] = true; + + return GeneralUtility::makeInstance(JsonResponse::class) + ->withStatus(200) + ->setPayload($data); + } +} diff --git a/README.md b/README.md index 11cbe5f..07725ee 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Installation 1. Install the extension using Composer: `composer req pixelant/qbank` -2. Activate the extension in TYPO3 by using the _Admin Tools > Extensions_ module or by running `vendor/bin/typo3 extension:activate qbank` in the command line. +2. Activate the extension in TYPO3 by using the _Admin Tools > Extensions_ module or by running `vendor/bin/typo3 extension:activate qbank; vendor/bin/typo3cms database:updateschema` in the command line. ## Configuration