add ability to delete files on update

This commit is contained in:
Mohit Panjwani
2020-12-03 12:49:37 +05:30
parent 3723697add
commit 28217df654
2 changed files with 53 additions and 17 deletions

View File

@ -13,6 +13,8 @@ class UpdateCommand extends Command
public $version; public $version;
public $response;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
@ -45,9 +47,10 @@ class UpdateCommand extends Command
set_time_limit(3600); // 1 hour set_time_limit(3600); // 1 hour
$this->installed = $this->getInstalledVersion(); $this->installed = $this->getInstalledVersion();
$this->version = $this->getLatestVersion(); $this->response = $this->getLatestVersionResponse();
$this->version = ($this->response) ? $this->response->version : false;
if ($this->version == 'extension_required') { if ($this->response == 'extension_required') {
$this->info('Sorry! Your system does not meet the minimum requirements for this update.'); $this->info('Sorry! Your system does not meet the minimum requirements for this update.');
$this->info('Please retry after installing the required version/extensions.'); $this->info('Please retry after installing the required version/extensions.');
@ -75,6 +78,12 @@ class UpdateCommand extends Command
return; return;
} }
if(isset($this->response->deleted_files) && !empty($this->response->deleted_files)) {
if (!$this->deleteFiles($this->response->deleted_files)) {
return;
}
}
if (!$this->migrateUpdate()) { if (!$this->migrateUpdate()) {
return; return;
} }
@ -91,7 +100,7 @@ class UpdateCommand extends Command
return Setting::getSetting('version'); return Setting::getSetting('version');
} }
public function getLatestVersion() public function getLatestVersionResponse()
{ {
$this->info('Your currently installed version is ' . $this->installed); $this->info('Your currently installed version is ' . $this->installed);
$this->line(''); $this->line('');
@ -100,26 +109,27 @@ class UpdateCommand extends Command
try { try {
$response = Updater::checkForUpdate($this->installed); $response = Updater::checkForUpdate($this->installed);
$extensions = $response->version->extensions; if ($response->success) {
$is_required = false; $extensions = $response->version->extensions;
foreach ($extensions as $key => $extension) { $is_required = false;
if(!$extension) { foreach ($extensions as $key => $extension) {
$is_required = true;
$this->info('❌ '.$key); if(!$extension) {
$is_required = true;
$this->info('❌ '.$key);
}
$this->info('✅ '.$key);
} }
$this->info('✅ '.$key); if($is_required) {
} return 'extension_required';
}
if($is_required) { return $response->version;
return 'extension_required';
}
if ($response->success) {
return $response->version->version;
} }
return false; return false;
@ -183,6 +193,21 @@ class UpdateCommand extends Command
return true; return true;
} }
public function deleteFiles($files)
{
$this->info('Deleting unused old files...');
try {
Updater::deleteFiles($files);
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return true;
}
public function migrateUpdate() public function migrateUpdate()
{ {
$this->info('Running Migrations...'); $this->info('Running Migrations...');

View File

@ -128,6 +128,17 @@ class Updater
return true; return true;
} }
public static function deleteFiles($json)
{
$files = json_decode($json);
foreach($files as $file) {
\File::delete(base_path($file));
}
return true;
}
public static function migrateUpdate() public static function migrateUpdate()
{ {
Artisan::call('migrate --force'); Artisan::call('migrate --force');