mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 12:03:14 +00:00
97 lines
3.3 KiB
PHP
97 lines
3.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2016 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Command\Plugin;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
|
|
|
class AddPlugin extends AbstractPluginCommand
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct('plugins:add');
|
|
|
|
$this
|
|
->setDescription('Installs a plugin to Phraseanet')
|
|
->addArgument('source', InputArgument::REQUIRED, 'The source is a folder');
|
|
}
|
|
|
|
protected function doExecutePluginAction(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$source = $input->getArgument('source');
|
|
$shouldDownload = $this->shouldDownloadPlugin($source);
|
|
|
|
if ($shouldDownload){
|
|
$command = $this->getApplication()->find('plugins:download');
|
|
$arguments = [
|
|
'command' => 'plugins:download',
|
|
'source' => $source
|
|
];
|
|
|
|
$downloadInput = new ArrayInput($arguments);
|
|
$command->run($downloadInput, $output);
|
|
|
|
} else {
|
|
|
|
$temporaryDir = $this->container['temporary-filesystem']->createTemporaryDirectory();
|
|
|
|
$output->write("Importing <info>$source</info>...");
|
|
$this->container['plugins.importer']->import($source, $temporaryDir);
|
|
$output->writeln(" <comment>OK</comment>");
|
|
|
|
$output->write("Validating plugin...");
|
|
$manifest = $this->container['plugins.plugins-validator']->validatePlugin($temporaryDir);
|
|
$output->writeln(" <comment>OK</comment> found <info>".$manifest->getName()."</info>");
|
|
|
|
$targetDir = $this->container['plugin.path'] . DIRECTORY_SEPARATOR . $manifest->getName();
|
|
|
|
$output->write("Setting up composer...");
|
|
$this->container['plugins.composer-installer']->install($temporaryDir);
|
|
$output->writeln(" <comment>OK</comment>");
|
|
|
|
$output->write("Installing plugin <info>".$manifest->getName()."</info>...");
|
|
$this->container['filesystem']->mirror($temporaryDir, $targetDir);
|
|
$output->writeln(" <comment>OK</comment>");
|
|
|
|
$output->write("Copying public files <info>".$manifest->getName()."</info>...");
|
|
$this->container['plugins.assets-manager']->update($manifest);
|
|
$output->writeln(" <comment>OK</comment>");
|
|
|
|
$output->write("Removing temporary directory...");
|
|
$this->container['filesystem']->remove($temporaryDir);
|
|
$output->writeln(" <comment>OK</comment>");
|
|
|
|
$output->write("Activating plugin...");
|
|
$this->container['conf']->set(['plugins', $manifest->getName(), 'enabled'], true);
|
|
$output->writeln(" <comment>OK</comment>");
|
|
|
|
$this->updateConfigFiles($input, $output);
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
protected function shouldDownloadPlugin($source)
|
|
{
|
|
$allowedScheme = array('https','ssh');
|
|
|
|
$scheme = parse_url($source, PHP_URL_SCHEME);
|
|
if (in_array($scheme, $allowedScheme)){
|
|
return true;
|
|
} else{
|
|
return false;
|
|
}
|
|
}
|
|
}
|