winter/modules/system/console/PluginRemove.php

111 lines
2.7 KiB
PHP
Raw Normal View History

2014-05-14 23:24:20 +10:00
<?php namespace System\Console;
use File;
use Illuminate\Console\Command;
use System\Classes\UpdateManager;
use System\Classes\PluginManager;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
/**
* Console command to remove a plugin.
*
* This completely deletes an existing plugin, including database tables, files
* and directories.
*
* @package october\system
* @author Alexey Bobkov, Samuel Georges
*/
2014-05-14 23:24:20 +10:00
class PluginRemove extends Command
{
use \Illuminate\Console\ConfirmableTrait;
2014-05-14 23:24:20 +10:00
/**
* The console command name.
* @var string
*/
protected $name = 'plugin:remove';
/**
* The console command description.
* @var string
*/
protected $description = 'Removes an existing plugin.';
/**
* Create a new command instance.
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
* @return void
*/
2017-07-14 16:28:47 +10:00
public function handle()
2014-05-14 23:24:20 +10:00
{
$pluginManager = PluginManager::instance();
$pluginName = $this->argument('name');
$pluginName = $pluginManager->normalizeIdentifier($pluginName);
2014-10-18 11:58:50 +02:00
if (!$pluginManager->hasPlugin($pluginName)) {
return $this->error(sprintf('Unable to find a registered plugin called "%s"', $pluginName));
2014-10-18 11:58:50 +02:00
}
2015-05-14 17:34:43 +10:00
if (!$this->confirmToProceed(sprintf('This will DELETE plugin "%s" from the filesystem and database.', $pluginName))) {
return;
2014-10-18 11:58:50 +02:00
}
/*
* Rollback plugin
*/
2017-05-20 09:03:58 +10:00
$manager = UpdateManager::instance()->setNotesOutput($this->output);
$manager->rollbackPlugin($pluginName);
/*
* Delete from file system
*/
if ($pluginPath = $pluginManager->getPluginPath($pluginName)) {
File::deleteDirectory($pluginPath);
$this->output->writeln(sprintf('<info>Deleted: %s</info>', $pluginName));
2014-05-14 23:24:20 +10:00
}
}
/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the plugin. Eg: AuthorName.PluginName'],
];
}
/**
* Get the console command options.
* @return array
*/
protected function getOptions()
{
return [
['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'],
];
}
/**
* Get the default confirmation callback.
* @return \Closure
*/
protected function getDefaultConfirmCallback()
{
2014-10-18 11:58:50 +02:00
return function () {
return true;
};
2014-05-14 23:24:20 +10:00
}
2014-10-18 11:58:50 +02:00
}