Skip to content

Commit

Permalink
[TASK] Ensure, TYPO3 is not running in CLI mode
Browse files Browse the repository at this point in the history
As the method deleteGlossary is called both in backend and CLI context,
the Exception should be thrown in CLI context, but generate a
FlashMessage in backend context.
  • Loading branch information
calien666 committed Apr 28, 2023
1 parent 3a8587c commit ecc2d3d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Classes/Service/DeeplGlossaryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -155,7 +156,7 @@ public function createGlossary(
*
* @throws DeepLException
*/
public function deleteGlossary(string $glossaryId)
public function deleteGlossary(string $glossaryId): ?array
{
$url = $this->client->buildBaseUrl(self::API_URL_SUFFIX_GLOSSARIES);
$url .= "/$glossaryId";
Expand All @@ -164,17 +165,22 @@ public function deleteGlossary(string $glossaryId)
$this->client->request($url, '', 'DELETE');
} catch (BadResponseException $e) {
// FlashMessage($message, $title, $severity = self::OK, $storeInSession)
$message = GeneralUtility::makeInstance(
FlashMessage::class,
$e->getMessage(),
'DeepL Api',
FlashMessage::WARNING,
true
);
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$messageQueue = $flashMessageService->getMessageQueueByIdentifier();
$messageQueue->addMessage($message);
if (Environment::isCli()) {
throw $e;
}else {
$message = GeneralUtility::makeInstance(
FlashMessage::class,
$e->getMessage(),
'DeepL Api',
FlashMessage::WARNING,
true
);
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$messageQueue = $flashMessageService->getMessageQueueByIdentifier();
$messageQueue->addMessage($message);
}
}
return null;
}

/**
Expand Down

0 comments on commit ecc2d3d

Please sign in to comment.