Skip to content

Commit

Permalink
[FEATURE] Add export cli task
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvia Bigler committed Sep 22, 2022
1 parent 4474b20 commit f26b4f0
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 3 deletions.
100 changes: 100 additions & 0 deletions Classes/Command/ExportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

declare(strict_types=1);

namespace IchHabRecht\MaskExport\Command;

use IchHabRecht\MaskExport\Controller\ExportController;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;

/*
* This file is part of the TYPO3 extension mask_export.
*
* (c) 2016 Nicole Cordes <[email protected]>, 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;
}
}
17 changes: 15 additions & 2 deletions Classes/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -290,6 +295,14 @@ protected function getElements()
return $elements;
}

/**
* @return mixed
*/
public function getAvailableElements()
{
return $this->maskConfiguration['tt_content']['elements'];
}

/**
* @param string $vendorName
* @param string $extensionName
Expand Down
14 changes: 14 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit f26b4f0

Please sign in to comment.