2017-11-01 19:43:42 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2017-11-02 12:07:15 +03:00
|
|
|
use App\Events\ModuleInstalled;
|
2017-11-01 19:43:42 +03:00
|
|
|
use App\Models\Module\Module;
|
|
|
|
use App\Models\Module\ModuleHistory;
|
|
|
|
use Illuminate\Console\Command;
|
2018-05-21 18:10:43 +03:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2017-11-01 19:43:42 +03:00
|
|
|
|
|
|
|
class ModuleInstall extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-11-01 22:15:25 +03:00
|
|
|
protected $signature = 'module:install {alias} {company_id}';
|
2017-11-01 19:43:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Install the specified module.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2018-12-20 17:35:28 +03:00
|
|
|
$alias = $this->argument('alias');
|
|
|
|
$company_id = $this->argument('company_id');
|
|
|
|
|
|
|
|
// Set company id
|
|
|
|
session(['company_id' => $company_id]);
|
|
|
|
|
2017-11-01 19:43:42 +03:00
|
|
|
$request = [
|
2018-12-20 17:35:28 +03:00
|
|
|
'company_id' => $company_id,
|
|
|
|
'alias' => strtolower($alias),
|
2017-11-01 19:43:42 +03:00
|
|
|
'status' => '1',
|
|
|
|
];
|
|
|
|
|
|
|
|
$model = Module::create($request);
|
|
|
|
|
2018-12-20 17:35:28 +03:00
|
|
|
$module = $this->laravel['modules']->findByAlias($alias);
|
2018-05-09 22:22:02 +03:00
|
|
|
|
2017-11-02 12:07:15 +03:00
|
|
|
// Add history
|
2017-11-01 19:43:42 +03:00
|
|
|
$data = [
|
2018-05-09 22:22:02 +03:00
|
|
|
'company_id' => $company_id,
|
2017-11-01 19:43:42 +03:00
|
|
|
'module_id' => $model->id,
|
|
|
|
'category' => $module->get('category'),
|
|
|
|
'version' => $module->get('version'),
|
2018-05-21 18:10:43 +03:00
|
|
|
'description' => trans('modules.installed', ['module' => $module->get('name')]),
|
2017-11-01 19:43:42 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
ModuleHistory::create($data);
|
|
|
|
|
2018-11-15 11:04:30 +03:00
|
|
|
// Clear cache
|
|
|
|
$this->call('cache:clear');
|
|
|
|
|
2017-11-02 12:07:15 +03:00
|
|
|
// Update database
|
|
|
|
$this->call('migrate', ['--force' => true]);
|
|
|
|
|
|
|
|
// Trigger event
|
2018-12-20 17:35:28 +03:00
|
|
|
event(new ModuleInstalled($alias, $company_id));
|
|
|
|
|
|
|
|
// Unset company id
|
|
|
|
session()->forget('company_id');
|
2017-11-02 12:07:15 +03:00
|
|
|
|
2017-11-01 19:43:42 +03:00
|
|
|
$this->info('Module installed!');
|
|
|
|
}
|
2018-05-21 18:10:43 +03:00
|
|
|
|
|
|
|
/**
|
2018-05-21 18:17:54 +03:00
|
|
|
* Get the console command arguments.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-05-21 18:10:43 +03:00
|
|
|
protected function getArguments()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
|
|
|
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
|
|
|
);
|
|
|
|
}
|
2017-11-01 19:43:42 +03:00
|
|
|
}
|