Skip to content

Commit

Permalink
fixup! Fixed so that ezpublish:legacy:init script adds legacy scripts…
Browse files Browse the repository at this point in the history
… to composer.json
  • Loading branch information
vidarl committed Oct 25, 2018
1 parent e2484cd commit 89fcfce
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bundle/Command/LegacyInitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Filesystem\Filesystem;

class LegacyInitCommand extends ContainerAwareCommand
Expand Down Expand Up @@ -94,19 +95,20 @@ protected function createDirectories(InputInterface $input, OutputInterface $out

protected function updateComposeJson(OutputInterface $output)
{
$errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
$updateComposerJson = false;
$composerJson = json_decode(file_get_contents('composer.json'), true);
if ($composerJson === null) {
$output->writeln("Unable to parse composer.json");
$errOutput->writeln('Error: Unable to parse composer.json');
return;
}

if (!array_key_exists('legacy-scripts', $composerJson['scripts'])){
if (!array_key_exists('legacy-scripts', $composerJson['scripts'])) {
$legacy_scripts = [
'eZ\\Bundle\\EzPublishLegacyBundle\\Composer\\ScriptHandler::installAssets',
'eZ\\Bundle\\EzPublishLegacyBundle\\Composer\\ScriptHandler::installLegacyBundlesExtensions',
'eZ\\Bundle\\EzPublishLegacyBundle\\Composer\\ScriptHandler::generateAutoloads',
'eZ\\Bundle\\EzPublishLegacyBundle\\Composer\\ScriptHandler::symlinkLegacyFiles'
'eZ\\Bundle\\EzPublishLegacyBundle\\Composer\\ScriptHandler::symlinkLegacyFiles',
];
$composerJson['scripts'] = array_merge(['legacy-scripts' => $legacy_scripts], $composerJson['scripts']);
$updateComposerJson = true;
Expand All @@ -120,7 +122,7 @@ protected function updateComposeJson(OutputInterface $output)
$offset = array_search('@php bin/console assetic:dump', $symfonyScripts);

if ($offset === false) {
$output->writeln('Warning : Unable to find "assetic:dump" in [symfony-scripts], putting "@legacy_scripts" at the end of array');
$errOutput->writeln('Warning : Unable to find "assetic:dump" in [symfony-scripts], putting "@legacy_scripts" at the end of array');
$offset = count($symfonyScripts);
}

Expand All @@ -130,7 +132,7 @@ protected function updateComposeJson(OutputInterface $output)
}

if ($updateComposerJson) {
file_put_contents('composer.json',json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL);
file_put_contents('composer.json', json_encode($composerJson, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL);
}
}
}

0 comments on commit 89fcfce

Please sign in to comment.