Compare commits

...

15 Commits

Author SHA1 Message Date
gitea-actions[bot] f560b0c63e chore(version): pre-release bump to 02.52.19-dev [skip ci] 2026-06-30 18:28:41 +00:00
jmiller 430b25cea5 fix: show progress modal for pre-extension-update backup
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 18s
The pre-update backup ran synchronously in onExtensionBeforeUpdate with
no browser feedback — the page just hung until backup + update finished.

Now the system plugin injects JavaScript on com_installer and
com_joomlaupdate pages that intercepts the update button, shows a
Bootstrap modal with a progress bar, and runs the backup via the
stepped AJAX API (ajax.init + ajax.step). On completion it proceeds
with the original update. On failure it shows Skip & Cancel buttons.

The server-side handler remains as a fallback for CLI/API updates.
A session flag prevents double-running when JS already handled it.

Claude-Session: https://claude.ai/code/session_01MbEjBtsSjPuTWhqqrMS2wG
2026-06-30 13:26:43 -05:00
jmiller ebc692789c chore: sync issue-branch.yml from Template-Generic [skip ci] 2026-06-30 18:12:34 +00:00
gitea-actions[bot] 983ec77dbd chore: promote changelog [Unreleased] → [02.52.18] 2026-06-30 18:12:06 +00:00
gitea-actions[bot] 25cf65f4cf chore(release): build 02.52.18 [skip ci] 2026-06-30 18:11:56 +00:00
jmiller 2d3a697f22 Merge pull request 'fix: remote upload prefix mismatch and restore security file' (#193) from fix/sftp-upload-and-restore-security into main 2026-06-30 18:11:32 +00:00
gitea-actions[bot] 3d9c48f40f chore(version): pre-release bump to 02.52.18-dev [skip ci]
RC Revert / Rename rc/ back to dev/ (pull_request) Has been skipped
Branch Cleanup / Delete merged branch (pull_request) Successful in 1s
Universal: Build & Release / Promote to RC (pull_request) Has been skipped
Universal: Build & Release / Build & Release Pipeline (pull_request) Successful in 33s
Universal: Workflow Sync Trigger / Sync workflows to live repos (pull_request) Successful in 2m23s
2026-06-30 18:00:27 +00:00
jmiller 4093267984 fix: add verbose error_log throughout restore script
Universal: PR Check / Branch Policy (pull_request) Failing after 2s
Joomla: Extension CI / Lint & Validate (pull_request) Failing after 8s
Joomla: Extension CI / Release Readiness Check (pull_request) Failing after 7s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Generic: Repo Health / Access control (pull_request) Successful in 2s
Universal: PR Check / Validate PR (pull_request) Failing after 8s
Generic: Project CI / Lint & Validate (pull_request) Successful in 16s
Universal: PR Check / Secret Scan (pull_request) Successful in 11s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 30s
Universal: Build & Release / Promote to RC (pull_request) Has been skipped
Universal: Build & Release / Build & Release Pipeline (pull_request) Has been skipped
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Successful in 41s
Generic: Project CI / Tests (pull_request) Has been cancelled
Joomla: Extension CI / Tests (PHP 8.2) (pull_request) Has been cancelled
Joomla: Extension CI / Tests (PHP 8.3) (pull_request) Has been cancelled
Joomla: Extension CI / PHPStan Analysis (pull_request) Has been cancelled
Joomla: Extension CI / Build RC Pre-Release (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report: Scripts Governance (pull_request) Has been cancelled
Generic: Repo Health / Report: Repository Health (pull_request) Has been cancelled
Every action handler now logs entry, key parameters, outcomes, and
failures to PHP error_log. Security file creation logs directory
permissions, PHP user, and the specific error when file_put_contents
fails. Database import logs SQL file size, statement counts, and
individual errors. Cleanup logs each file removal success/failure.

Claude-Session: https://claude.ai/code/session_01MbEjBtsSjPuTWhqqrMS2wG
2026-06-30 12:59:59 -05:00
gitea-actions[bot] 236609341f chore(version): pre-release bump to 02.52.17-dev [skip ci] 2026-06-30 17:53:59 +00:00
jmiller 20ce945e73 fix: recreate security file if missing while verification is pending
Universal: PR Check / Branch Policy (pull_request) Failing after 1s
Joomla: Extension CI / Release Readiness Check (pull_request) Failing after 6s
Generic: Repo Health / Access control (pull_request) Successful in 1s
Universal: PR Check / Validate PR (pull_request) Failing after 8s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Universal: PR Check / Secret Scan (pull_request) Successful in 9s
Joomla: Extension CI / Lint & Validate (pull_request) Failing after 11s
Generic: Project CI / Lint & Validate (pull_request) Successful in 13s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 22s
Universal: Build & Release / Promote to RC (pull_request) Has been skipped
Universal: Build & Release / Build & Release Pipeline (pull_request) Has been skipped
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Successful in 34s
Generic: Project CI / Tests (pull_request) Has been cancelled
Joomla: Extension CI / Tests (PHP 8.2) (pull_request) Has been cancelled
Joomla: Extension CI / Tests (PHP 8.3) (pull_request) Has been cancelled
Joomla: Extension CI / PHPStan Analysis (pull_request) Has been cancelled
Joomla: Extension CI / Build RC Pre-Release (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report: Scripts Governance (pull_request) Has been cancelled
Generic: Repo Health / Report: Repository Health (pull_request) Has been cancelled
The security file was only written inside the code-generation block
(first page load). If the file was deleted or failed to write, it
was never recreated because the session already held the code. Now
file writing is a separate check that runs whenever verification is
pending and the file is missing.

Claude-Session: https://claude.ai/code/session_01MbEjBtsSjPuTWhqqrMS2wG
2026-06-30 12:53:36 -05:00
gitea-actions[bot] f2f424a565 chore(version): pre-release bump to 02.52.16-dev [skip ci] 2026-06-30 17:50:30 +00:00
jmiller 3a6bb1c783 fix: remote upload prefix mismatch and restore security file visibility
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 23s
Remote uploaders (SFTP, FTP, S3, Google Drive) expect type-prefixed
property names (sftp_host, ftp_port, etc.) but createUploaderFromParams
passes unprefixed keys from the remotes table params JSON. Add prefix
mapping in createUploaderFromParams to bridge the naming gap.

Rename .mokorestore-security.php to mokorestore-security.php (no leading
dot) so the file is visible in file managers and not blocked by web
server dotfile rules. Also clean it up in actionCleanup.

Closes #13

Claude-Session: https://claude.ai/code/session_01MbEjBtsSjPuTWhqqrMS2wG
2026-06-30 12:50:02 -05:00
jmiller 785ffd85a3 chore: sync auto-release.yml from Template-Generic [skip ci] 2026-06-28 20:10:19 +00:00
jmiller 71da4af64b chore: sync issue-branch.yml from Template-Generic [skip ci] 2026-06-28 19:39:25 +00:00
jmiller 4d5711c304 chore: sync auto-release.yml from Template-Generic [skip ci] 2026-06-28 19:39:22 +00:00
23 changed files with 328 additions and 34 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: mokocli.Automation
# VERSION: 01.45.00
# VERSION: 02.52.19
# BRIEF: Auto-create feature branch when an issue is opened
name: "Universal: Issue Branch"
+4 -5
View File
@@ -1,6 +1,10 @@
# Changelog
## [Unreleased]
## [02.52.18] --- 2026-06-30
## [02.52.18] --- 2026-06-30
## [01.45.00] --- 2026-06-28
@@ -32,8 +36,3 @@
- MokoRestore stalling: unhandled promise rejections from network errors or non-JSON responses left UI in loading state
## [01.43.00] --- 2026-06-24
## [01.42.00] --- 2026-06-23
## [01.42.00] --- 2026-06-23
+1 -1
View File
@@ -23,7 +23,7 @@ DEFGROUP: Template-Joomla
INGROUP: Template-Joomla.Documentation
REPO: https://git.mokoconsulting.tech/MokoConsulting/Template-Joomla
PATH: /SECURITY.md
VERSION: 01.45.00
VERSION: 02.52.19
BRIEF: Security vulnerability reporting and handling policy
-->
@@ -7,7 +7,7 @@
-->
<extension type="component" method="upgrade">
<name>MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-02</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -0,0 +1 @@
/* 02.52.16 — no schema changes */
@@ -0,0 +1 @@
/* 02.52.17 — no schema changes */
@@ -0,0 +1 @@
/* 02.52.18 — no schema changes */
@@ -0,0 +1 @@
/* 02.52.19 — no schema changes */
@@ -84,6 +84,24 @@ class AjaxController extends BaseController
$this->sendJson($result);
}
/**
* Mark that the JS-driven pre-update backup has completed so the
* server-side onExtensionBeforeUpdate handler skips its own run.
* POST: task=ajax.markPreUpdateDone
*/
public function markPreUpdateDone(): void
{
if (!Session::checkToken('get') && !Session::checkToken('post')) {
$this->sendJson(['error' => true, 'message' => 'Invalid token'], 403);
return;
}
Factory::getSession()->set('mokosuitebackup.preupdate_js_done', true);
$this->sendJson(['success' => true]);
}
/**
* Browse server directories for the folder picker field.
* POST: task=ajax.browseDir&path=/some/path
@@ -547,7 +547,16 @@ class BackupEngine
*/
private function createUploaderFromParams(string $type, array $params): RemoteUploaderInterface
{
$fake = (object) $params;
$prefixMap = ['ftp' => 'ftp_', 'sftp' => 'sftp_', 's3' => 's3_', 'google_drive' => 'gdrive_'];
$prefix = $prefixMap[$type] ?? '';
$prefixed = [];
foreach ($params as $key => $value) {
$prefixed[$prefix . $key] = $value;
}
$fake = (object) $prefixed;
return match ($type) {
'ftp' => new FtpUploader($fake),
@@ -346,6 +346,9 @@ define('MOKOJOOMBACKUP_RESTORE', 1);
define('RESTORE_DIR', __DIR__);
define('BACKUP_FILE', RESTORE_DIR . '/site-backup.zip');
error_log('MokoRestore: Script loaded — RESTORE_DIR=' . RESTORE_DIR);
error_log('MokoRestore: PHP ' . PHP_VERSION . ', SAPI=' . php_sapi_name() . ', memory_limit=' . ini_get('memory_limit'));
session_start();
if (empty($_SESSION['restore_token'])) {
@@ -358,25 +361,37 @@ $token = $_SESSION['restore_token'];
// Write a security file to the web root with a random code.
// The user must read the code from the file and enter it in the browser
// to prove they have filesystem access before any restore actions are allowed.
$securityFile = RESTORE_DIR . '/.mokorestore-security.php';
$securityFile = RESTORE_DIR . '/mokorestore-security.php';
$securityCode = $_SESSION['security_code'] ?? '';
if (empty($securityCode)) {
$securityCode = strtoupper(substr(bin2hex(random_bytes(4)), 0, 8));
$_SESSION['security_code'] = $securityCode;
$_SESSION['security_verified'] = false;
}
// Write (or recreate) the security file whenever verification is still pending
if (empty($_SESSION['security_verified']) && !is_file($securityFile)) {
error_log('MokoRestore: Writing security file: ' . $securityFile);
error_log('MokoRestore: Target directory: ' . RESTORE_DIR . ' (writable: ' . (is_writable(RESTORE_DIR) ? 'yes' : 'NO') . ')');
// Write security file with the code
$securityContent = "<?php die('MokoRestore Security Code: " . $securityCode . "'); ?>\n"
. "MokoRestore Security Verification\n"
. "==================================\n"
. "Code: " . $securityCode . "\n"
. "Enter this code in the MokoRestore browser interface to proceed.\n"
. "This file will be deleted automatically after verification.\n";
if (file_put_contents($securityFile, $securityContent) === false) {
// Cannot write security file — skip verification to avoid locking user out
$written = @file_put_contents($securityFile, $securityContent);
if ($written === false) {
$err = error_get_last();
error_log('MokoRestore: FAILED to write security file — ' . ($err['message'] ?? 'unknown error'));
error_log('MokoRestore: Directory permissions: ' . decoct(@fileperms(RESTORE_DIR) & 0777) . ', owner: ' . @fileowner(RESTORE_DIR) . ', PHP user: ' . (function_exists('posix_getuid') ? posix_getuid() : 'n/a'));
error_log('MokoRestore: Security verification SKIPPED — user will not be challenged');
$_SESSION['security_verified'] = true;
error_log('MokoRestore: Cannot write security file — verification skipped (check directory permissions)');
} else {
error_log('MokoRestore: Security file created (' . $written . ' bytes)');
}
}
@@ -387,15 +402,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
if ($inputCode === $securityCode) {
$_SESSION['security_verified'] = true;
error_log('MokoRestore: Security code VERIFIED');
// Delete the security file
if (is_file($securityFile)) {
@unlink($securityFile);
error_log('MokoRestore: Security file deleted');
}
echo json_encode(['success' => true, 'message' => 'Security verified']);
} else {
echo json_encode(['success' => false, 'message' => 'Incorrect security code. Check the file: .mokorestore-security.php']);
error_log('MokoRestore: Security code REJECTED (input=' . $inputCode . ')');
echo json_encode(['success' => false, 'message' => 'Incorrect security code. Check the file: mokorestore-security.php']);
}
exit;
@@ -414,7 +431,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
}
if (!$securityVerified) {
echo json_encode(['success' => false, 'message' => 'Security verification required. Enter the code from .mokorestore-security.php']);
echo json_encode(['success' => false, 'message' => 'Security verification required. Enter the code from mokorestore-security.php']);
exit;
}
@@ -424,9 +441,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
@ignore_user_abort(true);
try {
error_log('MokoRestore: Action dispatched — ' . $_POST['action']);
$result = handleAction($_POST['action'], $_POST);
error_log('MokoRestore: Action ' . $_POST['action'] . ' completed — ' . ($result['success'] ? 'OK' : 'FAIL: ' . ($result['message'] ?? '')));
echo json_encode($result);
} catch (Throwable $e) {
error_log('MokoRestore: Action ' . $_POST['action'] . ' EXCEPTION — ' . $e->getMessage());
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
@@ -551,10 +571,14 @@ function actionPreflight(): array
function actionExtract(array $data): array
{
error_log('MokoRestore: Extract — target=' . BACKUP_FILE . ', exists=' . (file_exists(BACKUP_FILE) ? 'yes' : 'no'));
if (!file_exists(BACKUP_FILE)) {
throw new RuntimeException('Backup file not found: site-backup.zip');
}
error_log('MokoRestore: Extract — archive size=' . number_format(filesize(BACKUP_FILE) / 1048576, 2) . ' MB');
$zip = new ZipArchive();
if ($zip->open(BACKUP_FILE) !== true) {
@@ -591,6 +615,8 @@ function actionExtract(array $data): array
$count = $zip->numFiles;
$zip->close();
error_log('MokoRestore: Extract — ' . $count . ' files extracted to ' . RESTORE_DIR);
// Pre-fill from configuration.php.bak (sanitized backup) or
// configuration.php (legacy/unsanitized backup). Skip [SANITIZED:] values.
$existingConfig = [];
@@ -719,6 +745,8 @@ function actionDatabase(array $data): array
$user = $data['db_user'] ?? '';
$pass = $data['db_pass'] ?? '';
error_log('MokoRestore: Database import — host=' . $host . ', db=' . $name . ', user=' . $user);
if (empty($name) || empty($user)) {
throw new RuntimeException('Database name and user are required');
}
@@ -726,9 +754,12 @@ function actionDatabase(array $data): array
$sqlFile = RESTORE_DIR . '/database.sql';
if (!is_file($sqlFile)) {
error_log('MokoRestore: Database import — no database.sql found, skipping');
return ['success' => true, 'message' => 'No database.sql found — skipped', 'statements' => 0, 'errors' => 0];
}
error_log('MokoRestore: Database import — SQL file size=' . number_format(filesize($sqlFile) / 1048576, 2) . ' MB');
$pdo = new PDO(
"mysql:host={$host};dbname={$name};charset=utf8mb4",
$user,
@@ -835,6 +866,14 @@ function actionDatabase(array $data): array
$msg .= " ({$errors} warnings)";
}
error_log('MokoRestore: Database import — ' . $msg);
if (!empty($errorList)) {
foreach ($errorList as $i => $err) {
error_log('MokoRestore: DB error ' . ($i + 1) . ': ' . $err);
}
}
return [
'success' => ($statements > 0 || $errors === 0),
'message' => $msg,
@@ -847,6 +886,7 @@ function actionDatabase(array $data): array
function actionConfig(array $data): array
{
error_log('MokoRestore: Config rebuild started');
$host = $data['db_host'] ?? 'localhost';
$dbName = $data['db_name'] ?? '';
$dbUser = $data['db_user'] ?? '';
@@ -867,6 +907,7 @@ function actionConfig(array $data): array
// debug, cache, SEF, editor, etc.). Fall back to existing config
// for legacy/unsanitized backups, or build from scratch if neither exists.
$basePath = is_file($bakPath) ? $bakPath : (is_file($configPath) ? $configPath : null);
error_log('MokoRestore: Config — base template: ' . ($basePath ?? 'none (building from scratch)'));
if ($basePath !== null) {
$config = file_get_contents($basePath);
@@ -919,9 +960,12 @@ function actionConfig(array $data): array
}
if (file_put_contents($configPath, $config) === false) {
error_log('MokoRestore: Config — FAILED to write ' . $configPath);
return ['success' => false, 'message' => 'Failed to write Joomla config file — check directory permissions'];
}
error_log('MokoRestore: Config — written to ' . $configPath . ' (' . filesize($configPath) . ' bytes)');
// Remove .bak after successful rebuild
if (is_file($bakPath)) {
@unlink($bakPath);
@@ -1175,6 +1219,8 @@ function actionResetAdmin(array $data): array
$userId = (int) ($data['admin_id'] ?? 0);
$password = $data['new_password'] ?? '';
error_log('MokoRestore: Admin password reset — user_id=' . $userId);
if ($userId < 1 || strlen($password) < 8) {
throw new RuntimeException('Select an admin and enter a password (8+ characters)');
}
@@ -1188,6 +1234,7 @@ function actionResetAdmin(array $data): array
throw new RuntimeException('User not found or password unchanged');
}
error_log('MokoRestore: Admin password reset — success');
return ['success' => true, 'message' => 'Admin password updated successfully'];
}
@@ -1197,6 +1244,7 @@ function actionPostRestore(array $data): array
$prefix = getValidatedPrefix($data);
$tasks = json_decode($data['tasks'] ?? '[]', true) ?: [];
$results = [];
error_log('MokoRestore: Post-restore — ' . count($tasks) . ' task(s): ' . implode(', ', $tasks));
foreach ($tasks as $task) {
try {
@@ -1319,6 +1367,7 @@ function actionProvision(array $data): array
$prefix = getValidatedPrefix($data);
$tasks = json_decode($data['tasks'] ?? '[]', true) ?: [];
$results = [];
error_log('MokoRestore: Provisioning — ' . count($tasks) . ' task(s): ' . implode(', ', $tasks));
foreach ($tasks as $task) {
try {
@@ -1395,16 +1444,24 @@ function actionProvision(array $data): array
function actionCleanup(): array
{
error_log('MokoRestore: Cleanup started');
$removed = [];
foreach (['database.sql', 'site-backup.zip'] as $file) {
foreach (['database.sql', 'site-backup.zip', 'mokorestore-security.php'] as $file) {
$path = RESTORE_DIR . '/' . $file;
if (is_file($path) && @unlink($path)) {
$removed[] = $file;
if (is_file($path)) {
if (@unlink($path)) {
$removed[] = $file;
error_log('MokoRestore: Cleanup — removed ' . $file);
} else {
error_log('MokoRestore: Cleanup — FAILED to remove ' . $file);
}
}
}
error_log('MokoRestore: Cleanup complete — removed ' . count($removed) . ' file(s)');
return [
'success' => true,
'message' => 'Removed: ' . (empty($removed) ? '(none)' : implode(', ', $removed))
@@ -1570,14 +1627,14 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica N
<!-- Step 0: Security Verification -->
<div class="mr-panel <?php echo $securityVerified ? '' : 'visible'; ?>" id="panel0">
<h2>Security Verification</h2>
<p class="mr-desc">To prevent unauthorized access, enter the security code from the file <code>.mokorestore-security.php</code> in your site root.</p>
<p class="mr-desc">To prevent unauthorized access, enter the security code from the file <code>mokorestore-security.php</code> in your site root.</p>
<div style="border:1px solid #e2e8f0;border-radius:8px;padding:1.25rem;margin-bottom:1.25rem;background:#f8fafc">
<div style="font-weight:600;font-size:0.9rem;color:#334155;margin-bottom:1rem;display:flex;align-items:center;gap:0.5rem">
<span style="font-size:1.1rem">&#128274;</span> How to find the code
</div>
<ol style="margin:0;padding-left:1.25rem;color:#475569;font-size:0.9rem;line-height:1.6">
<li>Connect to your server via FTP, SSH, or file manager</li>
<li>Open <code>.mokorestore-security.php</code> in the site root directory</li>
<li>Open <code>mokorestore-security.php</code> in the site root directory</li>
<li>Copy the 8-character code and enter it below</li>
</ol>
</div>
@@ -889,7 +889,16 @@ class SteppedBackupEngine
*/
private function createUploaderFromParams(string $type, array $params): RemoteUploaderInterface
{
$fake = (object) $params;
$prefixMap = ['ftp' => 'ftp_', 'sftp' => 'sftp_', 's3' => 's3_', 'google_drive' => 'gdrive_'];
$prefix = $prefixMap[$type] ?? '';
$prefixed = [];
foreach ($params as $key => $value) {
$prefixed[$prefix . $key] = $value;
}
$fake = (object) $prefixed;
return match ($type) {
'ftp' => new FtpUploader($fake),
@@ -8,7 +8,7 @@
-->
<extension type="module" client="administrator" method="upgrade">
<name>mod_mokosuitebackup_cpanel</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-23</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -7,7 +7,7 @@
-->
<extension type="plugin" group="actionlog" method="upgrade">
<name>Action Log - MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-04</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -7,7 +7,7 @@
-->
<extension type="plugin" group="console" method="upgrade">
<name>Console - MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-04</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -7,7 +7,7 @@
-->
<extension type="plugin" group="content" method="upgrade">
<name>Content - MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-04</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="quickicon" method="upgrade">
<name>Quick Icon - MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-02</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -7,7 +7,7 @@
-->
<extension type="plugin" group="system" method="upgrade">
<name>System - MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-02</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -28,6 +28,7 @@ final class MokoSuiteBackup extends CMSPlugin implements SubscriberInterface
return [
'onAfterInitialise' => 'onAfterInitialise',
'onAfterRoute' => 'onAfterRoute',
'onBeforeRender' => 'onBeforeRender',
'onExtensionBeforeUpdate' => 'onExtensionBeforeUpdate',
'onExtensionBeforeUninstall' => 'onExtensionBeforeUninstall',
];
@@ -347,10 +348,52 @@ final class MokoSuiteBackup extends CMSPlugin implements SubscriberInterface
}
/**
* Run a backup before any extension is updated.
* Inject JavaScript on installer/update pages to show a backup progress
* modal before extension updates proceed.
*/
public function onBeforeRender(Event $event): void
{
$app = $this->getApplication();
if (!$app->isClient('administrator')) {
return;
}
$option = $app->input->getCmd('option', '');
$view = $app->input->getCmd('view', '');
if ($option !== 'com_installer' && $option !== 'com_joomlaupdate') {
return;
}
$params = ComponentHelper::getParams('com_mokosuitebackup');
if (!(int) $params->get('backup_before_update', 0)) {
return;
}
$profileId = (int) $params->get('default_profile', 1);
$token = \Joomla\CMS\Session\Session::getFormToken();
$js = $this->getPreUpdateBackupScript($profileId, $token);
$app->getDocument()->addScriptDeclaration($js);
}
/**
* Run a backup before any extension is updated (server-side fallback
* for CLI/API updates where JavaScript is not available).
*/
public function onExtensionBeforeUpdate(Event $event): void
{
$session = Factory::getSession();
if ($session->get('mokosuitebackup.preupdate_js_done', false)) {
$session->set('mokosuitebackup.preupdate_js_done', false);
return;
}
$this->runPreActionBackup('backup_before_update', 'Pre-update backup');
}
@@ -408,6 +451,161 @@ final class MokoSuiteBackup extends CMSPlugin implements SubscriberInterface
}
}
/**
* Build the inline JavaScript that intercepts extension update actions
* and runs a stepped backup with a progress modal first.
*/
private function getPreUpdateBackupScript(int $profileId, string $token): string
{
$baseUrl = \Joomla\CMS\Uri\Uri::base() . 'index.php?option=com_mokosuitebackup&format=json&' . $token . '=1';
return <<<JS
document.addEventListener('DOMContentLoaded', function() {
var msbOrigSubmit = Joomla.submitbutton;
var msbBackupRunning = false;
var msbPendingTask = null;
// Create modal
var msbModal = document.createElement('div');
msbModal.id = 'msbPreUpdateModal';
msbModal.className = 'modal fade';
msbModal.setAttribute('tabindex', '-1');
msbModal.setAttribute('data-bs-backdrop', 'static');
msbModal.setAttribute('data-bs-keyboard', 'false');
msbModal.innerHTML = '<div class="modal-dialog modal-dialog-centered"><div class="modal-content">'
+ '<div class="modal-header"><h5 class="modal-title"><span class="icon-archive me-2"></span>Pre-Update Backup</h5></div>'
+ '<div class="modal-body">'
+ '<p id="msbStatusText">Creating a backup before updating...</p>'
+ '<div class="progress" style="height:24px"><div id="msbProgressBar" class="progress-bar progress-bar-striped progress-bar-animated" style="width:0%">0%</div></div>'
+ '<div id="msbLogArea" style="max-height:120px;overflow-y:auto;font-size:0.8rem;color:#64748b;margin-top:12px;font-family:monospace;white-space:pre-wrap"></div>'
+ '</div>'
+ '<div class="modal-footer" id="msbFooter" style="display:none">'
+ '<button type="button" class="btn btn-secondary" id="msbSkipBtn">Skip & Update</button>'
+ '<button type="button" class="btn btn-danger" id="msbCancelBtn">Cancel</button>'
+ '</div>'
+ '</div></div>';
document.body.appendChild(msbModal);
var bsModal = new bootstrap.Modal(msbModal);
function msbUpdateProgress(pct, msg) {
var bar = document.getElementById('msbProgressBar');
bar.style.width = pct + '%';
bar.textContent = pct + '%';
if (msg) document.getElementById('msbStatusText').textContent = msg;
}
function msbLog(msg) {
var log = document.getElementById('msbLogArea');
log.textContent += msg + '\\n';
log.scrollTop = log.scrollHeight;
}
function msbShowFooter() {
document.getElementById('msbFooter').style.display = '';
}
function msbFinish(success) {
msbBackupRunning = false;
if (success && msbPendingTask) {
msbUpdateProgress(100, 'Backup complete — proceeding with update...');
// Mark JS backup done so server-side handler skips
fetch('{$baseUrl}&task=ajax.markPreUpdateDone', {method:'POST', headers:{'X-Requested-With':'XMLHttpRequest'}});
setTimeout(function() {
bsModal.hide();
msbOrigSubmit.call(Joomla, msbPendingTask);
msbPendingTask = null;
}, 800);
}
}
function msbRunStep(sessionId) {
fetch('{$baseUrl}&task=ajax.step&session_id=' + encodeURIComponent(sessionId), {
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'}
})
.then(function(r) { return r.json(); })
.then(function(data) {
if (data.error) {
msbUpdateProgress(data.progress || 0, 'Backup error: ' + data.message);
msbLog('ERROR: ' + data.message);
msbShowFooter();
return;
}
msbUpdateProgress(data.progress || 0, data.message || data.phase || 'Working...');
if (data.message) msbLog(data.message);
if (data.done) {
msbFinish(true);
} else {
msbRunStep(sessionId);
}
})
.catch(function(err) {
msbUpdateProgress(0, 'Backup request failed');
msbLog('Network error: ' + err.message);
msbShowFooter();
});
}
function msbStartBackup() {
msbBackupRunning = true;
msbUpdateProgress(0, 'Initializing backup...');
msbLog('Starting pre-update backup (profile {$profileId})...');
fetch('{$baseUrl}&task=ajax.init&profile_id={$profileId}&description=Pre-update+backup', {
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'}
})
.then(function(r) { return r.json(); })
.then(function(data) {
if (data.error) {
msbUpdateProgress(0, 'Backup init failed: ' + data.message);
msbLog('INIT ERROR: ' + data.message);
msbShowFooter();
return;
}
msbLog('Backup initialized — ' + data.message);
msbUpdateProgress(data.progress || 5, data.message || 'Running...');
msbRunStep(data.session_id);
})
.catch(function(err) {
msbUpdateProgress(0, 'Could not start backup');
msbLog('Network error: ' + err.message);
msbShowFooter();
});
}
// Intercept Joomla toolbar submit
Joomla.submitbutton = function(task) {
if ((task === 'update.update' || task === 'update.install') && !msbBackupRunning) {
msbPendingTask = task;
bsModal.show();
msbStartBackup();
return;
}
msbOrigSubmit.call(Joomla, task);
};
// Skip button — proceed without backup
document.getElementById('msbSkipBtn').addEventListener('click', function() {
bsModal.hide();
msbBackupRunning = false;
if (msbPendingTask) {
msbOrigSubmit.call(Joomla, msbPendingTask);
msbPendingTask = null;
}
});
// Cancel button — abort everything
document.getElementById('msbCancelBtn').addEventListener('click', function() {
bsModal.hide();
msbBackupRunning = false;
msbPendingTask = null;
});
});
JS;
}
/**
* Send a JSON response and terminate — used by web cron handler.
*/
@@ -7,7 +7,7 @@
-->
<extension type="plugin" group="task" method="upgrade">
<name>Task - MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-02</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -7,7 +7,7 @@
-->
<extension type="plugin" group="webservices" method="upgrade">
<name>Web Services - MokoSuiteBackup</name>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-02</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
+1 -1
View File
@@ -8,7 +8,7 @@
<extension type="package" method="upgrade">
<name>Package - MokoSuiteBackup</name>
<packagename>mokosuitebackup</packagename>
<version>01.45.00</version>
<version>02.52.19</version>
<creationDate>2026-06-02</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>