mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Add plugin add and remove commands
This commit is contained in:
@@ -34,7 +34,7 @@ use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand;
|
|||||||
use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
|
use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
|
||||||
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand;
|
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand;
|
||||||
|
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../plugins/autoload.php';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$cli = new CLI("
|
$cli = new CLI("
|
||||||
|
41
lib/Alchemy/Phrasea/Command/Plugin/AbstractPluginCommand.php
Normal file
41
lib/Alchemy/Phrasea/Command/Plugin/AbstractPluginCommand.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 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 Alchemy\Phrasea\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
abstract class AbstractPluginCommand extends Command
|
||||||
|
{
|
||||||
|
protected function validatePlugins(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$manifests = array();
|
||||||
|
|
||||||
|
$output->write("Validating plugins...");
|
||||||
|
foreach ($this->container['plugins.explorer'] as $directory) {
|
||||||
|
$manifests[] = $manifest = $this->container['plugins.plugins-validator']->validatePlugin($directory);
|
||||||
|
}
|
||||||
|
$output->writeln(" <comment>OK</comment>");
|
||||||
|
|
||||||
|
return $manifests;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateConfigFiles(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$manifests = $this->validatePlugins($input, $output);
|
||||||
|
|
||||||
|
$output->write("Updating config files...");
|
||||||
|
$this->container['plugins.autoloader-generator']->write($manifests);
|
||||||
|
$output->writeln(" <comment>OK</comment>");
|
||||||
|
}
|
||||||
|
}
|
61
lib/Alchemy/Phrasea/Command/Plugin/AddPlugin.php
Normal file
61
lib/Alchemy/Phrasea/Command/Plugin/AddPlugin.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 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;
|
||||||
|
|
||||||
|
class AddPlugin extends AbstractPluginCommand
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('plugins:add');
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setDescription('Install a plugin to Phraseanet')
|
||||||
|
->addArgument('source', InputArgument::REQUIRED, 'The source is a folder');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$source = $input->getArgument('source');
|
||||||
|
|
||||||
|
$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['plugins.directory'] . 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("Removing temporary directory...");
|
||||||
|
$this->container['filesystem']->remove($temporaryDir);
|
||||||
|
$output->writeln(" <comment>OK</comment>");
|
||||||
|
|
||||||
|
$this->updateConfigFiles($input, $output);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
43
lib/Alchemy/Phrasea/Command/Plugin/RemovePlugin.php
Normal file
43
lib/Alchemy/Phrasea/Command/Plugin/RemovePlugin.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2013 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;
|
||||||
|
|
||||||
|
class RemovePlugin extends AbstractPluginCommand
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('plugins:remove');
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setDescription('Removes a plugin given its name')
|
||||||
|
->addArgument('name', InputArgument::REQUIRED, 'The name of the plugin');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$name = $input->getArgument('name');
|
||||||
|
|
||||||
|
$path = $this->container['plugins.directory'] . DIRECTORY_SEPARATOR . $name;
|
||||||
|
|
||||||
|
$output->write("Removing <info>$name</info>...");
|
||||||
|
$this->container['filesystem']->remove($path);
|
||||||
|
$output->writeln(" <comment>OK</comment>");
|
||||||
|
|
||||||
|
$this->updateConfigFiles($input, $output);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user