akaunting/app/Console/Commands/FinishUpdate.php

69 lines
1.8 KiB
PHP
Raw Normal View History

2019-12-03 15:41:56 +03:00
<?php
namespace App\Console\Commands;
use App\Events\Install\UpdateFinished;
2020-02-03 18:57:31 +03:00
use App\Models\Common\Company;
2019-12-03 15:41:56 +03:00
use Illuminate\Console\Command;
class FinishUpdate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
2020-02-03 18:57:31 +03:00
protected $signature = 'update:finish {alias} {company} {new} {old}';
2019-12-03 15:41:56 +03:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'Finish the update process through CLI';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(3600); // 1 hour
2019-12-03 15:41:56 +03:00
$this->info('Finishing update...');
$this->call('cache:clear');
2019-12-15 15:52:15 +03:00
$alias = $this->argument('alias');
2020-02-03 18:57:31 +03:00
$company_id = $this->argument('company');
2019-12-15 15:52:15 +03:00
$new = $this->argument('new');
$old = $this->argument('old');
// Check if file mirror was successful
$version = ($alias == 'core') ? version('short') : module($alias)->get('version');
if ($version != $new) {
2020-06-03 23:23:41 +03:00
logger($alias . ' update failed:: file version > ' . $version . ' -vs- ' . 'request version > ' . $new);
2019-12-15 15:52:15 +03:00
throw new \Exception(trans('modules.errors.finish', ['module' => $alias]));
}
2020-02-03 18:57:31 +03:00
// Set locale for modules
if ($alias != 'core') {
$company = Company::find($company_id);
if (!empty($company->locale)) {
app()->setLocale($company->locale);
}
2020-02-03 18:57:31 +03:00
}
2019-12-15 15:52:15 +03:00
session(['company_id' => $company_id]);
2019-12-19 18:20:00 +03:00
setting()->setExtraColumns(['company_id' => $company_id]);
2019-12-15 15:52:15 +03:00
// Disable model cache during update
config(['laravel-model-caching.enabled' => false]);
2019-12-15 15:52:15 +03:00
event(new UpdateFinished($alias, $new, $old));
2019-12-03 15:41:56 +03:00
}
}