From 848c5646f9f8d742282da0fc9106667fb845cfa1 Mon Sep 17 00:00:00 2001 From: jayvirsinh_gohil Date: Sat, 16 Nov 2019 13:25:39 +0530 Subject: [PATCH] refactor upadater --- app/Space/Updater.php | 66 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/app/Space/Updater.php b/app/Space/Updater.php index 3c58ff28..7fbb337a 100644 --- a/app/Space/Updater.php +++ b/app/Space/Updater.php @@ -48,36 +48,37 @@ class Updater File::makeDirectory($temp_path2); } - $file = $temp_path . '/upload.zip'; - - // Add content to the Zip file - $uploaded = is_int(file_put_contents($file, $data)) ? true : false; - - if (!$uploaded) { - return false; - } - - // Unzip the file - $zip = new ZipArchive(); - - if ($zip->open($file)) { - $zip->extractTo($temp_path2); - } - - $zip->close(); - - // Delete zip file - File::delete($file); - - if (!File::copyDirectory($temp_path2.'/Crater', base_path())) { - return false; - } - - // Delete temp directory - File::deleteDirectory($temp_path); - File::deleteDirectory($temp_path2); - try { + + $file = $temp_path . '/upload.zip'; + + // Add content to the Zip file + $uploaded = is_int(file_put_contents($file, $data)) ? true : false; + + if (!$uploaded) { + return false; + } + + // Unzip the file + $zip = new ZipArchive(); + + if ($zip->open($file)) { + $zip->extractTo($temp_path2); + } + + $zip->close(); + + // Delete zip file + File::delete($file); + + if (!File::copyDirectory($temp_path2.'/Crater', base_path())) { + return false; + } + + // Delete temp directory + File::deleteDirectory($temp_path); + File::deleteDirectory($temp_path2); + if (!$isMinor) { event(new UpdateFinished($installed, $version)); } @@ -88,6 +89,13 @@ class Updater 'data' => [] ]; } catch (\Exception $e) { + + if (File::isDirectory($temp_path)) { + // Delete temp directory + File::deleteDirectory($temp_path); + File::deleteDirectory($temp_path2); + } + return [ 'success' => false, 'errors' => 'Update error',