2017-11-01 16:43:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
namespace Akaunting\Module\Commands;
|
2017-11-01 16:43:42 +00:00
|
|
|
|
|
|
|
|
use App\Models\Module\Module;
|
|
|
|
|
use App\Models\Module\ModuleHistory;
|
2020-02-06 14:08:20 +00:00
|
|
|
use App\Traits\Permissions;
|
2017-11-01 16:43:42 +00:00
|
|
|
use Illuminate\Console\Command;
|
2019-11-16 07:21:14 +00:00
|
|
|
use Illuminate\Support\Str;
|
2018-05-21 15:10:43 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2017-11-01 16:43:42 +00:00
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
class InstallCommand extends Command
|
2017-11-01 16:43:42 +00:00
|
|
|
{
|
2020-02-06 14:08:20 +00:00
|
|
|
use Permissions;
|
|
|
|
|
|
2017-11-01 16:43:42 +00:00
|
|
|
/**
|
|
|
|
|
* The name and signature of the console command.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2020-02-03 15:57:31 +00:00
|
|
|
protected $signature = 'module:install {alias} {company} {locale=en-GB}';
|
2017-11-01 16:43:42 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $description = 'Install the specified module.';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
2019-11-16 07:21:14 +00:00
|
|
|
$alias = Str::kebab($this->argument('alias'));
|
2020-02-03 15:57:31 +00:00
|
|
|
$company_id = $this->argument('company');
|
|
|
|
|
$locale = $this->argument('locale');
|
2018-12-20 14:35:28 +00:00
|
|
|
|
2018-12-25 13:49:37 +00:00
|
|
|
$old_company_id = session('company_id');
|
|
|
|
|
|
2018-12-20 14:35:28 +00:00
|
|
|
session(['company_id' => $company_id]);
|
|
|
|
|
|
2020-02-03 15:57:31 +00:00
|
|
|
app()->setLocale($locale);
|
|
|
|
|
|
2019-12-03 12:41:56 +00:00
|
|
|
$module = module($alias);
|
|
|
|
|
|
|
|
|
|
$model = Module::create([
|
2018-12-20 14:35:28 +00:00
|
|
|
'company_id' => $company_id,
|
2019-12-03 12:41:56 +00:00
|
|
|
'alias' => $alias,
|
2019-11-16 07:21:14 +00:00
|
|
|
'enabled' => '1',
|
2019-12-03 12:41:56 +00:00
|
|
|
]);
|
2018-05-09 19:22:02 +00:00
|
|
|
|
2019-12-03 12:41:56 +00:00
|
|
|
ModuleHistory::create([
|
2018-05-09 19:22:02 +00:00
|
|
|
'company_id' => $company_id,
|
2017-11-01 16:43:42 +00:00
|
|
|
'module_id' => $model->id,
|
2019-11-19 14:06:50 +00:00
|
|
|
'category' => $module->get('category', 'payment-method'),
|
2017-11-01 16:43:42 +00:00
|
|
|
'version' => $module->get('version'),
|
2019-12-03 12:41:56 +00:00
|
|
|
'description' => trans('modules.installed', ['module' => $alias]),
|
|
|
|
|
]);
|
2017-11-01 16:43:42 +00:00
|
|
|
|
2018-11-15 08:04:30 +00:00
|
|
|
$this->call('cache:clear');
|
|
|
|
|
|
2020-02-07 11:37:22 +00:00
|
|
|
// Disable model cache during installation
|
|
|
|
|
config(['laravel-model-caching.enabled' => false]);
|
|
|
|
|
|
2017-11-02 09:07:15 +00:00
|
|
|
// Update database
|
|
|
|
|
$this->call('migrate', ['--force' => true]);
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
event(new \App\Events\Module\Installed($alias, $company_id));
|
2018-12-20 14:35:28 +00:00
|
|
|
|
2020-02-06 14:08:20 +00:00
|
|
|
$this->attachDefaultModulePermissions($module);
|
2020-01-06 21:21:33 +00:00
|
|
|
|
2018-12-20 14:35:28 +00:00
|
|
|
session()->forget('company_id');
|
2017-11-02 09:07:15 +00:00
|
|
|
|
2018-12-25 13:49:37 +00:00
|
|
|
if (!empty($old_company_id)) {
|
|
|
|
|
session(['company_id' => $old_company_id]);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 16:43:42 +00:00
|
|
|
$this->info('Module installed!');
|
|
|
|
|
}
|
2018-05-21 15:10:43 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-05-21 15:17:54 +00:00
|
|
|
* Get the console command arguments.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2018-05-21 15:10:43 +00:00
|
|
|
protected function getArguments()
|
|
|
|
|
{
|
|
|
|
|
return array(
|
|
|
|
|
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
|
|
|
|
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-11-01 16:43:42 +00:00
|
|
|
}
|