From cfbd5eba596c64627cca03fab9460d040f07622c Mon Sep 17 00:00:00 2001 From: denisdulici Date: Wed, 1 Nov 2017 19:43:42 +0300 Subject: [PATCH] added module:install command --- app/Console/Commands/ModuleInstall.php | 55 ++++++++++++++++++++++++++ app/Console/Kernel.php | 1 + app/Http/Controllers/Modules/Item.php | 21 +--------- 3 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 app/Console/Commands/ModuleInstall.php diff --git a/app/Console/Commands/ModuleInstall.php b/app/Console/Commands/ModuleInstall.php new file mode 100644 index 000000000..cdff4b84b --- /dev/null +++ b/app/Console/Commands/ModuleInstall.php @@ -0,0 +1,55 @@ + $this->argument('company_id'), + 'alias' => strtolower($this->argument('module')), + 'status' => '1', + ]; + + $model = Module::create($request); + + $module = LaravelModule::findByAlias($model->alias); + + $data = [ + 'company_id' => $this->argument('company_id'), + 'module_id' => $model->id, + 'category' => $module->get('category'), + 'version' => $module->get('version'), + 'description' => trans('modules.history.installed', ['module' => $module->get('name')]), + ]; + + ModuleHistory::create($data); + + $this->info('Module installed!'); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index b447f2f42..116597687 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel Commands\CompanySeed::class, Commands\BillReminder::class, Commands\InvoiceReminder::class, + Commands\ModuleInstall::class, ]; /** diff --git a/app/Http/Controllers/Modules/Item.php b/app/Http/Controllers/Modules/Item.php index 3e804520f..a540d03ff 100644 --- a/app/Http/Controllers/Modules/Item.php +++ b/app/Http/Controllers/Modules/Item.php @@ -10,8 +10,6 @@ use App\Models\Module\ModuleHistory; use App\Traits\Modules; use Illuminate\Routing\Route; -use Module as MModule; - class Item extends Controller { use Modules; @@ -132,7 +130,7 @@ class Item extends Controller /** * Show the form for viewing the specified resource. * - * @param $path + * @param $request * * @return Response */ @@ -143,22 +141,7 @@ class Item extends Controller $json = $this->installModule($path); if ($json['success']) { - $request['company_id'] = session('company_id'); - $request['alias'] = $json['data']['alias']; - - $module = Module::create($request->all()); - - $mmodule = MModule::findByAlias($module->alias); - - $data = array( - 'company_id' => session('company_id'), - 'module_id' => $module->id, - 'category' => $mmodule->get('category'), - 'version' => $mmodule->get('version'), - 'description' => trans('modules.history.installed', ['module' => $mmodule->get('name')]), - ); - - ModuleHistory::create($data); + Artisan::call('module:install ' . $json['data']['alias'] . ' ' . session('company_id')); $message = trans('messages.success.added', ['type' => trans('modules.installed', ['module' => $json['data']['name']])]);