fixed #350
This commit is contained in:
parent
c57f3936ca
commit
243d7edaf6
76
app/Console/Commands/ModuleDisable.php
Normal file
76
app/Console/Commands/ModuleDisable.php
Normal 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.'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
76
app/Console/Commands/ModuleEnable.php
Normal file
76
app/Console/Commands/ModuleEnable.php
Normal 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.'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ use App\Events\ModuleInstalled;
|
|||||||
use App\Models\Module\Module;
|
use App\Models\Module\Module;
|
||||||
use App\Models\Module\ModuleHistory;
|
use App\Models\Module\ModuleHistory;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Module as LaravelModule;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
|
||||||
class ModuleInstall extends Command
|
class ModuleInstall extends Command
|
||||||
{
|
{
|
||||||
@ -39,7 +39,7 @@ class ModuleInstall extends Command
|
|||||||
|
|
||||||
$model = Module::create($request);
|
$model = Module::create($request);
|
||||||
|
|
||||||
$module = LaravelModule::findByAlias($model->alias);
|
$module = $this->laravel['modules']->findByAlias($model->alias);
|
||||||
|
|
||||||
$company_id = $this->argument('company_id');
|
$company_id = $this->argument('company_id');
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ class ModuleInstall extends Command
|
|||||||
'module_id' => $model->id,
|
'module_id' => $model->id,
|
||||||
'category' => $module->get('category'),
|
'category' => $module->get('category'),
|
||||||
'version' => $module->get('version'),
|
'version' => $module->get('version'),
|
||||||
'description' => trans('modules.history.installed', ['module' => $module->get('name')]),
|
'description' => trans('modules.installed', ['module' => $module->get('name')]),
|
||||||
];
|
];
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
ModuleHistory::create($data);
|
||||||
@ -62,4 +62,17 @@ class ModuleInstall extends Command
|
|||||||
|
|
||||||
$this->info('Module installed!');
|
$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.'),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ class Kernel extends ConsoleKernel
|
|||||||
Commands\BillReminder::class,
|
Commands\BillReminder::class,
|
||||||
Commands\Install::class,
|
Commands\Install::class,
|
||||||
Commands\InvoiceReminder::class,
|
Commands\InvoiceReminder::class,
|
||||||
|
Commands\ModuleDisable::class,
|
||||||
|
Commands\ModuleEnable::class,
|
||||||
Commands\ModuleInstall::class,
|
Commands\ModuleInstall::class,
|
||||||
Commands\RecurringCheck::class,
|
Commands\RecurringCheck::class,
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user