|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace IchHabRecht\MaskExport\Command; |
| 6 | + |
| 7 | +use IchHabRecht\MaskExport\Controller\ExportController; |
| 8 | +use Symfony\Component\Console\Command\Command; |
| 9 | +use Symfony\Component\Console\Input\InputArgument; |
| 10 | +use Symfony\Component\Console\Input\InputInterface; |
| 11 | +use Symfony\Component\Console\Output\OutputInterface; |
| 12 | +use TYPO3\CMS\Core\Core\Bootstrap; |
| 13 | +use TYPO3\CMS\Core\Utility\GeneralUtility; |
| 14 | +use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException; |
| 15 | +use TYPO3\CMS\Extbase\Mvc\Request; |
| 16 | +use TYPO3\CMS\Extensionmanager\Domain\Model\Extension; |
| 17 | + |
| 18 | +/* |
| 19 | + * This file is part of the TYPO3 extension mask_export. |
| 20 | + * |
| 21 | + * (c) 2016 Nicole Cordes <[email protected]>, CPS-IT GmbH |
| 22 | + * |
| 23 | + * It is free software; you can redistribute it and/or modify it under |
| 24 | + * the terms of the GNU General Public License, either version 2 |
| 25 | + * of the License, or any later version. |
| 26 | + * |
| 27 | + * For the full copyright and license information, please read the |
| 28 | + * LICENSE file that was distributed with this source code. |
| 29 | + */ |
| 30 | + |
| 31 | +/** |
| 32 | + * This class provides a CLI command for exporting the mask elements |
| 33 | + */ |
| 34 | +class ExportCommand extends Command |
| 35 | +{ |
| 36 | + protected function configure(): void |
| 37 | + { |
| 38 | + $this |
| 39 | + ->setHelp('Export all mask elements') |
| 40 | + ->addArgument( |
| 41 | + 'vendorName', |
| 42 | + InputArgument::REQUIRED, |
| 43 | + 'Vendor name for the new extension' |
| 44 | + ) |
| 45 | + ->addArgument( |
| 46 | + 'extensionName', |
| 47 | + InputArgument::REQUIRED, |
| 48 | + 'Extension name for the new extension' |
| 49 | + ) |
| 50 | + ->addArgument( |
| 51 | + 'path', |
| 52 | + InputArgument::OPTIONAL, |
| 53 | + 'Path for the extension to be written. Defaults to the usual extension path.' |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @param InputInterface $input |
| 59 | + * @param OutputInterface $output |
| 60 | + * @return int |
| 61 | + */ |
| 62 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 63 | + { |
| 64 | + ['path' => $path, 'extensionName' => $extensionName, 'vendorName' => $vendorName] = $input->getArguments(); |
| 65 | + GeneralUtility::setIndpEnv('TYPO3_REQUEST_URL', ''); |
| 66 | + Bootstrap::initializeBackendUser(); |
| 67 | + |
| 68 | + $request = GeneralUtility::makeInstance(Request::class); |
| 69 | + $request->setControllerName('Export'); |
| 70 | + $request->setControllerActionName('install'); |
| 71 | + $request->setArguments([ |
| 72 | + 'vendorName' => $input->getArgument('vendorName'), |
| 73 | + 'extensionName' => $input->getArgument('extensionName'), |
| 74 | + 'elements' => [], |
| 75 | + ]); |
| 76 | + if ($path) { |
| 77 | + $request->setArgument('path', $path . '/'); |
| 78 | + } |
| 79 | + |
| 80 | + $controller = GeneralUtility::makeInstance(ExportController::class); |
| 81 | + $elements = $controller->getAvailableElements(); |
| 82 | + $GLOBALS['BE_USER']->uc['mask_export'] = [ |
| 83 | + 'vendorName' => $vendorName, |
| 84 | + 'extensionName' => $extensionName, |
| 85 | + 'elements' => implode(',', array_keys($elements)), |
| 86 | + ]; |
| 87 | + try { |
| 88 | + $controller->processRequest($request); |
| 89 | + } catch (StopActionException $e) { |
| 90 | + // Ignore this Exception because it is for web requests only |
| 91 | + } |
| 92 | + $output->writeln(sprintf( |
| 93 | + 'Extension written to %s%s', |
| 94 | + $path ? realpath($path) . '/' : Extension::returnInstallPaths()['Local'], |
| 95 | + $input->getArgument('extensionName') |
| 96 | + )); |
| 97 | + |
| 98 | + return Command::SUCCESS; |
| 99 | + } |
| 100 | +} |
0 commit comments