From 243d7edaf622bca8e65b628f9776d1edbf96d66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Mon, 21 May 2018 18:10:43 +0300 Subject: [PATCH] fixed #350 --- app/Console/Commands/ModuleDisable.php | 76 ++++++++++++++++++++++++++ app/Console/Commands/ModuleEnable.php | 76 ++++++++++++++++++++++++++ app/Console/Commands/ModuleInstall.php | 19 ++++++- app/Console/Kernel.php | 2 + 4 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 app/Console/Commands/ModuleDisable.php create mode 100644 app/Console/Commands/ModuleEnable.php diff --git a/app/Console/Commands/ModuleDisable.php b/app/Console/Commands/ModuleDisable.php new file mode 100644 index 000000000..1aca333e2 --- /dev/null +++ b/app/Console/Commands/ModuleDisable.php @@ -0,0 +1,76 @@ +argument('alias'); + $company_id = $this->argument('company_id'); + + $model = Module::alias($alias)->companyId($company_id)->get(); + + if (!$model) { + $this->info("Module [{$alias}] not found."); + return; + } + + if ($model->enabled == 1) { + $model->enabled = 0; + $model->save(); + + $module = $this->laravel['modules']->findByAlias($alias); + + // Add history + $data = [ + 'company_id' => $company_id, + 'module_id' => $model->id, + 'category' => $module->get('category'), + 'version' => $module->get('version'), + 'description' => trans('modules.disabled', ['module' => $module->get('name')]), + ]; + + ModuleHistory::create($data); + + $this->info("Module [{$alias}] disabled."); + } else { + $this->comment("Module [{$alias}] is already disabled."); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return array( + array('alias', InputArgument::REQUIRED, 'Module alias.'), + array('company_id', InputArgument::REQUIRED, 'Company ID.'), + ); + } +} diff --git a/app/Console/Commands/ModuleEnable.php b/app/Console/Commands/ModuleEnable.php new file mode 100644 index 000000000..8bf8375e0 --- /dev/null +++ b/app/Console/Commands/ModuleEnable.php @@ -0,0 +1,76 @@ +argument('alias'); + $company_id = $this->argument('company_id'); + + $model = Module::alias($alias)->companyId($company_id)->get(); + + if (!$model) { + $this->info("Module [{$alias}] not found."); + return; + } + + if ($model->enabled == 0) { + $model->enabled = 1; + $model->save(); + + $module = $this->laravel['modules']->findByAlias($alias); + + // Add history + $data = [ + 'company_id' => $company_id, + 'module_id' => $model->id, + 'category' => $module->get('category'), + 'version' => $module->get('version'), + 'description' => trans('modules.enabled', ['module' => $module->get('name')]), + ]; + + ModuleHistory::create($data); + + $this->info("Module [{$alias}] enabled."); + } else { + $this->comment("Module [{$alias}] is already enabled."); + } + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return array( + array('alias', InputArgument::REQUIRED, 'Module alias.'), + array('company_id', InputArgument::REQUIRED, 'Company ID.'), + ); + } +} diff --git a/app/Console/Commands/ModuleInstall.php b/app/Console/Commands/ModuleInstall.php index 4e279a217..b7bc63422 100644 --- a/app/Console/Commands/ModuleInstall.php +++ b/app/Console/Commands/ModuleInstall.php @@ -6,7 +6,7 @@ use App\Events\ModuleInstalled; use App\Models\Module\Module; use App\Models\Module\ModuleHistory; use Illuminate\Console\Command; -use Module as LaravelModule; +use Symfony\Component\Console\Input\InputArgument; class ModuleInstall extends Command { @@ -39,7 +39,7 @@ class ModuleInstall extends Command $model = Module::create($request); - $module = LaravelModule::findByAlias($model->alias); + $module = $this->laravel['modules']->findByAlias($model->alias); $company_id = $this->argument('company_id'); @@ -49,7 +49,7 @@ class ModuleInstall extends Command 'module_id' => $model->id, 'category' => $module->get('category'), 'version' => $module->get('version'), - 'description' => trans('modules.history.installed', ['module' => $module->get('name')]), + 'description' => trans('modules.installed', ['module' => $module->get('name')]), ]; ModuleHistory::create($data); @@ -62,4 +62,17 @@ class ModuleInstall extends Command $this->info('Module installed!'); } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return array( + array('alias', InputArgument::REQUIRED, 'Module alias.'), + array('company_id', InputArgument::REQUIRED, 'Company ID.'), + ); + } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index a83c826cf..d8f35a822 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -17,6 +17,8 @@ class Kernel extends ConsoleKernel Commands\BillReminder::class, Commands\Install::class, Commands\InvoiceReminder::class, + Commands\ModuleDisable::class, + Commands\ModuleEnable::class, Commands\ModuleInstall::class, Commands\RecurringCheck::class, ];