FEATURE #1753: add commands for enablind/disabling modules

This commit is contained in:
Michal Kváček
2017-08-01 22:58:59 +02:00
parent c2502a2355
commit 8c15a63c2a
12 changed files with 252 additions and 21 deletions
@@ -0,0 +1,44 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class DisableModule extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:disable {module}';
/**
* The console command description.
* @var string
*/
protected $description = 'Disable module';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$moduleName = $this->argument('module');
$module = Module::where('static_name', $moduleName)
->firstOrFail();
if ($module->has_submodules) {
$submodules = $module->submodules;
foreach ($submodules as $submodule) {
$this->call('module:disable', ['module' => $submodule->static_name]);
}
}
$module->enabled = false;
$module->save();
$this->line('Module ' . $module->static_name . ' disabled.');
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class EnableModule extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:enable {module}';
/**
* The console command description.
* @var string
*/
protected $description = 'Enable module';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$moduleName = $this->argument('module');
$module = Module::where('static_name', $moduleName)
->firstOrFail();
if ($module->has_submodules) {
$submodules = $module->submodules;
foreach ($submodules as $submodule) {
$this->call('module:enable', ['module' => $submodule->static_name]);
}
}
if ($module->parent_id) {
$module->parent->update(['enabled' => true]);
}
$module->enabled = true;
$module->save();
$this->line('Module ' . $module->static_name . ' enabled.');
}
}
@@ -155,13 +155,12 @@ class InstallModule extends Command
if (is_null($module)) {
// insert module into database
$settings = [
'staticName' => $this->moduleName,
'providers' => $providers,
'order' => isset($config['order']) ? $config['order'] : 0,
'files' => isset($config['files']) ? $config['files'] : []
];
$module = Installer::install($name, $alias, $description, $handler, $this->parentModuleId, $settings);
$module = Installer::install($name, $alias, $this->moduleName, $description, $handler, $this->parentModuleId, $settings);
}
// try to install submodules
@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands\Modules;
use App\Models\Module;
use Illuminate\Console\Command;
class ModuleMigrate extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'module:migrate {module}';
/**
* The console command description.
* @var string
*/
protected $description = 'Run migrations in specified module';
/**
* Execute the console command.
* @return mixed
*/
public function handle()
{
$moduleName = $this->argument('module');
$module = Module::where('static_name', $moduleName)
->firstOrFail();
if ($module->has_submodules) {
$submodules = $module->submodules;
foreach ($submodules as $submodule) {
$this->call('module:migrate', ['module' => $submodule->static_name]);
}
}
$this->line('Migrating ' . $module->static_name);
$this->call('migrate', ['--path' => config('modules.paths.modules').'/'.$moduleName.'/Database']);
}
}
+2 -2
View File
@@ -45,7 +45,7 @@ class SetTemplate extends Command
$config['staticName'] = $template;
if ($current) {
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $current->module_settings['staticName'] . '.');
$this->line('Template is already installed. Currently using template ' . trans($current->name) . ' located in /templates/' . $current->static_name . '.');
$confirm = $this->confirm('Uninstall it and install *' . trans($config['name']) . '*? All data associated with installed template will be lost!');
if ($confirm) {
@@ -59,7 +59,7 @@ class SetTemplate extends Command
}
try {
Installer::install($config['name'], $config['alias'], $config['description'], $config['handler'], false, $config);
Installer::install($config['name'], $config['alias'], $current->static_name, $config['description'], $config['handler'], false, $config);
} catch (\Exception $e) {
$this->error('Cannot install template ' . $template . '. Message: ' . $e->getMessage());
return;
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class UninstallModule extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
}
}
+6 -1
View File
@@ -3,6 +3,9 @@
namespace App\Console;
use App\Console\Commands\Modules\CreateNew;
use App\Console\Commands\Modules\DisableModule;
use App\Console\Commands\Modules\EnableModule;
use App\Console\Commands\Modules\ModuleMigrate;
use App\Console\Commands\PublishTemplateResources;
use App\Console\Commands\TemplateInfo;
use Illuminate\Console\Scheduling\Schedule;
@@ -12,13 +15,15 @@ class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\NewUser::class,
Commands\ChangePassword::class,
CreateNew::class,
ModuleMigrate::class,
EnableModule::class,
DisableModule::class,
Commands\Modules\InstallModule::class,
Commands\Modules\InstallAllModules::class,
Commands\TranslateDirectory::class,