From c0ecf6ce730f0622dfd0658ef13cc715cbd870fa Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sun, 5 Jul 2026 21:13:35 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20pre-update=20modal=20phase=202=20?= =?UTF-8?q?=E2=80=94=20auto-run=20backup=20on=20Update=20click=20(#196)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opt-in param preupdate_auto_intercept (off by default). When enabled the injected update-page script wraps window.Joomla.submitbutton so clicking the toolbar Update button first pops the progress modal, runs the pre-update backup, and re-issues the original update task on success. - Matches only update.update / update.install (not Find Updates / Clear Cache, which also start with 'update'). - Reuses the phase-1 overlay + ajax.preupdateAck throttle so the subsequent server-side onExtensionBeforeUpdate backup is skipped. - The manual 'Back up now' notice remains a fallback for flows that don't route through submitbutton (e.g. some com_joomlaupdate paths). Refs #196 Claude-Session: https://claude.ai/code/session_01WbGBN9VyRK61zczYWcCQ2i --- CHANGELOG.md | 3 +- .../packages/com_mokosuitebackup/config.xml | 12 ++++ .../language/en-GB/com_mokosuitebackup.ini | 2 + .../language/en-US/com_mokosuitebackup.ini | 2 + .../media/js/update-backup.js | 59 +++++++++++++++++++ .../src/Extension/MokoSuiteBackup.php | 7 ++- 6 files changed, 81 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0733ee39..e7e17c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## [Unreleased] ### Added -- Pre-update backup **notice + live-progress modal** on the admin update pages (Joomla Update and Extensions → Update). Because the server-side `onExtensionBeforeUpdate` backup runs synchronously and can't drive a browser modal, the system plugin now injects a "back up before you update" notice with a **Back up now** button that runs the same stepped backup as the dashboard and shows a live progress bar. On success it pings a new `ajax.preupdateAck` endpoint, which arms the same throttle the server-side hook checks — so clicking Joomla's Update afterwards won't run a duplicate backup. Gated by the existing `show_update_notice` + `backup_before_update` params. (Auto-intercepting the Update button is the planned phase-2 follow-up — see #196.) (#196) +- Pre-update backup **notice + live-progress modal** on the admin update pages (Joomla Update and Extensions → Update). Because the server-side `onExtensionBeforeUpdate` backup runs synchronously and can't drive a browser modal, the system plugin now injects a "back up before you update" notice with a **Back up now** button that runs the same stepped backup as the dashboard and shows a live progress bar. On success it pings a new `ajax.preupdateAck` endpoint, which arms the same throttle the server-side hook checks — so clicking Joomla's Update afterwards won't run a duplicate backup. Gated by the existing `show_update_notice` + `backup_before_update` params. (#196) +- Pre-update modal **phase 2 — "Auto-run on Update click"** (new opt-in param `preupdate_auto_intercept`, off by default). When enabled, clicking the toolbar **Update** button on the Joomla Update / Extensions-update page first pops the backup progress modal, runs the pre-update backup, then automatically continues the update. Implemented by wrapping `Joomla.submitbutton` for the `update.update` / `update.install` tasks only (Find Updates / Clear Cache are untouched); the manual "Back up now" notice remains as a fallback for any flow that doesn't route through `submitbutton`. (#196) - Retention now prunes **remote** copies too: when a backup is pruned by age/count, its archive is deleted from every enabled remote destination (SFTP / FTP / S3 / Google Drive), not just the local copy. Each uploader gained an idempotent `delete()` method (already-absent file = success), and removal is best-effort — a failing destination is logged but never blocks local pruning. The shared standalone `restore.php` is intentionally left in place (every backup overwrites it, so newer backups still depend on it). (#229) ### Changed diff --git a/source/packages/com_mokosuitebackup/config.xml b/source/packages/com_mokosuitebackup/config.xml index 84db7fca..94650c5b 100644 --- a/source/packages/com_mokosuitebackup/config.xml +++ b/source/packages/com_mokosuitebackup/config.xml @@ -151,6 +151,18 @@ + + + + getWebAssetManager()->useScript('core'); $doc->addScriptOptions('plg_system_mokosuitebackup.preupdate', [ - 'ajaxUrl' => Route::_('index.php?option=com_mokosuitebackup&format=json', false), - 'token' => Session::getFormToken(), - 'profileId' => (int) $params->get('default_profile', 1), + 'ajaxUrl' => Route::_('index.php?option=com_mokosuitebackup&format=json', false), + 'token' => Session::getFormToken(), + 'profileId' => (int) $params->get('default_profile', 1), + 'autoIntercept' => (bool) (int) $params->get('preupdate_auto_intercept', 0), 'labels' => [ 'notice' => Text::_('PLG_SYSTEM_MOKOJOOMBACKUP_UPDATE_NOTICE'), 'backupNow' => Text::_('PLG_SYSTEM_MOKOJOOMBACKUP_BACKUP_NOW'),