Last active
December 7, 2022 10:40
-
-
Save gggeek/b01e76694319888a97cdf56cb084662d to your computer and use it in GitHub Desktop.
A symfony command for eZPublish 5 that lists all available Legacy command-line scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\AppBundle\Command; | |
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class ListLegacyScriptsCommand extends ContainerAwareCommand | |
{ | |
protected function configure() | |
{ | |
$this | |
->setName('acme:app:list_legacy_scripts') | |
->setDescription("Lists all available legacy scripts (php ones)") | |
; | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
// quick and dirty... | |
exec("cd ezpublish_legacy && find -L bin/php -type f -name '*.php'", $binScripts, $retCode); | |
exec ("cd ezpublish_legacy && find -L extension/ -type f -path 'extension/*/bin/*' -name '*.php'", $extScripts, $retCode); | |
sort($extScripts); | |
$out = array(); | |
$maxlen = 0; | |
foreach(array_merge($binScripts, $extScripts) as $script) { | |
$code = file_get_contents('ezpublish_legacy/'.$script); | |
if (strpos($script, 'bin/php') === 0) { | |
$ext = 'kernel'; | |
} else { | |
preg_match('#extension/([^/]+)/#', $script, $matches); | |
$ext = $matches[1]; | |
} | |
$out[$ext][$script] = ''; | |
/// @todo use a better parser than this... | |
if (preg_match('/(?:\$scriptSettings *\[ *)?[\'"]description[\'"](?: *\])? *=>? *\(? *[\'"](.*)[\'"]/', $code, $matches)) { | |
$out[$ext][$script] = trim(str_replace(array("\n", '\n'), ' ', $matches[1])); | |
$maxlen = (strlen($script) > $maxlen) ? strlen($script) : $maxlen; | |
} | |
} | |
$output->writeln(''); | |
$output->writeln('<comment>Available commands:</comment>'); | |
foreach ($out as $ext => $scripts) { | |
$output->writeln("<comment>$ext</comment>"); | |
foreach ($scripts as $name => $desc) { | |
$output->writeln(' ' . "<info>$name</info>" . str_repeat(' ', $maxlen - strlen($name) + 1) . $desc); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment