akaunting/app/Console/Commands/ModuleInstall.php

82 lines
1.9 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;
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()
{
$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);
2018-05-21 18:10:43 +03:00
$module = $this->laravel['modules']->findByAlias($model->alias);
2017-11-01 19:43:42 +03:00
$company_id = $this->argument('company_id');
2017-11-02 12:07:15 +03:00
// Add history
2017-11-01 19:43:42 +03:00
$data = [
'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
event(new ModuleInstalled($model->alias, $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
}