akaunting/app/Console/Commands/ModuleInstall.php

64 lines
1.5 KiB
PHP
Raw Normal View History

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;
use Module as LaravelModule;
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()
{
$request = [
'company_id' => $this->argument('company_id'),
2017-11-01 22:15:25 +03:00
'alias' => strtolower($this->argument('alias')),
2017-11-01 19:43:42 +03:00
'status' => '1',
];
$model = Module::create($request);
$module = LaravelModule::findByAlias($model->alias);
2017-11-02 12:07:15 +03:00
// Add history
2017-11-01 19:43:42 +03:00
$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);
2017-11-02 12:07:15 +03:00
// Update database
$this->call('migrate', ['--force' => true]);
// Trigger event
event(new ModuleInstalled($model->alias));
2017-11-01 19:43:42 +03:00
$this->info('Module installed!');
}
}