From 9a36e182923b69e4c4ff39d08f0652631c1da2b4 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Fri, 29 Sep 2023 20:37:50 +0200 Subject: [PATCH] feat: added verification to update process (#2492) --- phpmyfaq/.htaccess | 1 + phpmyfaq/admin/api/configuration-list.php | 6 +- .../admin/assets/src/configuration/upgrade.js | 12 ++-- .../templates/configuration/upgrade.twig | 10 +++- phpmyfaq/src/admin-routes.php | 5 ++ .../Administration/UpdateController.php | 59 ++++++++++++++++--- phpmyfaq/src/phpMyFAQ/Enums/ReleaseType.php | 2 +- phpmyfaq/src/phpMyFAQ/Setup/Installer.php | 2 +- phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php | 48 +++++++++------ tests/content/user/attachments/.gitkeep | 0 tests/content/user/images/.gitkeep | 0 tests/phpMyFAQ/Setup/UpgradeTest.php | 9 ++- 12 files changed, 110 insertions(+), 44 deletions(-) create mode 100644 tests/content/user/attachments/.gitkeep create mode 100644 tests/content/user/images/.gitkeep diff --git a/phpmyfaq/.htaccess b/phpmyfaq/.htaccess index a55c35497c..d487028e80 100644 --- a/phpmyfaq/.htaccess +++ b/phpmyfaq/.htaccess @@ -139,6 +139,7 @@ RewriteRule user/request-removal index.php?action=request-remo RewriteRule user/logout index.php?action=logout [L,QSA] # Administration API +RewriteRule admin/api/health-check admin/api/updates.php RewriteRule admin/api/versions admin/api/updates.php RewriteRule admin/api/update-check admin/api/updates.php RewriteRule admin/api/download-package admin/api/updates.php diff --git a/phpmyfaq/admin/api/configuration-list.php b/phpmyfaq/admin/api/configuration-list.php index eb3096ecb3..514b3adbb7 100755 --- a/phpmyfaq/admin/api/configuration-list.php +++ b/phpmyfaq/admin/api/configuration-list.php @@ -248,9 +248,9 @@ function renderInputForm(mixed $key, string $type): void (ReleaseType::DEVELOPMENT->value === $faqConfig->get($key)) ? 'selected' : '' ); printf( - '', - ReleaseType::RELEASE->value, - (ReleaseType::RELEASE->value === $faqConfig->get($key)) ? 'selected' : '' + '', + ReleaseType::STABLE->value, + (ReleaseType::STABLE->value === $faqConfig->get($key)) ? 'selected' : '' ); printf( '', diff --git a/phpmyfaq/admin/assets/src/configuration/upgrade.js b/phpmyfaq/admin/assets/src/configuration/upgrade.js index ee76c66ca3..790cc2e5a0 100644 --- a/phpmyfaq/admin/assets/src/configuration/upgrade.js +++ b/phpmyfaq/admin/assets/src/configuration/upgrade.js @@ -63,7 +63,7 @@ export const handleCheckForUpdates = () => { if (downloadButton) { downloadButton.addEventListener('click', (event) => { event.preventDefault(); - fetch(window.location.pathname + 'api/download-package/nightly', { + fetch(window.location.pathname + 'api/download-package/3.2.1', { method: 'POST', headers: { Accept: 'application/json, text/plain, */*', @@ -80,14 +80,16 @@ export const handleCheckForUpdates = () => { const result = document.getElementById('result-download-nightly'); if (result) { if (response.version === 'current') { - result.replaceWith(addElement('p', { innerText: response.message })); + result.replaceWith(addElement('p', { innerText: response.success })); } else { - result.replaceWith(addElement('p', { innerText: response.message })); + result.replaceWith(addElement('p', { innerText: response.success })); } } }) - .catch((error) => { - console.error(error); + .catch(async (error) => { + const errorMessage = await error.cause.response.json(); + const result = document.getElementById('result-download-nightly'); + result.replaceWith(addElement('p', { innerText: errorMessage.error })); }); }); } diff --git a/phpmyfaq/admin/assets/templates/configuration/upgrade.twig b/phpmyfaq/admin/assets/templates/configuration/upgrade.twig index c7d36cc785..de136a5e6b 100644 --- a/phpmyfaq/admin/assets/templates/configuration/upgrade.twig +++ b/phpmyfaq/admin/assets/templates/configuration/upgrade.twig @@ -17,7 +17,15 @@ You can check for new versions of phpMyFAQ, re-install or update your installation.

- + +
+ + +
+ +