refactor: full database snapshot/restore, remove table selection #95

Merged
jmiller merged 8 commits from dev into main 2026-05-31 01:24:07 +00:00
41 changed files with 343 additions and 457 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
<display-name>Package - MokoWaaS</display-name>
<org>MokoConsulting</org>
<description>White-label identity, security hardening, and tenant restriction layer for WaaS-managed Joomla environments</description>
<version>02.27.00</version>
<version>02.26.04</version>
<license spdx="GPL-3.0-or-later">GNU General Public License v3</license>
</identity>
<governance>
+1 -1
View File
@@ -5,7 +5,7 @@
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Automation
# VERSION: 02.27.00
# VERSION: 02.26.04
# BRIEF: Auto-create feature branch when an issue is opened
name: "Universal: Issue Branch"
+28 -3
View File
@@ -14,14 +14,12 @@
INGROUP: MokoWaaS.Documentation
REPO: https://github.com/mokoconsulting-tech/mokowaas
PATH: ./CHANGELOG.md
VERSION: 02.27.00
VERSION: 02.26.04
BRIEF: Version history using `Keep a Changelog`
-->
# Changelog
## [Unreleased]
## [02.27.00] --- 2026-05-31
### Added
- API endpoint `POST /api/index.php/v1/mokowaas/install` — install extensions from a remote ZIP URL
- Demo Mode with configurable warning banner on frontend when enabled
@@ -51,3 +49,30 @@ All notable changes to the MokoWaaS plugin will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [02.17.00] --- 2026-05-28
### Changed
- Migrated all workflow and template paths from `.github/` to `.mokogitea/`
- Template source paths updated: `templates/gitea/` to `templates/mokogitea/`
- HCL definition files removed -- Template repos are now the canonical source
### Added
- `branch-cleanup.yml`: auto-delete merged feature branches after PR merge
- `plg_webservices_perfectpublisher`: REST API for Perfect Publisher (com_autotweet) — channels, posts, requests, rules, feeds, and stats
### Planned
- License/subscription check
- System email template branding (DB approach)
### Added
- Trusted IPs: configurable repeatable rows of IP addresses, CIDR ranges, and wildcards that bypass admin session timeout
- Supports exact IPs (192.168.1.100), CIDR (10.0.0.0/24), and wildcards (192.168.1.*)
- Each entry has a label and enabled toggle for easy management
- Current IP display above trusted IPs table so admins can easily add their own IP
### Fixed
- Trusted IP session bypass: moved from `onAfterInitialise` to `boot()` so Joomla's session lifetime is extended before the session handler validates it (was too late, Joomla expired the session first)
- updates.xml: removed stale pre-release entries pointing to non-existent dev artifacts, legacy plugin update entry that caused stable sites to attempt dev downloads
- Removed duplicate `<updateservers>` from inner plugin manifest — only the package-level manifest should register the update server
- Auto-cleanup of stale plugin-level update site entries on install/update (cleans `#__update_sites` and `#__update_sites_extensions`)
+1 -1
View File
@@ -14,7 +14,7 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Documentation
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: ./CODE_OF_CONDUCT.md
BRIEF: Reference + packaging repo for Moko Consulting Developer GPT Other Default
-->
+1 -1
View File
@@ -19,7 +19,7 @@
DEFGROUP: mokoconsulting-tech.MokoWaaSBrand
INGROUP: MokoStandards.Governance
REPO: https://github.com/mokoconsulting-tech/MokoWaaSBrand
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /GOVERNANCE.md
BRIEF: Project governance rules, roles, and decision process for MokoWaaSBrand
-->
+1 -1
View File
@@ -15,7 +15,7 @@
INGROUP: MokoWaaS.Documentation
REPO: https://github.com/mokoconsulting-tech/mokowaas
PATH: ./LICENSE.md
VERSION: 02.27.00
VERSION: 02.26.04
BRIEF: Project license (GPL-3.0-or-later)
-->
GNU GENERAL PUBLIC LICENSE
+1 -1
View File
@@ -9,7 +9,7 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS
REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /README.md
BRIEF: MokoWaaS platform plugin for Joomla
-->
+1 -1
View File
@@ -23,7 +23,7 @@ DEFGROUP: [PROJECT_NAME]
INGROUP: [PROJECT_NAME].Documentation
REPO: [REPOSITORY_URL]
PATH: /SECURITY.md
VERSION: 02.27.00
VERSION: 02.26.04
BRIEF: Security vulnerability reporting and handling policy
-->
+2 -2
View File
@@ -11,13 +11,13 @@
INGROUP: MokoWaaS.Build
REPO: https://github.com/mokoconsulting-tech/mokowaas
FILE: build-guide.md
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/
BRIEF: Build and packaging guide for the MokoWaaS system plugin
NOTE: Defines environment setup, repository layout, packaging rules, and release preparation
-->
# MokoWaaS Build Guide (VERSION: 02.27.00)
# MokoWaaS Build Guide (VERSION: 02.26.04)
## 1. Purpose
+2 -2
View File
@@ -10,13 +10,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Guides
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/configuration-guide.md
BRIEF: Configuration guide for the MokoWaaS system plugin
NOTE: Defines plugin parameters, expected behaviors, and recommended defaults
-->
# MokoWaaS Configuration Guide (VERSION: 02.27.00)
# MokoWaaS Configuration Guide (VERSION: 02.26.04)
## 1. Objective
+2 -2
View File
@@ -10,13 +10,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Guides
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/installation-guide.md
BRIEF: Installation guide for the MokoWaaS system plugin
NOTE: First document in the guide set
-->
# MokoWaaS Installation Guide (VERSION: 02.27.00)
# MokoWaaS Installation Guide (VERSION: 02.26.04)
## Introduction
+2 -2
View File
@@ -10,13 +10,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Guides
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/operations-guide.md
BRIEF: Operational guide for administering and managing the MokoWaaS system plugin
NOTE: Defines lifecycle, responsibilities, and operational behaviors
-->
# MokoWaaS Operations Guide (VERSION: 02.27.00)
# MokoWaaS Operations Guide (VERSION: 02.26.04)
## Introduction
+2 -2
View File
@@ -10,13 +10,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Guides
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/rollback-and-recovery-guide.md
BRIEF: Rollback and recovery guide for restoring stable operation after plugin related incidents
NOTE: Completes the core guide set for WaaS plugin governance
-->
# MokoWaaS Rollback and Recovery Guide (VERSION: 02.27.00)
# MokoWaaS Rollback and Recovery Guide (VERSION: 02.26.04)
## Introduction
+2 -2
View File
@@ -7,13 +7,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Guides
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/testing-guide.md
BRIEF: Testing guide for MokoWaaS v02.01.08
NOTE: Covers manual test procedures for language overrides, install/uninstall, and configuration
-->
# MokoWaaS Testing Guide (VERSION: 02.27.00)
# MokoWaaS Testing Guide (VERSION: 02.26.04)
## 1. Prerequisites
+2 -2
View File
@@ -10,13 +10,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Guides
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/troubleshooting-guide.md
BRIEF: Troubleshooting guide for diagnosing and resolving issues related to the MokoWaaS plugin
NOTE: Designed for administrators and WaaS operations teams
-->
# MokoWaaS Troubleshooting Guide (VERSION: 02.27.00)
# MokoWaaS Troubleshooting Guide (VERSION: 02.26.04)
## Introduction
+2 -2
View File
@@ -10,13 +10,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Guides
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/guides/upgrade-and-versioning-guide.md
BRIEF: Guide for updating, versioning, and maintaining the MokoWaaS plugin
NOTE: Defines release flow, version rules, and upgrade validation
-->
# MokoWaaS Upgrade and Versioning Guide (VERSION: 02.27.00)
# MokoWaaS Upgrade and Versioning Guide (VERSION: 02.26.04)
## Introduction
+2 -2
View File
@@ -10,13 +10,13 @@
DEFGROUP: Joomla.Plugin
INGROUP: MokoWaaS.Documentation
REPO: https://github.com/mokoconsulting-tech/mokowaas
VERSION: 02.27.00
VERSION: 02.26.04
PATH: /docs/index.md
BRIEF: Master index of all documentation for the MokoWaaS plugin
NOTE: Automatically maintained index for all guide canvases
-->
# MokoWaaS Documentation Index (VERSION: 02.27.00)
# MokoWaaS Documentation Index (VERSION: 02.26.04)
## Introduction
+2 -2
View File
@@ -11,12 +11,12 @@
INGROUP: MokoWaaS
REPO: https://github.com/mokoconsulting-tech/mokowaas
PATH: /docs/plugin-basic.md
VERSION: 02.27.00
VERSION: 02.26.04
BRIEF: Baseline documentation for the MokoWaaS system plugin
NOTE: Foundational reference for internal and external stakeholders
-->
# MokoWaaS Plugin Overview (VERSION: 02.27.00)
# MokoWaaS Plugin Overview (VERSION: 02.26.04)
## Introduction
+1 -1
View File
@@ -10,7 +10,7 @@ DEFGROUP: MokoWaaS.Documentation
INGROUP: MokoStandards.Templates
REPO: https://github.com/mokoconsulting-tech/MokoWaaS
PATH: /docs/update-server.md
VERSION: 02.27.00
VERSION: 02.26.04
BRIEF: How this extension's Joomla update server file (update.xml) is managed
-->
@@ -103,13 +103,9 @@ class ResetController extends BaseController
require_once $serviceFile;
$tablesParam = $params->get('demo_snapshot_tables', '');
$tables = is_array($tablesParam) ? array_filter($tablesParam) : array_filter(array_map('trim', explode("\n", $tablesParam)));
$media = $params->get('demo_snapshot_include_media', ['images']);
if ($media === '1' || $media === true) $media = ['images'];
if ($media === '0' || $media === false) $media = [];
$media = (bool) $params->get('demo_snapshot_include_media', 1);
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, (array) $media);
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($media);
}
/**
@@ -130,13 +130,9 @@ class SnapshotController extends BaseController
$plugin = PluginHelper::getPlugin('system', 'mokowaas');
$params = $plugin ? new Registry($plugin->params) : new Registry;
$tablesParam = $params->get('demo_snapshot_tables', '');
$tables = is_array($tablesParam) ? array_filter($tablesParam) : array_filter(array_map('trim', explode("\n", $tablesParam)));
$media = $params->get('demo_snapshot_include_media', ['images']);
if ($media === '1' || $media === true) $media = ['images'];
if ($media === '0' || $media === false) $media = [];
$media = (bool) $params->get('demo_snapshot_include_media', 1);
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, (array) $media);
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($media);
}
/**
+1 -1
View File
@@ -7,7 +7,7 @@
<license>GPL-3.0-or-later</license>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<version>02.27.00</version>
<version>02.26.04-dev</version>
<description>Minimal API-only component for MokoWaaS. Provides REST endpoints for site health, cache, updates, and backups.</description>
<namespace path="api/src">Moko\Component\MokoWaaS\Api</namespace>
<administration>
@@ -22,7 +22,7 @@
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* REPO: https://github.com/mokoconsulting-tech/mokowaas
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/Extension/MokoWaaS.php
* NOTE: Handles Joomla system events for rebranding functionality
*/
@@ -878,6 +878,11 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface
$changed = true;
}
}
elseif ($params->get('demo_next_reset', '') !== '')
{
$params->set('demo_next_reset', '');
$changed = true;
}
// Demo Mode: Take Snapshot Now
if ((int) $params->get('demo_take_snapshot_now', 0) === 1)
@@ -1734,34 +1739,9 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface
{
require_once __DIR__ . '/../Service/DemoResetService.php';
$tablesParam = $this->params->get('demo_snapshot_tables', '');
$includeMedia = (bool) $this->params->get('demo_snapshot_include_media', 1);
// Handle both checkbox array and legacy newline-separated textarea
if (is_array($tablesParam))
{
$tables = array_filter($tablesParam);
}
else
{
$tables = array_filter(array_map('trim', explode("\n", $tablesParam)));
}
$mediaDirs = $this->params->get('demo_snapshot_include_media', ['images']);
// Handle legacy boolean value
if ($mediaDirs === '1' || $mediaDirs === true)
{
$mediaDirs = ['images'];
}
elseif ($mediaDirs === '0' || $mediaDirs === false)
{
$mediaDirs = [];
}
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService(
$tables,
(array) $mediaDirs
);
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($includeMedia);
}
/**
@@ -7,7 +7,7 @@
* FILE INFORMATION
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/Field/AllowedIpsField.php
* BRIEF: Custom form field that displays the current IP whitelist
*/
@@ -8,7 +8,7 @@
* FILE INFORMATION
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/Field/CopyableTokenField.php
* BRIEF: Read-only token field with a copy-to-clipboard button
*/
@@ -7,7 +7,7 @@
* FILE INFORMATION
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/Field/CurrentIpField.php
* BRIEF: Read-only field that displays the current user's IP address
*/
@@ -8,7 +8,7 @@
* FILE INFORMATION
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/Field/NextResetField.php
* BRIEF: Read-only field that displays the next scheduled reset in the site timezone
*/
@@ -32,6 +32,20 @@ class NextResetField extends FormField
protected function getInput()
{
// Check if demo mode is enabled via the form data
$demoEnabled = false;
if ($this->form)
{
$demoEnabled = (int) $this->form->getValue('demo_mode_enabled', 'params', 0) === 1;
}
if (!$demoEnabled)
{
return '<span class="form-control-plaintext text-muted">Demo mode is off</span>'
. '<input type="hidden" name="' . $this->name . '" value="" />';
}
if (empty($this->value))
{
return '<div class="alert alert-secondary mb-0 py-2">No reset scheduled — save the plugin config to calculate.</div>';
@@ -8,7 +8,7 @@
* FILE INFORMATION
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/Field/SnapshotTablesField.php
* BRIEF: Multi-select list field that loads DB tables with sensible defaults
*/
@@ -88,6 +88,11 @@ class SnapshotTablesField extends FormField
$selected = (array) $selected;
// Flatten nested arrays from broken save format [["#__content"],["#__categories"]]
$selected = array_map(function ($v) {
return is_array($v) ? reset($v) : $v;
}, $selected);
// Group tables
$grouped = [];
@@ -116,7 +121,7 @@ class SnapshotTablesField extends FormField
// Build HTML select with optgroups
$size = (int) ($this->element['size'] ?? 15);
$html = '<select name="' . $this->name . '[]" id="' . $this->id . '"'
$html = '<select name="' . $this->name . '" id="' . $this->id . '"'
. ' multiple="multiple" size="' . $size . '"'
. ' class="form-select">';
@@ -10,7 +10,7 @@
* INGROUP: MokoWaaS
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
* PATH: /src/packages/plg_system_mokowaas/Service/ContentSyncReceiver.php
* VERSION: 02.27.00
* VERSION: 02.26.04
* BRIEF: Receiver-side content sync — applies incoming payload to local DB
*/
@@ -10,7 +10,7 @@
* INGROUP: MokoWaaS
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
* PATH: /src/packages/plg_system_mokowaas/Service/ContentSyncService.php
* VERSION: 02.27.00
* VERSION: 02.26.04
* BRIEF: Sender-side content sync — builds payload and pushes to remote sites
*/
@@ -10,8 +10,8 @@
* INGROUP: MokoWaaS
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
* PATH: /src/packages/plg_system_mokowaas/Service/DemoResetService.php
* VERSION: 02.27.00
* BRIEF: Core snapshot/restore service for demo site reset
* VERSION: 02.28.00
* BRIEF: Full database snapshot/restore service for demo site reset
*/
namespace Moko\Plugin\System\MokoWaaS\Service;
@@ -22,15 +22,13 @@ use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;
/**
* Demo Reset Service — manages baseline snapshots and restore operations.
* Demo Reset Service — full database snapshot and restore.
*
* This is the single source of truth for all snapshot logic. Called by:
* - Admin one-shot toggles (onExtensionAfterSave)
* - Query-string API (?mokowaas=reset / ?mokowaas=snapshot)
* - REST API (/api/v1/mokowaas/reset, /api/v1/mokowaas/snapshot)
* - Joomla Scheduled Task (plg_task_mokowaasdemo)
* Takes a complete mysqldump of the database and restores it wholesale.
* This avoids the complexity of selective table management and ensures
* the site returns to an exact known state.
*
* @since 02.21.00
* @since 02.28.00
*/
class DemoResetService
{
@@ -42,38 +40,6 @@ class DemoResetService
*/
private const MAX_NAME_LENGTH = 64;
/**
* Rows per batch for paginated table dump/restore.
*
* @var int
* @since 02.21.00
*/
private const BATCH_SIZE = 500;
/**
* Default tables to snapshot if none configured.
*
* @var array
* @since 02.21.00
*/
private const DEFAULT_TABLES = [
'#__content',
'#__categories',
'#__fields',
'#__fields_values',
'#__fields_groups',
'#__menu',
'#__menu_types',
'#__modules',
'#__modules_menu',
'#__users',
'#__user_usergroup_map',
'#__user_profiles',
'#__tags',
'#__contentitem_tag_map',
'#__assets',
];
/**
* Root directory for all snapshots.
*
@@ -83,47 +49,25 @@ class DemoResetService
private string $snapshotDir;
/**
* Tables to include in snapshots.
* Whether to include /images/ in snapshots.
*
* @var array
* @var bool
* @since 02.21.00
*/
private array $tables;
/**
* Directories to include in media snapshot (e.g. ['images', 'media']).
*
* @var array
* @since 02.25.00
*/
private array $mediaDirs;
private bool $includeMedia;
/**
* Constructor.
*
* @param array $tables Table names with #__ prefix
* @param array|bool $mediaDirs Dirs to snapshot: ['images','media'], true (= images), false/[] (= none)
* @param string $baseDir Override snapshot root (for testing)
* @param bool $includeMedia Include /images/ directory in snapshot
* @param string $baseDir Override snapshot root (for testing)
*
* @since 02.21.00
* @since 02.28.00
*/
public function __construct(array $tables = [], $mediaDirs = ['images'], string $baseDir = '')
public function __construct(bool $includeMedia = true, string $baseDir = '')
{
$this->tables = !empty($tables) ? $tables : self::DEFAULT_TABLES;
$this->snapshotDir = $baseDir ?: JPATH_ROOT . '/mokowaas-snapshots';
if ($mediaDirs === true)
{
$this->mediaDirs = ['images'];
}
elseif ($mediaDirs === false || empty($mediaDirs))
{
$this->mediaDirs = [];
}
else
{
$this->mediaDirs = (array) $mediaDirs;
}
$this->includeMedia = $includeMedia;
$this->snapshotDir = $baseDir ?: JPATH_ROOT . '/mokowaas-snapshots';
}
/**
@@ -158,16 +102,16 @@ class DemoResetService
}
/**
* Create a named snapshot of the current site state.
* Create a full database snapshot.
*
* @param string $name Snapshot name (alphanumeric, hyphens, underscores)
* @param string $name Snapshot name
*
* @return array Result payload with status, tables count, size info
* @return array Result payload
*
* @throws \InvalidArgumentException On invalid snapshot name
* @throws \RuntimeException On filesystem/database failures
* @throws \InvalidArgumentException On invalid name
* @throws \RuntimeException On failure
*
* @since 02.21.00
* @since 02.28.00
*/
public function createSnapshot(string $name): array
{
@@ -176,7 +120,6 @@ class DemoResetService
$path = $this->getSnapshotPath($name);
// Remove existing snapshot with the same name
if (is_dir($path))
{
$this->removeDirectory($path);
@@ -187,39 +130,45 @@ class DemoResetService
throw new \RuntimeException('Failed to create snapshot directory: ' . $path);
}
$db = Factory::getDbo();
$prefix = $db->getPrefix();
$tables = $db->getTableList();
$dumped = 0;
// Full database dump
$config = Factory::getConfig();
$host = $config->get('host', 'localhost');
$dbName = $config->get('db');
$user = $config->get('user');
$pass = $config->get('password');
foreach ($this->tables as $tableName)
$dumpFile = $path . '/database.sql';
// Use mysqldump for a complete, reliable dump
$cmd = sprintf(
'mysqldump --host=%s --user=%s --password=%s --single-transaction --routines --triggers --add-drop-table %s > %s 2>&1',
escapeshellarg($host),
escapeshellarg($user),
escapeshellarg($pass),
escapeshellarg($dbName),
escapeshellarg($dumpFile)
);
exec($cmd, $output, $exitCode);
if ($exitCode !== 0 || !file_exists($dumpFile) || filesize($dumpFile) === 0)
{
$realTable = str_replace('#__', $prefix, $tableName);
if (!in_array($realTable, $tables))
{
continue;
}
$this->dumpTable($tableName, $realTable, $path, $db);
$dumped++;
// Fallback: PHP-based dump if mysqldump is not available
$this->phpDatabaseDump($dumpFile);
}
// Media snapshot — one ZIP per directory
$mediaDirs = [];
$dumpSizeMb = round(filesize($dumpFile) / 1048576, 1);
foreach ($this->mediaDirs as $dir)
// Media snapshot
$hasMedia = false;
if ($this->includeMedia)
{
$fullPath = JPATH_ROOT . '/' . $dir;
$imagesDir = JPATH_ROOT . '/images';
if (is_dir($fullPath))
if (is_dir($imagesDir))
{
$zipName = 'media_' . $dir . '.zip';
if ($this->snapshotDirectory($fullPath, $path . '/' . $zipName))
{
$mediaDirs[] = $dir;
}
$hasMedia = $this->snapshotDirectory($imagesDir, $path . '/media.zip');
}
}
@@ -227,10 +176,9 @@ class DemoResetService
$manifest = [
'name' => $name,
'created_at' => gmdate('Y-m-d\TH:i:s\Z'),
'tables' => $dumped,
'table_list' => $this->tables,
'has_media' => !empty($mediaDirs),
'media_dirs' => $mediaDirs,
'type' => 'full-database',
'dump_size_mb' => $dumpSizeMb,
'has_media' => $hasMedia,
'joomla_version' => JVERSION,
];
@@ -240,17 +188,17 @@ class DemoResetService
);
Log::add(
sprintf('Demo snapshot "%s" created (%d tables, media=%s)', $name, $dumped, $hasMedia ? 'yes' : 'no'),
sprintf('Demo snapshot "%s" created (full DB %.1f MB, media=%s)', $name, $dumpSizeMb, $hasMedia ? 'yes' : 'no'),
Log::INFO,
'mokowaas'
);
return [
'status' => 'ok',
'message' => 'Snapshot created',
'name' => $name,
'tables' => $dumped,
'has_media' => $hasMedia,
'status' => 'ok',
'message' => 'Snapshot created',
'name' => $name,
'dump_size_mb' => $dumpSizeMb,
'has_media' => $hasMedia,
];
}
@@ -264,7 +212,7 @@ class DemoResetService
* @throws \InvalidArgumentException On invalid name
* @throws \RuntimeException On missing snapshot or restore failure
*
* @since 02.21.00
* @since 02.28.00
*/
public function restoreSnapshot(string $name): array
{
@@ -285,7 +233,14 @@ class DemoResetService
throw new \RuntimeException('Invalid manifest for snapshot: ' . $name);
}
// Clear Joomla cache before restore
$dumpFile = $path . '/database.sql';
if (!file_exists($dumpFile))
{
throw new \RuntimeException('Database dump not found in snapshot: ' . $name);
}
// Clear Joomla cache
try
{
$cache = Factory::getCache('');
@@ -293,75 +248,51 @@ class DemoResetService
}
catch (\Throwable $e)
{
// Cache clear is best-effort
// Best effort
}
$db = Factory::getDbo();
$prefix = $db->getPrefix();
$restored = 0;
// Restore database
$config = Factory::getConfig();
$host = $config->get('host', 'localhost');
$dbName = $config->get('db');
$user = $config->get('user');
$pass = $config->get('password');
// Restore tables — assets first for ACL integrity
$sqlFiles = glob($path . '/*.sql');
// Try mysql CLI first (fastest, handles large dumps)
$cmd = sprintf(
'mysql --host=%s --user=%s --password=%s %s < %s 2>&1',
escapeshellarg($host),
escapeshellarg($user),
escapeshellarg($pass),
escapeshellarg($dbName),
escapeshellarg($dumpFile)
);
// Sort: #__assets first
usort($sqlFiles, function ($a, $b) {
$aIsAssets = str_contains(basename($a), '__assets');
$bIsAssets = str_contains(basename($b), '__assets');
exec($cmd, $output, $exitCode);
if ($aIsAssets) return -1;
if ($bIsAssets) return 1;
return strcmp($a, $b);
});
foreach ($sqlFiles as $sqlFile)
if ($exitCode !== 0)
{
try
{
$this->restoreTable($sqlFile, $db, $prefix);
$restored++;
}
catch (\Throwable $e)
{
Log::add(
sprintf('Demo reset: failed to restore %s: %s', basename($sqlFile), $e->getMessage()),
Log::ERROR,
'mokowaas'
);
}
// Fallback: PHP-based restore
$this->phpDatabaseRestore($dumpFile);
}
// Restore media directories
// Restore /images/
$mediaRestored = false;
$restoredDirs = $manifest['media_dirs'] ?? [];
// Legacy support: old manifests used has_media=true with a single media.zip for /images/
if (empty($restoredDirs) && ($manifest['has_media'] ?? false))
if ($manifest['has_media'] ?? false)
{
$restoredDirs = ['images'];
}
foreach ($restoredDirs as $dir)
{
$zipName = 'media_' . $dir . '.zip';
$zipPath = $path . '/' . $zipName;
// Legacy fallback: old snapshots used media.zip for images
if (!file_exists($zipPath) && $dir === 'images' && file_exists($path . '/media.zip'))
{
$zipPath = $path . '/media.zip';
}
$zipPath = $path . '/media.zip';
$imagesDir = JPATH_ROOT . '/images';
if (file_exists($zipPath))
{
$targetDir = JPATH_ROOT . '/' . $dir;
$this->clearDirectory($targetDir);
$this->clearDirectory($imagesDir);
$zip = new \ZipArchive();
if ($zip->open($zipPath) === true)
{
$zip->extractTo($targetDir);
$zip->extractTo($imagesDir);
$zip->close();
$mediaRestored = true;
}
@@ -369,17 +300,17 @@ class DemoResetService
}
Log::add(
sprintf('Demo site reset to baseline "%s" (%d tables, media=%s)', $name, $restored, $mediaRestored ? 'yes' : 'no'),
sprintf('Demo site reset to baseline "%s" (full DB, media=%s)', $name, $mediaRestored ? 'yes' : 'no'),
Log::WARNING,
'mokowaas'
);
return [
'status' => 'ok',
'message' => 'Site restored to baseline: ' . $name,
'baseline' => $name,
'restored_tables' => $restored,
'media_restored' => $mediaRestored,
'status' => 'ok',
'message' => 'Site restored to baseline: ' . $name,
'baseline' => $name,
'type' => 'full-database',
'media_restored' => $mediaRestored,
];
}
@@ -405,154 +336,158 @@ class DemoResetService
$this->removeDirectory($path);
Log::add(
sprintf('Demo snapshot "%s" deleted', $name),
Log::INFO,
'mokowaas'
);
return true;
}
/**
* Dump a single table to a SQL file using paginated reads.
* PHP fallback: dump entire database when mysqldump is unavailable.
*
* @param string $logicalName Table name with #__ prefix
* @param string $realName Actual table name with prefix
* @param string $dir Snapshot directory
* @param \Joomla\Database\DatabaseInterface $db Database driver
* @param string $dumpFile Output file path
*
* @return void
*
* @since 02.21.00
* @since 02.28.00
*/
private function dumpTable(string $logicalName, string $realName, string $dir, $db): void
private function phpDatabaseDump(string $dumpFile): void
{
$safeFileName = str_replace('#__', 'jml__', $logicalName);
$fp = fopen($dir . '/' . $safeFileName . '.sql', 'w');
$db = Factory::getDbo();
$tables = $db->getTableList();
$fp = fopen($dumpFile, 'w');
if ($fp === false)
{
throw new \RuntimeException('Cannot write dump file for: ' . $logicalName);
throw new \RuntimeException('Cannot write dump file');
}
// Get column names for consistent INSERT statements
$columns = $db->getTableColumns($realName, false);
$colNames = array_keys($columns);
$quotedCols = array_map([$db, 'quoteName'], $colNames);
$colList = implode(', ', $quotedCols);
fwrite($fp, "SET FOREIGN_KEY_CHECKS=0;\n\n");
$offset = 0;
while (true)
foreach ($tables as $table)
{
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName($realName))
->setLimit(self::BATCH_SIZE, $offset);
// CREATE TABLE statement
$db->setQuery('SHOW CREATE TABLE ' . $db->quoteName($table));
$create = $db->loadAssoc();
$createSql = $create['Create Table'] ?? $create['Create View'] ?? '';
$db->setQuery($query);
$rows = $db->loadAssocList();
if (empty($rows))
{
break;
}
// Build multi-value INSERT
$values = [];
foreach ($rows as $row)
{
$vals = [];
foreach ($colNames as $col)
{
$val = $row[$col];
if ($val === null)
{
$vals[] = 'NULL';
}
else
{
$vals[] = $db->quote($val);
}
}
$values[] = '(' . implode(', ', $vals) . ')';
}
fwrite($fp, 'INSERT INTO ' . $db->quoteName($realName)
. ' (' . $colList . ') VALUES ' . "\n"
. implode(",\n", $values) . ";\n\n");
$offset += self::BATCH_SIZE;
if (count($rows) < self::BATCH_SIZE)
{
break;
}
}
fclose($fp);
}
/**
* Restore a table from a SQL dump file.
*
* @param string $sqlFile Path to the .sql file
* @param \Joomla\Database\DatabaseInterface $db Database driver
* @param string $prefix Table prefix
*
* @return void
*
* @since 02.21.00
*/
private function restoreTable(string $sqlFile, $db, string $prefix): void
{
// Derive table name from filename: jml__content.sql -> {prefix}content
$baseName = basename($sqlFile, '.sql');
$realTable = str_replace('jml__', $prefix, $baseName);
// Truncate the table first
$db->setQuery('TRUNCATE TABLE ' . $db->quoteName($realTable));
$db->execute();
$sql = file_get_contents($sqlFile);
if (empty(trim($sql)))
{
return;
}
// Split by semicolons and execute each statement
$statements = array_filter(
array_map('trim', explode(";\n", $sql)),
function ($s) { return !empty($s) && $s !== ';'; }
);
foreach ($statements as $statement)
{
$statement = rtrim($statement, ';');
if (empty($statement))
if (empty($createSql))
{
continue;
}
$db->setQuery($statement);
$db->execute();
fwrite($fp, "DROP TABLE IF EXISTS " . $db->quoteName($table) . ";\n");
fwrite($fp, $createSql . ";\n\n");
// Skip views for data dump
if (isset($create['Create View']))
{
continue;
}
// Dump data in batches
$offset = 0;
while (true)
{
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName($table))
->setLimit(500, $offset);
$db->setQuery($query);
$rows = $db->loadAssocList();
if (empty($rows))
{
break;
}
// Get column names
$columns = array_keys($rows[0]);
$quotedCols = array_map([$db, 'quoteName'], $columns);
$colList = implode(', ', $quotedCols);
$values = [];
foreach ($rows as $row)
{
$vals = [];
foreach ($columns as $col)
{
$val = $row[$col];
$vals[] = $val === null ? 'NULL' : $db->quote($val);
}
$values[] = '(' . implode(', ', $vals) . ')';
}
fwrite($fp, 'INSERT INTO ' . $db->quoteName($table)
. ' (' . $colList . ') VALUES ' . "\n"
. implode(",\n", $values) . ";\n\n");
$offset += 500;
if (count($rows) < 500)
{
break;
}
}
}
fwrite($fp, "\nSET FOREIGN_KEY_CHECKS=1;\n");
fclose($fp);
}
/**
* PHP fallback: restore database from SQL dump when mysql CLI is unavailable.
*
* @param string $dumpFile SQL dump file path
*
* @return void
*
* @since 02.28.00
*/
private function phpDatabaseRestore(string $dumpFile): void
{
$db = Factory::getDbo();
$sql = file_get_contents($dumpFile);
if (empty($sql))
{
throw new \RuntimeException('Empty database dump file');
}
// Split by semicolons followed by newlines (avoids splitting within values)
$statements = preg_split('/;\s*\n/', $sql);
foreach ($statements as $statement)
{
$statement = trim($statement);
if (empty($statement) || $statement === ';')
{
continue;
}
try
{
$db->setQuery($statement);
$db->execute();
}
catch (\Throwable $e)
{
// Log but continue — partial restore is better than aborting
Log::add('DB restore warning: ' . $e->getMessage(), Log::WARNING, 'mokowaas');
}
}
}
/**
* Create a ZIP archive of a directory.
*
* @param string $sourceDir Full path to the directory to archive
* @param string $zipPath Full path for the output ZIP file
* @param string $sourceDir Full path to directory
* @param string $zipPath Output ZIP path
*
* @return bool True if archived successfully
* @return bool
*
* @since 02.25.00
*/
@@ -608,7 +543,7 @@ class DemoResetService
{
if (!mkdir($this->snapshotDir, 0755, true))
{
throw new \RuntimeException('Cannot create snapshot directory: ' . $this->snapshotDir);
throw new \RuntimeException('Cannot create snapshot directory');
}
}
@@ -620,57 +555,24 @@ class DemoResetService
}
}
/**
* Get the full path for a named snapshot.
*
* @param string $name Snapshot name
*
* @return string Full directory path
*
* @since 02.21.00
*/
private function getSnapshotPath(string $name): string
{
return $this->snapshotDir . '/' . $name;
}
/**
* Validate a snapshot name to prevent path traversal.
*
* @param string $name Snapshot name to validate
*
* @return void
*
* @throws \InvalidArgumentException On invalid name
*
* @since 02.21.00
*/
private function validateSnapshotName(string $name): void
{
if ($name === '' || strlen($name) > self::MAX_NAME_LENGTH)
{
throw new \InvalidArgumentException(
'Snapshot name must be 1-' . self::MAX_NAME_LENGTH . ' characters'
);
throw new \InvalidArgumentException('Snapshot name must be 1-' . self::MAX_NAME_LENGTH . ' characters');
}
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $name))
{
throw new \InvalidArgumentException(
'Snapshot name must contain only letters, numbers, hyphens, and underscores'
);
throw new \InvalidArgumentException('Snapshot name must contain only letters, numbers, hyphens, and underscores');
}
}
/**
* Recursively remove a directory and all contents.
*
* @param string $dir Directory to remove
*
* @return void
*
* @since 02.21.00
*/
private function removeDirectory(string $dir): void
{
$items = new \RecursiveIteratorIterator(
@@ -680,28 +582,12 @@ class DemoResetService
foreach ($items as $item)
{
if ($item->isDir())
{
@rmdir($item->getPathname());
}
else
{
@unlink($item->getPathname());
}
$item->isDir() ? @rmdir($item->getPathname()) : @unlink($item->getPathname());
}
@rmdir($dir);
}
/**
* Clear all contents of a directory without removing the directory itself.
*
* @param string $dir Directory to clear
*
* @return void
*
* @since 02.21.00
*/
private function clearDirectory(string $dir): void
{
if (!is_dir($dir))
@@ -716,14 +602,7 @@ class DemoResetService
foreach ($items as $item)
{
if ($item->isDir())
{
@rmdir($item->getPathname());
}
else
{
@unlink($item->getPathname());
}
$item->isDir() ? @rmdir($item->getPathname()) : @unlink($item->getPathname());
}
}
}
+6 -11
View File
@@ -30,7 +30,7 @@
<license>GNU General Public License version 3 or later; see LICENSE.md</license>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<version>02.27.00</version>
<version>02.26.04-dev</version>
<description>This plugin rebrands the Joomla system interface with MokoWaaS identity. It applies language overrides and ensures consistent branding across the platform.</description>
<namespace path=".">Moko\Plugin\System\MokoWaaS</namespace>
<scriptfile>script.php</scriptfile>
@@ -318,17 +318,12 @@
label="PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_LABEL"
description="PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_DESC"
/>
<field name="demo_snapshot_tables" type="SnapshotTables"
label="PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_LABEL"
description="PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_DESC"
multiple="true"
size="15"
/>
<field name="demo_snapshot_include_media" type="checkboxes"
<field name="demo_snapshot_include_media" type="radio" default="1"
label="PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_LABEL"
description="PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC">
<option value="images">Images (/images/)</option>
<option value="media">Media (/media/)</option>
description="PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC"
class="btn-group btn-group-yesno">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="demo_active_baseline" type="text"
label="PLG_SYSTEM_MOKOWAAS_DEMO_ACTIVE_BASELINE_LABEL"
+1 -1
View File
@@ -22,7 +22,7 @@
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* REPO: https://github.com/mokoconsulting-tech/mokowaas
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/script.php
* BRIEF: Installation script for MokoWaaS plugin
* NOTE: Handles installation, update, and uninstallation tasks including language override deployment
@@ -22,7 +22,7 @@
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* REPO: https://github.com/mokoconsulting-tech/mokowaas
* VERSION: 02.27.00
* VERSION: 02.26.04
* PATH: /src/services/provider.php
* BRIEF: Service provider for dependency injection in Joomla 5.x
* NOTE: Registers the plugin with Joomla's DI container
@@ -12,7 +12,7 @@
<license>GNU General Public License version 3 or later; see LICENSE</license>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<version>02.27.00</version>
<version>02.26.04-dev</version>
<description>PLG_TASK_MOKOWAASDEMO_DESC</description>
<namespace path="src">Moko\Plugin\Task\MokoWaaSDemo</namespace>
@@ -97,13 +97,9 @@ final class DemoReset extends CMSPlugin implements SubscriberInterface
require_once $serviceFile;
$tablesParam = $sysParams->get('demo_snapshot_tables', '');
$tables = is_array($tablesParam) ? array_filter($tablesParam) : array_filter(array_map('trim', explode("\n", $tablesParam)));
$media = $sysParams->get('demo_snapshot_include_media', ['images']);
if ($media === '1' || $media === true) $media = ['images'];
if ($media === '0' || $media === false) $media = [];
$media = (bool) $sysParams->get('demo_snapshot_include_media', 1);
$service = new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, (array) $media);
$service = new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($media);
try
{
@@ -7,7 +7,7 @@
<license>GPL-3.0-or-later</license>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<version>02.27.00</version>
<version>02.26.04-dev</version>
<description>Joomla Web Services API routes for MokoWaaS site management — health checks, cache, updates, backups, and site info.</description>
<namespace path="src">Moko\Plugin\WebServices\MokoWaaS</namespace>
<files>
@@ -7,7 +7,7 @@
<license>GPL-3.0-or-later</license>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<version>02.27.00</version>
<version>02.26.04-dev</version>
<description>Joomla Web Services API routes for Perfect Publisher (com_autotweet) — channels, posts, requests, rules, and feeds.</description>
<namespace path="src">Moko\Plugin\WebServices\PerfectPublisher</namespace>
<files>
@@ -8,7 +8,7 @@
* INGROUP: MokoWaaS
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
* PATH: /src/packages/plg_webservices_perfectpublisher/services/provider.php
* VERSION: 02.27.00
* VERSION: 02.26.04
* BRIEF: DI service provider for Perfect Publisher Web Services plugin
*/
@@ -8,7 +8,7 @@
* INGROUP: MokoWaaS
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
* PATH: /src/packages/plg_webservices_perfectpublisher/src/Extension/PerfectPublisherApi.php
* VERSION: 02.27.00
* VERSION: 02.26.04
* BRIEF: Web Services API plugin for Perfect Publisher (com_autotweet)
*/
+1 -1
View File
@@ -2,7 +2,7 @@
<extension type="package" method="upgrade">
<name>Package - MokoWaaS</name>
<packagename>mokowaas</packagename>
<version>02.27.00</version>
<version>02.26.04-dev</version>
<creationDate>2026-05-23</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>