FEATURE: Provide cli to generate migration commands

* Provide symfony cli app to generate migration for filesystem and sql.
This commit is contained in:
Daniel Siepmann 2017-05-16 10:20:56 +02:00
parent 413d8e45f5
commit 7b23a82adc
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 119 additions and 2 deletions

View file

@ -16,7 +16,8 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Typo3Update\\": "src/Standards/Typo3Update/" "Typo3Update\\": "src/Standards/Typo3Update/",
"Typo3Update\\CommandLine\\": "src/CommandLine/"
}, },
"files": [ "files": [
"src/CodeSniffer/Tokenizers/TypoScript.php" "src/CodeSniffer/Tokenizers/TypoScript.php"
@ -27,11 +28,12 @@
"helmich/typo3-typoscript-parser": "1.1.*", "helmich/typo3-typoscript-parser": "1.1.*",
"squizlabs/php_codesniffer": "2.8.*", "squizlabs/php_codesniffer": "2.8.*",
"symfony/yaml": "3.2.*", "symfony/yaml": "3.2.*",
"symfony/finder": "3.2.*",
"symfony/console": "3.2.*",
"higidi/composer-phpcodesniffer-standards-plugin": "*" "higidi/composer-phpcodesniffer-standards-plugin": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "5.7.*", "phpunit/phpunit": "5.7.*",
"symfony/finder": "3.2.*",
"phpmd/phpmd": "2.6.*", "phpmd/phpmd": "2.6.*",
"pdepend/pdepend": "2.5.*" "pdepend/pdepend": "2.5.*"
} }

16
src/CommandLine/App.php Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/../../vendor/autoload.php';
use Symfony\Component\Console\Application;
use Typo3Update\CommandLine\Commands\Fluid\ReplaceNameSpaceImport;
call_user_func(function () {
$application = new Application();
$command = new ReplaceNameSpaceImport();
$application->add($command);
$application->setDefaultCommand($command->getName(), true);
$application->run();
});

View file

@ -0,0 +1,99 @@
<?php
namespace Typo3Update\CommandLine\Commands\Fluid;
/*
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
/**
*
*/
class ReplaceNameSpaceImport extends Command
{
protected $input;
protected $output;
protected function configure()
{
$this->setName('Typo3Update:generateReplaceNamespaceImports')
->setDescription('Will dump command to replace Namespace imports in Fluid.')
->setHelp('Replaces =Tx_ExtName_ViewHelpers with =\Vendor\ExtName\ViewHelpers. SQL is provided as some might have fluid in their database.')
->addArgument('documentRoot', InputArgument::REQUIRED, 'The document root containing TYPO3 installation.')
->addArgument('vendor', InputArgument::REQUIRED, 'Namespace vendor to use.')
->addOption('hide-cli', null, InputOption::VALUE_OPTIONAL, 'Do not display cli command output.', false)
->addOption('hide-sql', null, InputOption::VALUE_OPTIONAL, 'Do not display sql query output.', false)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
foreach ($this->getExtensionKeys($input->getArgument('documentRoot')) as $extKey) {
$this->migrateExtension($extKey, $input->getArgument('vendor'));
}
}
protected function migrateExtension($extKey, $vendor)
{
$extName = implode('', array_map('ucfirst', explode('_', $extKey)));
if ($this->output->isVerbose()) {
$this->output->writeln("<info>Processing: $extName</info>");
}
if ($this->input->getOption('hide-cli') == false) {
$this->output->writeln("LC_ALL=C sed -i '' 's#Tx_{$extName}_ViewHelpers#{$vendor}\\\\{$extName}\\\\ViewHelpers#' `ag 'Tx_{$extName}_ViewHelpers' --html -l`;");
}
if ($this->input->getOption('hide-sql') == false) {
$this->output->writeln("UPDATE tt_content SET bodytext = replace(bodytext, 'Tx_{$extName}_ViewHelpers', '{$vendor}\\{$extName}\\ViewHelpers') WHERE bodytext LIKE '%Tx_{$extName}_ViewHelpers%';");
}
}
protected function getExtensionKeys($documentRoot)
{
$finder = new Finder();
$folders = $finder->directories()
->depth('==0')
->in($this->getTypo3ConfFolder($documentRoot))
;
foreach ($folders as $folder) {
yield $folder->getRelativePathname();
}
}
protected function getTypo3ConfFolder($documentRoot)
{
$confFolder = $documentRoot . DIRECTORY_SEPARATOR . 'typo3conf' . DIRECTORY_SEPARATOR . 'ext';
if (is_dir($confFolder)) {
return $confFolder;
}
throw new \Exception('typo3conf/ext folder coult not be found in document root "' . $documentRoot . '"', 1494920027);
}
}