2019-12-03 15:41:56 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Events\Install\UpdateFinished;
|
|
|
|
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()
|
|
|
|
{
|
2020-02-11 00:12:14 +03:00
|
|
|
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]));
|
|
|
|
}
|
|
|
|
|
2022-03-02 19:03:06 +03:00
|
|
|
$company = company($company_id);
|
2020-02-11 00:12:14 +03:00
|
|
|
|
2022-03-02 19:03:06 +03:00
|
|
|
if (empty($company)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-03 18:57:31 +03:00
|
|
|
|
2022-03-02 19:03:06 +03:00
|
|
|
$company->makeCurrent();
|
2021-04-22 12:02:49 +03:00
|
|
|
|
2022-03-02 19:03:06 +03:00
|
|
|
// Set locale for modules
|
|
|
|
if (($alias != 'core') && !empty($company->locale)) {
|
|
|
|
app()->setLocale($company->locale);
|
2021-04-22 12:02:49 +03:00
|
|
|
}
|
2019-12-15 15:52:15 +03:00
|
|
|
|
2020-02-07 14:37:22 +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
|
|
|
}
|
|
|
|
}
|