Skip to content

Commit

Permalink
Fixed so that ezpublish:legacy:init script adds legacy scripts to com…
Browse files Browse the repository at this point in the history
…poser.json
  • Loading branch information
vidarl committed Oct 25, 2018
1 parent b3f26a7 commit e2484cd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions bundle/Command/LegacyInitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->createDirectories($input, $output);
$this->updateComposeJson($output);
}

protected function createDirectories(InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -90,4 +91,46 @@ protected function createDirectories(InputInterface $input, OutputInterface $out
EOT
);
}

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

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'
];
$composerJson['scripts'] = array_merge(['legacy-scripts' => $legacy_scripts], $composerJson['scripts']);
$updateComposerJson = true;
}

if (!array_key_exists('symfony-scripts', $composerJson['scripts'])) {
$composerJson['scripts']['symfony-scripts'] = ['@legacy-scripts'];
$updateComposerJson = true;
} elseif (!in_array('@legacy-scripts', $composerJson['scripts']['symfony-scripts'])) {
$symfonyScripts = $composerJson['scripts']['symfony-scripts'];
$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');
$offset = count($symfonyScripts);
}

array_splice($symfonyScripts, $offset, 0, ['@legacy-scripts']);
$composerJson['scripts']['symfony-scripts'] = $symfonyScripts;
$updateComposerJson = true;
}

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

0 comments on commit e2484cd

Please sign in to comment.