refactored module commands
This commit is contained in:
@ -2,18 +2,11 @@
|
||||
|
||||
namespace Akaunting\Module\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use App\Traits\Permissions;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use App\Abstracts\Commands\Module;
|
||||
use App\Models\Module\Module as Model;
|
||||
|
||||
class InstallCommand extends Command
|
||||
class InstallCommand extends Module
|
||||
{
|
||||
use Permissions;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@ -35,65 +28,23 @@ class InstallCommand extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$alias = Str::kebab($this->argument('alias'));
|
||||
$company_id = $this->argument('company');
|
||||
$locale = $this->argument('locale');
|
||||
$this->prepare();
|
||||
|
||||
$old_company_id = session('company_id');
|
||||
$this->changeRuntime();
|
||||
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
app()->setLocale($locale);
|
||||
|
||||
$module = module($alias);
|
||||
|
||||
$model = Module::create([
|
||||
'company_id' => $company_id,
|
||||
'alias' => $alias,
|
||||
// Create db
|
||||
$this->model = Model::create([
|
||||
'company_id' => $this->company_id,
|
||||
'alias' => $this->alias,
|
||||
'enabled' => '1',
|
||||
]);
|
||||
|
||||
ModuleHistory::create([
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category', 'payment-method'),
|
||||
'version' => $module->get('version'),
|
||||
'description' => trans('modules.installed', ['module' => $alias]),
|
||||
]);
|
||||
$this->createHistory('installed');
|
||||
|
||||
if (config('module.cache.enabled')) {
|
||||
Cache::forget(config('module.cache.key'));
|
||||
}
|
||||
event(new \App\Events\Module\Installed($this->alias, $this->company_id));
|
||||
|
||||
// Disable model cache during installation
|
||||
config(['laravel-model-caching.enabled' => false]);
|
||||
|
||||
// Update database
|
||||
$this->call('migrate', ['--force' => true]);
|
||||
|
||||
event(new \App\Events\Module\Installed($alias, $company_id));
|
||||
|
||||
$this->attachDefaultModulePermissions($module);
|
||||
|
||||
session()->forget('company_id');
|
||||
|
||||
if (!empty($old_company_id)) {
|
||||
session(['company_id' => $old_company_id]);
|
||||
}
|
||||
$this->revertRuntime();
|
||||
|
||||
$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.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user