diff --git a/Classes/Command/ExportCommand.php b/Classes/Command/ExportCommand.php new file mode 100644 index 0000000..a6b33c1 --- /dev/null +++ b/Classes/Command/ExportCommand.php @@ -0,0 +1,100 @@ +, CPS-IT GmbH + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE file that was distributed with this source code. + */ + +/** + * This class provides a CLI command for exporting the mask elements + */ +class ExportCommand extends Command +{ + protected function configure(): void + { + $this + ->setHelp('Export all mask elements') + ->addArgument( + 'vendorName', + InputArgument::REQUIRED, + 'Vendor name for the new extension' + ) + ->addArgument( + 'extensionName', + InputArgument::REQUIRED, + 'Extension name for the new extension' + ) + ->addArgument( + 'path', + InputArgument::OPTIONAL, + 'Path for the extension to be written. Defaults to the usual extension path.' + ); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int + { + ['path' => $path, 'extensionName' => $extensionName, 'vendorName' => $vendorName] = $input->getArguments(); + GeneralUtility::setIndpEnv('TYPO3_REQUEST_URL', ''); + Bootstrap::initializeBackendUser(); + + $request = GeneralUtility::makeInstance(Request::class); + $request->setControllerName('Export'); + $request->setControllerActionName('install'); + $request->setArguments([ + 'vendorName' => $input->getArgument('vendorName'), + 'extensionName' => $input->getArgument('extensionName'), + 'elements' => [], + ]); + if ($path) { + $request->setArgument('path', $path . '/'); + } + + $controller = GeneralUtility::makeInstance(ExportController::class); + $elements = $controller->getAvailableElements(); + $GLOBALS['BE_USER']->uc['mask_export'] = [ + 'vendorName' => $vendorName, + 'extensionName' => $extensionName, + 'elements' => implode(',', array_keys($elements)), + ]; + try { + $controller->processRequest($request); + } catch (StopActionException $e) { + // Ignore this Exception because it is for web requests only + } + $output->writeln(sprintf( + 'Extension written to %s%s', + $path ? realpath($path) . '/' : Extension::returnInstallPaths()['Local'], + $input->getArgument('extensionName') + )); + + return Command::SUCCESS; + } +} diff --git a/Classes/Controller/ExportController.php b/Classes/Controller/ExportController.php index 2bbfef9..e0969f4 100644 --- a/Classes/Controller/ExportController.php +++ b/Classes/Controller/ExportController.php @@ -178,15 +178,20 @@ public function downloadAction($vendorName, $extensionName, $elements) * @param string $vendorName * @param string $extensionName * @param array $elements + * @param string $path */ - public function installAction($vendorName, $extensionName, $elements) + public function installAction($vendorName, $extensionName, $elements, $path = null) { $paths = Extension::returnInstallPaths(); if (empty($paths['Local']) || !file_exists($paths['Local'])) { throw new \RuntimeException('Local extension install path is missing', 1500061028); } - $extensionPath = $paths['Local'] . $extensionName; + if (!$path) { + $path = $paths['Local']; + } + + $extensionPath = $path . $extensionName; $files = $this->getFiles($vendorName, $extensionName, $elements); $this->writeExtensionFilesToPath($files, $extensionPath); @@ -290,6 +295,14 @@ protected function getElements() return $elements; } + /** + * @return array + */ + public function getAvailableElements() + { + return $this->maskConfiguration['tt_content']['elements'] ?? []; + } + /** * @param string $vendorName * @param string $extensionName diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..cc8d422 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,14 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + IchHabRecht\MaskExport\: + resource: '../Classes/*' + + IchHabRecht\MaskExport\Command\ExportCommand: + tags: + - name: console.command + command: 'mask:export' + description: 'Export all mask elements' diff --git a/README.md b/README.md index a0737b2..2164b92 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,15 @@ Simply install mask and mask_export with Composer or the Extension Manager. ## Usage +### Backend - use the mask wizard to configure own content elements - change to tab "Code Export" - if you like change the extension key, the default one is *my_mask_export* - either install or download your extension +### CLI +./vendor/bin/typo3 mask:export MyVendor my_extension_name [save_path] + ## Best practise It is recommended to **not touch** the generated export extension. @@ -57,7 +61,7 @@ You can find some common configuration in the [my_maskexport_sitepackage](https: example site package. Furthermore you can refer to the slides [CCE (Custom Content Elements) - Best Practice ](https://de.slideshare.net/cpsitgmbh/cce-custom-content-elements-best-practice) -for additional information. +for additional information. ## Community