From 7e426cfb5dffaf5b097d9468f808461c7405c81e Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Thu, 16 Mar 2023 15:13:52 +0100 Subject: [PATCH] init --- core/module/install/install.php | 4 +-- core/module/install/view/update/update.js.php | 35 ++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/core/module/install/install.php b/core/module/install/install.php index 997c5fd1..c612c25d 100644 --- a/core/module/install/install.php +++ b/core/module/install/install.php @@ -296,14 +296,14 @@ class install extends common case 2: file_put_contents(self::TEMP_DIR . 'update.tar.gz', helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/update.tar.gz')); $md5origin = helper::getUrlContents(common::ZWII_UPDATE_URL . common::ZWII_UPDATE_CHANNEL . '/update.md5'); - $md5origin = (explode(' ', $md5origin)); + $md5origin = explode(' ', $md5origin); $md5target = md5_file(self::TEMP_DIR . 'update.tar.gz'); // Valeurs en sortie $this->addOutput([ 'display' => self::DISPLAY_JSON, 'content' => [ 'success' => $md5origin[0] === $md5target, - 'data' => null + 'data' => $md5origin[0] === $md5target ? null : json_encode("Checksum error") ] ]); break; diff --git a/core/module/install/view/update/update.js.php b/core/module/install/view/update/update.js.php index 0252e321..25cc24f2 100644 --- a/core/module/install/view/update/update.js.php +++ b/core/module/install/view/update/update.js.php @@ -1,6 +1,7 @@ function step(i, data) { var errors = ["", "", "", ""]; - $(".installUpdateProgressText").hide(), $(".installUpdateProgressText[data-id=" + i + "]").show(), $.ajax({ + $(".installUpdateProgressText").hide(), $(".installUpdateProgressText[data-id=" + i + "]").show(); + $.ajax({ type: "POST", url: "?install/steps", data: { @@ -8,13 +9,37 @@ function step(i, data) { data: data }, success: function (result) { + if (!result.success) { // Vérification de la propriété "success" + // Appel de la fonction de gestion d'erreur + showError(i, result, errors); + return; + } setTimeout((function () { - !0 === result.success ? 4 === i ? ($("#installUpdateSuccess").show(), $("#installUpdateEnd").removeClass("disabled"), $("#installUpdateProgress").hide()) : step(i + 1, result.data) : ($("#installUpdateErrorStep").text(errors[i]), $("#installUpdateError").show(), $("#installUpdateEnd").removeClass("disabled"), $("#installUpdateProgress").hide(), console.error(result), $("#installUpdateErrorMessage").text(result.replace(/<[^p].*?>/g, ""))) + if (4 === i) { + $("#installUpdateSuccess").show(); + $("#installUpdateEnd").removeClass("disabled"); + $("#installUpdateProgress").hide(); + } else { + step(i + 1, result.data); + } }), 2e3) }, error: function (xhr) { - $("#installUpdateErrorStep").text(errors[1]), $("#installUpdateError").show(), $("#installUpdateEnd").removeClass("disabled"), $("#installUpdateProgress").hide(), console.error(xhr.responseText), $("#installUpdateErrorMessage").text(xhr.responseText.replace(/<[^p].*?>/g, "")) + // Appel de la fonction de gestion d'erreur + showError(1, xhr.responseText, errors); } - }) + }); } -$(window).on("load", step(1, null)); \ No newline at end of file + +function showError(step, message, errors) { + $("#installUpdateErrorStep").text(errors[step]); + $("#installUpdateError").show(); + $("#installUpdateEnd").removeClass("disabled"); + $("#installUpdateProgress").hide(); + console.error(message); + $("#installUpdateErrorMessage").text(message.replace(/<[^p].*?>/g, "")); +} + +$(window).on("load", function() { + step(1, null); +});