2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace System\Console;
|
|
|
|
|
2022-02-23 22:13:34 -06:00
|
|
|
use Winter\Storm\Console\Command;
|
2014-05-14 23:24:20 +10:00
|
|
|
use System\Classes\UpdateManager;
|
|
|
|
|
2017-03-16 17:08:20 +11:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2021-03-10 15:02:53 -06:00
|
|
|
* @package winter\wn-system-module
|
2017-03-16 17:08:20 +11:00
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
2014-05-14 23:24:20 +10:00
|
|
|
class PluginRefresh extends Command
|
|
|
|
{
|
2022-02-24 20:29:53 -06:00
|
|
|
use \Winter\Storm\Console\Traits\ConfirmsWithInput;
|
2022-02-23 22:13:34 -06:00
|
|
|
use Traits\HasPluginArgument;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|null The default command name for lazy loading.
|
|
|
|
*/
|
|
|
|
protected static $defaultName = 'plugin:refresh';
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/**
|
2022-02-23 22:13:34 -06:00
|
|
|
* @var string The name and signature of this command.
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
2022-02-23 22:13:34 -06:00
|
|
|
protected $signature = 'plugin:refresh
|
2022-02-24 20:29:53 -06:00
|
|
|
{plugin : The plugin to refresh. <info>(eg: Winter.Blog)</info>}
|
2022-02-24 22:02:01 -06:00
|
|
|
{--f|force : Force the operation to run and ignore production warnings and confirmation questions.}';
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
2022-02-23 22:13:34 -06:00
|
|
|
* @var string The console command description.
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
protected $description = 'Removes and re-adds an existing plugin.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
2022-02-24 20:29:53 -06:00
|
|
|
public function handle(): int
|
2014-05-14 23:24:20 +10:00
|
|
|
{
|
2022-02-23 22:13:34 -06:00
|
|
|
$pluginName = $this->getPluginIdentifier();
|
2014-05-29 17:33:02 +10:00
|
|
|
|
2022-02-24 20:29:53 -06:00
|
|
|
if (!$this->confirmWithInput(
|
|
|
|
"This will completely remove and reinstall $pluginName. This may result in potential data loss.",
|
|
|
|
$pluginName
|
|
|
|
)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-02-23 22:13:34 -06:00
|
|
|
|
|
|
|
// Set the UpdateManager output stream to the CLI
|
2017-05-20 09:03:58 +10:00
|
|
|
$manager = UpdateManager::instance()->setNotesOutput($this->output);
|
2014-05-14 23:24:20 +10:00
|
|
|
|
2022-02-23 22:13:34 -06:00
|
|
|
// Rollback the plugin
|
2014-05-14 23:24:20 +10:00
|
|
|
$manager->rollbackPlugin($pluginName);
|
|
|
|
|
2022-02-23 22:13:34 -06:00
|
|
|
// Reinstall the plugin
|
2014-05-14 23:24:20 +10:00
|
|
|
$this->output->writeln('<info>Reinstalling plugin...</info>');
|
|
|
|
$manager->updatePlugin($pluginName);
|
2022-02-24 20:29:53 -06:00
|
|
|
|
|
|
|
return 0;
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|