This commit is contained in:
Denis Duliçi 2018-05-21 18:10:43 +03:00
parent c57f3936ca
commit 243d7edaf6
4 changed files with 170 additions and 3 deletions

View File

@ -0,0 +1,76 @@
<?php
namespace App\Console\Commands;
use App\Models\Module\Module;
use App\Models\Module\ModuleHistory;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class ModuleDisable extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'module:disable {alias} {company_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Disable the specified module.';
/**
* Execute the console command.
*/
public function handle()
{
$alias = $this->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.'),
);
}
}

View File

@ -0,0 +1,76 @@
<?php
namespace App\Console\Commands;
use App\Models\Module\Module;
use App\Models\Module\ModuleHistory;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
class ModuleEnable extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'module:enable {alias} {company_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enable the specified module.';
/**
* Execute the console command.
*/
public function handle()
{
$alias = $this->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.'),
);
}
}

View File

@ -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.'),
);
}
}

View File

@ -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,
];