mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 20:21:10 -04:00
refactor upadater
This commit is contained in:
@ -48,36 +48,37 @@ class Updater
|
|||||||
File::makeDirectory($temp_path2);
|
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 {
|
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) {
|
if (!$isMinor) {
|
||||||
event(new UpdateFinished($installed, $version));
|
event(new UpdateFinished($installed, $version));
|
||||||
}
|
}
|
||||||
@ -88,6 +89,13 @@ class Updater
|
|||||||
'data' => []
|
'data' => []
|
||||||
];
|
];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
if (File::isDirectory($temp_path)) {
|
||||||
|
// Delete temp directory
|
||||||
|
File::deleteDirectory($temp_path);
|
||||||
|
File::deleteDirectory($temp_path2);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'errors' => 'Update error',
|
'errors' => 'Update error',
|
||||||
|
|||||||
Reference in New Issue
Block a user