Create and register a command to delete modules

parent 5e31ce88
<?php
namespace Modules\Core\Console;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class DeleteModuleCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'asgard:delete:module';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete a module and optionally its migrations';
/**
* @var Filesystem
*/
private $finder;
public function __construct(Filesystem $finder)
{
parent::__construct();
$this->finder = $finder;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$module = $this->argument('module');
$modulePath = config('modules.paths.modules') . '/' . $module;
if ($this->finder->exists($modulePath) === false) {
$this->error('This module does not exist');
return;
}
if (is_core_module($module) === true) {
$this->error('You cannot remove a core module.');
return;
}
if ($this->option('migrations') === true) {
$this->call('module:migrate-reset', ['module' => $module]);
}
$this->finder->deleteDirectory($modulePath);
$this->info('Module successfully deleted');
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['module', InputArgument::REQUIRED, 'The module name'],
];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['migrations', 'm', InputOption::VALUE_NONE, 'Reset the module migrations', null],
];
}
}
......@@ -7,6 +7,7 @@ use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Console\DeleteModuleCommand;
use Modules\Core\Console\DownloadModuleCommand;
use Modules\Core\Console\InstallCommand;
use Modules\Core\Console\PublishModuleAssetsCommand;
......@@ -110,6 +111,7 @@ class CoreServiceProvider extends ServiceProvider
PublishThemeAssetsCommand::class,
PublishModuleAssetsCommand::class,
DownloadModuleCommand::class,
DeleteModuleCommand::class,
]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment