winter/modules/system/console/PluginRefresh.php

91 lines
2.1 KiB
PHP
Raw Normal View History

2014-05-14 23:24:20 +10:00
<?php namespace System\Console;
use Illuminate\Console\Command;
use System\Classes\UpdateManager;
use System\Classes\PluginManager;
2014-05-14 23:24:20 +10:00
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
/**
* Console command to refresh a plugin.
*
* This destroys all database tables for a specific plugin, then builds them up again.
* It is a great way for developers to debug and develop new plugins.
*
* @package october\system
* @author Alexey Bobkov, Samuel Georges
*/
2014-05-14 23:24:20 +10:00
class PluginRefresh extends Command
{
/**
* The console command name.
* @var string
*/
protected $name = 'plugin:refresh';
/**
* The console command description.
* @var string
*/
protected $description = 'Removes and re-adds 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
{
2017-05-20 09:03:58 +10:00
/*
* Lookup plugin
*/
2014-05-14 23:24:20 +10:00
$pluginName = $this->argument('name');
$pluginName = PluginManager::instance()->normalizeIdentifier($pluginName);
2015-11-09 15:36:58 -08:00
if (!PluginManager::instance()->exists($pluginName)) {
throw new \InvalidArgumentException(sprintf('Plugin "%s" not found.', $pluginName));
}
2017-05-20 09:03:58 +10:00
$manager = UpdateManager::instance()->setNotesOutput($this->output);
2014-05-14 23:24:20 +10:00
2017-05-20 09:03:58 +10:00
/*
* Rollback plugin
*/
2014-05-14 23:24:20 +10:00
$manager->rollbackPlugin($pluginName);
2017-05-20 09:03:58 +10:00
/*
* Update plugin
*/
2014-05-14 23:24:20 +10:00
$this->output->writeln('<info>Reinstalling plugin...</info>');
$manager->updatePlugin($pluginName);
}
/**
* 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 [];
}
2014-10-18 11:58:50 +02:00
}