From 135faf496becf94ec550dc05e165d6809dab7c86 Mon Sep 17 00:00:00 2001 From: Christine Zoglmeier Date: Mon, 6 Nov 2023 09:14:29 +0100 Subject: [PATCH] [WIP] Check for TYPO3 context in command controllers resolves: https://projekte.in2code.de/issues/48026 --- Classes/Command/Foreign/Status/AllCommand.php | 7 ++++++ .../Typo3Context/Typo3ContextService.php | 21 +++++++++++++++++ .../Typo3ContextServiceInjection.php | 23 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 Classes/Service/Typo3Context/Typo3ContextService.php create mode 100644 Classes/Service/Typo3Context/Typo3ContextServiceInjection.php diff --git a/Classes/Command/Foreign/Status/AllCommand.php b/Classes/Command/Foreign/Status/AllCommand.php index ab2ab2af6..28b246c95 100644 --- a/Classes/Command/Foreign/Status/AllCommand.php +++ b/Classes/Command/Foreign/Status/AllCommand.php @@ -29,6 +29,7 @@ * This copyright notice MUST APPEAR in all copies of the script! */ +use In2code\In2publishCore\Testing\Service\Typo3ContextServiceInjection; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -36,6 +37,8 @@ class AllCommand extends Command { + use Typo3ContextServiceInjection; + public const IDENTIFIER = 'in2publish_core:status:all'; protected CommandRegistry $cmdRegistry; @@ -50,6 +53,10 @@ public function injectCommandRegistry(CommandRegistry $commandRegistry): void protected function execute(InputInterface $input, OutputInterface $output): int { + if ($this->typo3ContextService->isCliOrBackendEnvironment()) { + $output->writeln('This command is only available in backend or CLI context'); + return Command::FAILURE; + } $this->cmdRegistry->getCommandByIdentifier(VersionCommand::IDENTIFIER)->execute($input, $output); $this->cmdRegistry->getCommandByIdentifier(CreateMasksCommand::IDENTIFIER)->execute($input, $output); $this->cmdRegistry->getCommandByIdentifier(GlobalConfigurationCommand::IDENTIFIER)->execute($input, $output); diff --git a/Classes/Service/Typo3Context/Typo3ContextService.php b/Classes/Service/Typo3Context/Typo3ContextService.php new file mode 100644 index 000000000..33c2142a1 --- /dev/null +++ b/Classes/Service/Typo3Context/Typo3ContextService.php @@ -0,0 +1,21 @@ +isBackend(); + } +} + diff --git a/Classes/Service/Typo3Context/Typo3ContextServiceInjection.php b/Classes/Service/Typo3Context/Typo3ContextServiceInjection.php new file mode 100644 index 000000000..3b3fa8ac9 --- /dev/null +++ b/Classes/Service/Typo3Context/Typo3ContextServiceInjection.php @@ -0,0 +1,23 @@ +typo3ContextService = $typo3ContextService; + } +}