From d9a02909d6b5cb52a81006a26e22787a15d1baae Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Sun, 12 Jan 2025 11:06:01 +0100 Subject: [PATCH] feat(update): added possibility to activate maintenance mode in online update, closes #3321 --- CHANGELOG.md | 1 + .../admin/assets/src/configuration/upgrade.js | 42 +++++++++++++++++-- .../admin/configuration/upgrade.twig | 7 ++++ phpmyfaq/src/admin-api-routes.php | 5 +++ .../Api/ConfigurationController.php | 23 +++++++++- .../Administration/UpdateController.php | 5 +++ phpmyfaq/translations/language_de.php | 1 + phpmyfaq/translations/language_en.php | 1 + 8 files changed, 81 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a716c17d3..ca233532cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This is a log of major user-visible changes in each phpMyFAQ release. - added configuration to edit robots.txt (Thorsten) - added Symfony Routing for administration backend (Thorsten) - added code snippets plugin with syntax highlighting in WYSIWYG editor (Thorsten) +- improved online update feature (Thorsten) - migrated from WYSIWYG editor from TinyMCE to Jodit Editor (Thorsten) - migrated from Webpack to Vite v6 (Thorsten) - migrated from Jest to vitest (Thorsten) diff --git a/phpmyfaq/admin/assets/src/configuration/upgrade.js b/phpmyfaq/admin/assets/src/configuration/upgrade.js index a86512b129..33bb81cbaa 100644 --- a/phpmyfaq/admin/assets/src/configuration/upgrade.js +++ b/phpmyfaq/admin/assets/src/configuration/upgrade.js @@ -23,6 +23,7 @@ export const handleCheckForUpdates = () => { const downloadButton = document.getElementById('pmf-button-download-now'); const extractButton = document.getElementById('pmf-button-extract-package'); const installButton = document.getElementById('pmf-button-install-package'); + const buttonActivate = document.getElementById('pmf-button-activate-maintenance-mode'); // Health Check if (checkHealthButton) { @@ -35,15 +36,16 @@ export const handleCheckForUpdates = () => { if (responseData.success) { card.classList.add('text-bg-success'); - result.replaceWith(addElement('p', { innerText: responseData.success })); + result.replaceWith(addElement('p', { id: 'result-check-health', innerText: responseData.success })); } if (responseData.warning) { card.classList.add('text-bg-warning'); - result.replaceWith(addElement('p', { innerText: responseData.warning })); + result.replaceWith(addElement('p', { id: 'result-check-health', innerText: responseData.warning })); + buttonActivate.classList.remove('d-none'); } if (responseData.error) { card.classList.add('text-bg-danger'); - result.replaceWith(addElement('p', { innerText: responseData.error })); + result.replaceWith(addElement('p', { id: 'result-check-health', innerText: responseData.error })); } } catch (error) { if (error.cause && error.cause.response) { @@ -56,6 +58,40 @@ export const handleCheckForUpdates = () => { }); } + // Activate Maintenance Mode + if (buttonActivate) { + buttonActivate.addEventListener('click', async (event) => { + event.preventDefault(); + try { + const response = await fetch('./api/configuration/activate-maintenance-mode', { + method: 'POST', + headers: { + Accept: 'application/json, text/plain, */*', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ csrf: buttonActivate.getAttribute('data-pmf-csrf') }), + }); + + if (!response.ok) { + throw new Error('Network response was not ok'); + } + + const responseData = await response.json(); + const result = document.getElementById('result-check-health'); + const card = document.getElementById('pmf-update-step-health-check'); + + if (responseData.success) { + card.classList.remove('text-bg-warning'); + card.classList.add('text-bg-success'); + result.replaceWith(addElement('p', { innerText: responseData.success })); + buttonActivate.classList.add('d-none'); + } + } catch (error) { + console.error(error); + } + }); + } + // Check Update if (checkUpdateButton) { checkUpdateButton.addEventListener('click', async (event) => { diff --git a/phpmyfaq/assets/templates/admin/configuration/upgrade.twig b/phpmyfaq/assets/templates/admin/configuration/upgrade.twig index 28fca953c8..28e1568927 100644 --- a/phpmyfaq/assets/templates/admin/configuration/upgrade.twig +++ b/phpmyfaq/assets/templates/admin/configuration/upgrade.twig @@ -19,6 +19,13 @@

{{ 'msgHealthCheck' | translate }}

+ +
+ +