fix AddPluginTest

This commit is contained in:
Arthur de Moulins
2020-03-13 19:51:10 +01:00
parent 23d757c4d6
commit 6ed22b53dc
2 changed files with 17 additions and 3 deletions

View File

@@ -15,6 +15,21 @@ use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
function normalizePath($path) {
return array_reduce(explode('/', $path), function ($a, $b) {
if($a === 0)
$a = '/';
if($b === '' || $b === '.')
return $a;
if($b === '..')
return dirname($a);
return preg_replace('/\/+/', '/', "$a/$b");
}, 0);
}
abstract class AbstractPluginCommand extends Command
{
protected function validatePlugins(InputInterface $input, OutputInterface $output)
@@ -54,13 +69,12 @@ abstract class AbstractPluginCommand extends Command
protected function doInstallPlugin($source, InputInterface $input, OutputInterface $output)
{
$output->write("Validating plugin...");
$manifest = $this->container['plugins.plugins-validator']->validatePlugin($source);
$output->writeln(" <comment>OK</comment> found <info>".$manifest->getName()."</info>");
$targetDir = $this->container['plugin.path'] . DIRECTORY_SEPARATOR . $manifest->getName();
if (realpath($targetDir) !== realpath($source)) {
if (normalizePath($targetDir) !== normalizePath($source)) {
$temporaryDir = $this->container['temporary-filesystem']->createTemporaryDirectory();
$output->write("Importing <info>$source</info>...");
$this->container['plugins.importer']->import($source, $temporaryDir);