Compare commits
81 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ecaa0e7ca | |||
| e3c9bd3b06 | |||
| 3ad1d36a8f | |||
| 6b0919daf3 | |||
| d2779af818 | |||
| 11a217d3b9 | |||
| e943b248e5 | |||
| 440e528786 | |||
| 5e290a21a1 | |||
| 888cd4cb67 | |||
| f81b895af6 | |||
| c8df9876fe | |||
| a520b791a3 | |||
| cd5a9f7ecb | |||
| 36dccc713a | |||
| 4bad7325f1 | |||
| cb775cdc4c | |||
| 96e89d0b0f | |||
| 9a313439ae | |||
| 9626344e3b | |||
| 74e61b00e6 | |||
| c9cedeb14a | |||
| 00b78b9d43 | |||
| c4a1cf356a | |||
| 0be8cc876c | |||
| 1e3513b714 | |||
| 22ccd233c2 | |||
| 4985c2e7b4 | |||
| b7b63d8172 | |||
| e377bef840 | |||
| 7d89d77a92 | |||
| 1f4d598e38 | |||
| 2807a54483 | |||
| 7b79256318 | |||
| 22acb25bbe | |||
| 586b7bc105 | |||
| 6cceb85be6 | |||
| 14b45cb36d | |||
| 45cbd5cad4 | |||
| b1519cf12a | |||
| d9012ffddb | |||
| 0740b495e1 | |||
| 1dff862d2b | |||
| ccdab8b5da | |||
| 5245d15b9d | |||
| 1673616523 | |||
| 62654e41a6 | |||
| 88817690e5 | |||
| 689bf1712f | |||
| 65e986344e | |||
| c37e6d9637 | |||
| cee142c714 | |||
| 1e404e1c7b | |||
| 87b8c770f3 | |||
| ab38f96dbc | |||
| 0cb8c3d6e4 | |||
| c94e92a97e | |||
| 02149ecc04 | |||
| abe906b4d7 | |||
| 2cd327e002 | |||
| e0ffef12f5 | |||
| f8612d55e5 | |||
| 76a9f643c9 | |||
| e824251c4a | |||
| d17544aba2 | |||
| 294a06028b | |||
| 210e1182c5 | |||
| 461d63efca | |||
| 747a7a4081 | |||
| 3975e8e205 | |||
| ea20256a67 | |||
| 817e00fc75 | |||
| 2aa69c1fe2 | |||
| e1db1149d8 | |||
| 67344f65b2 | |||
| f4caa1821e | |||
| e25281e130 | |||
| 1f25fe310f | |||
| 40fffcb234 | |||
| f451fb4d1a | |||
| 137d51a534 |
@@ -5,10 +5,10 @@
|
||||
-->
|
||||
<moko-platform xmlns="https://standards.mokoconsulting.tech/moko-platform/1.0" schema-version="1.0">
|
||||
<identity>
|
||||
<name>MokoWaaS</name>
|
||||
<name>Package - MokoWaaS</name>
|
||||
<org>MokoConsulting</org>
|
||||
<description>White-label identity, security hardening, and tenant restriction layer for WaaS-managed Joomla environments</description>
|
||||
<version>02.21.02</version>
|
||||
<version>02.26.00</version>
|
||||
<license spdx="GPL-3.0-or-later">GNU General Public License v3</license>
|
||||
</identity>
|
||||
<governance>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# FILE INFORMATION
|
||||
# DEFGROUP: Gitea.Workflow
|
||||
# INGROUP: moko-platform.Automation
|
||||
# VERSION: 02.21.02
|
||||
# VERSION: 02.26.00
|
||||
# BRIEF: Auto-create feature branch when an issue is opened
|
||||
|
||||
name: "Universal: Issue Branch"
|
||||
|
||||
+10
-28
@@ -14,12 +14,14 @@
|
||||
INGROUP: MokoWaaS.Documentation
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
PATH: ./CHANGELOG.md
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
BRIEF: Version history using `Keep a Changelog`
|
||||
-->
|
||||
|
||||
# Changelog
|
||||
## [Unreleased]
|
||||
|
||||
## [02.26.00] --- 2026-05-30
|
||||
### 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
|
||||
@@ -28,6 +30,13 @@
|
||||
- REST endpoints `POST /api/v1/mokowaas/reset` and `GET/POST /api/v1/mokowaas/snapshot`
|
||||
- `plg_task_mokowaasdemo` — Joomla Scheduled Task plugin for automatic demo site reset
|
||||
- Admin toggles: Take Snapshot Now and Restore Baseline Now in plugin config
|
||||
- Content Sync: one-way push of articles, categories, menus, and modules to remote MokoWaaS sites
|
||||
- Content Sync: API endpoints `POST /?mokowaas=sync` (sender) and `POST /?mokowaas=sync-receive` (receiver)
|
||||
- Content Sync: REST endpoints `POST /api/v1/mokowaas/sync` and `POST /api/v1/mokowaas/sync-receive`
|
||||
- Content Sync: configurable sync targets with URL + API token in plugin settings
|
||||
- Package installer: protect all MokoWaaS extensions (not just system plugin) and ensure update server stays enabled
|
||||
- Package installer: clean up legacy `mokowaasbrand` extension entries and files on install/update
|
||||
- API endpoint `GET /?mokowaas=extensions` and `GET /api/v1/mokowaas/extensions` — list installed extensions with version, status, and update server info
|
||||
|
||||
## [02.20.00] --- 2026-05-28
|
||||
|
||||
@@ -42,30 +51,3 @@ 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
@@ -14,7 +14,7 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Documentation
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
PATH: ./CODE_OF_CONDUCT.md
|
||||
BRIEF: Reference + packaging repo for Moko Consulting Developer GPT Other Default
|
||||
-->
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
DEFGROUP: mokoconsulting-tech.MokoWaaSBrand
|
||||
INGROUP: MokoStandards.Governance
|
||||
REPO: https://github.com/mokoconsulting-tech/MokoWaaSBrand
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
PATH: /GOVERNANCE.md
|
||||
BRIEF: Project governance rules, roles, and decision process for MokoWaaSBrand
|
||||
-->
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
INGROUP: MokoWaaS.Documentation
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
PATH: ./LICENSE.md
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
BRIEF: Project license (GPL-3.0-or-later)
|
||||
-->
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS
|
||||
REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
PATH: /README.md
|
||||
BRIEF: MokoWaaS platform plugin for Joomla
|
||||
-->
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ DEFGROUP: [PROJECT_NAME]
|
||||
INGROUP: [PROJECT_NAME].Documentation
|
||||
REPO: [REPOSITORY_URL]
|
||||
PATH: /SECURITY.md
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
BRIEF: Security vulnerability reporting and handling policy
|
||||
-->
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
INGROUP: MokoWaaS.Build
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
FILE: build-guide.md
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Build Guide (VERSION: 02.26.00)
|
||||
|
||||
## 1. Purpose
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Guides
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Configuration Guide (VERSION: 02.26.00)
|
||||
|
||||
## 1. Objective
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Guides
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Installation Guide (VERSION: 02.26.00)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Guides
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Operations Guide (VERSION: 02.26.00)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Guides
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Rollback and Recovery Guide (VERSION: 02.26.00)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Guides
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Testing Guide (VERSION: 02.26.00)
|
||||
|
||||
## 1. Prerequisites
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Guides
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Troubleshooting Guide (VERSION: 02.26.00)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Guides
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Upgrade and Versioning Guide (VERSION: 02.26.00)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
+2
-2
@@ -10,13 +10,13 @@
|
||||
DEFGROUP: Joomla.Plugin
|
||||
INGROUP: MokoWaaS.Documentation
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
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.21.02)
|
||||
# MokoWaaS Documentation Index (VERSION: 02.26.00)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
INGROUP: MokoWaaS
|
||||
REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
PATH: /docs/plugin-basic.md
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
BRIEF: Baseline documentation for the MokoWaaS system plugin
|
||||
NOTE: Foundational reference for internal and external stakeholders
|
||||
-->
|
||||
|
||||
# MokoWaaS Plugin Overview (VERSION: 02.21.02)
|
||||
# MokoWaaS Plugin Overview (VERSION: 02.26.00)
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ DEFGROUP: MokoWaaS.Documentation
|
||||
INGROUP: MokoStandards.Templates
|
||||
REPO: https://github.com/mokoconsulting-tech/MokoWaaS
|
||||
PATH: /docs/update-server.md
|
||||
VERSION: 02.21.02
|
||||
VERSION: 02.26.00
|
||||
BRIEF: How this extension's Joomla update server file (update.xml) is managed
|
||||
-->
|
||||
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* @package MokoWaaS
|
||||
* @subpackage com_mokowaas
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
*/
|
||||
|
||||
namespace Moko\Component\MokoWaaS\Api\Controller;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
|
||||
/**
|
||||
* Extensions list API controller.
|
||||
*
|
||||
* GET /api/index.php/v1/mokowaas/extensions
|
||||
*
|
||||
* Returns all installed extensions with type, element, folder, version,
|
||||
* enabled/protected/locked status, and update server info.
|
||||
*
|
||||
* Optional filters via query params:
|
||||
* ?type=plugin — filter by extension type
|
||||
* ?search=moko — search name or element
|
||||
* ?enabled=1 — only enabled/disabled
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
class ExtensionsController extends BaseController
|
||||
{
|
||||
/**
|
||||
* List installed extensions.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function displayList(): void
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$user = $app->getIdentity();
|
||||
|
||||
if (!$user->authorise('core.manage', 'com_installer'))
|
||||
{
|
||||
$this->sendJson(403, ['error' => 'Not authorized — requires core.manage on com_installer']);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('e.extension_id'),
|
||||
$db->quoteName('e.name'),
|
||||
$db->quoteName('e.type'),
|
||||
$db->quoteName('e.element'),
|
||||
$db->quoteName('e.folder'),
|
||||
$db->quoteName('e.client_id'),
|
||||
$db->quoteName('e.enabled'),
|
||||
$db->quoteName('e.protected'),
|
||||
$db->quoteName('e.locked'),
|
||||
$db->quoteName('e.manifest_cache'),
|
||||
])
|
||||
->from($db->quoteName('#__extensions', 'e'))
|
||||
->order($db->quoteName('e.type') . ' ASC, ' . $db->quoteName('e.name') . ' ASC');
|
||||
|
||||
// Filter by type
|
||||
$typeFilter = $app->input->get('type', '', 'CMD');
|
||||
|
||||
if ($typeFilter !== '')
|
||||
{
|
||||
$query->where($db->quoteName('e.type') . ' = ' . $db->quote($typeFilter));
|
||||
}
|
||||
|
||||
// Filter by enabled
|
||||
$enabledFilter = $app->input->get('enabled', '', 'CMD');
|
||||
|
||||
if ($enabledFilter !== '')
|
||||
{
|
||||
$query->where($db->quoteName('e.enabled') . ' = ' . (int) $enabledFilter);
|
||||
}
|
||||
|
||||
// Search name or element
|
||||
$search = $app->input->get('search', '', 'STRING');
|
||||
|
||||
if ($search !== '')
|
||||
{
|
||||
$searchQuoted = $db->quote('%' . $db->escape($search, true) . '%');
|
||||
$query->where(
|
||||
'(' . $db->quoteName('e.name') . ' LIKE ' . $searchQuoted
|
||||
. ' OR ' . $db->quoteName('e.element') . ' LIKE ' . $searchQuoted . ')'
|
||||
);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadAssocList();
|
||||
|
||||
// Get update sites for cross-reference
|
||||
$usQuery = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('us.update_site_id'),
|
||||
$db->quoteName('us.name', 'site_name'),
|
||||
$db->quoteName('us.location'),
|
||||
$db->quoteName('us.enabled', 'site_enabled'),
|
||||
$db->quoteName('usm.extension_id'),
|
||||
])
|
||||
->from($db->quoteName('#__update_sites', 'us'))
|
||||
->innerJoin(
|
||||
$db->quoteName('#__update_sites_extensions', 'usm')
|
||||
. ' ON ' . $db->quoteName('us.update_site_id')
|
||||
. ' = ' . $db->quoteName('usm.update_site_id')
|
||||
);
|
||||
$db->setQuery($usQuery);
|
||||
$updateSites = [];
|
||||
|
||||
foreach ($db->loadAssocList() ?: [] as $us)
|
||||
{
|
||||
$updateSites[(int) $us['extension_id']] = [
|
||||
'name' => $us['site_name'],
|
||||
'location' => $us['location'],
|
||||
'enabled' => (bool) $us['site_enabled'],
|
||||
];
|
||||
}
|
||||
|
||||
// Build response
|
||||
$extensions = [];
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$manifest = json_decode($row['manifest_cache'] ?: '{}', true);
|
||||
$extId = (int) $row['extension_id'];
|
||||
|
||||
$ext = [
|
||||
'extension_id' => $extId,
|
||||
'name' => $row['name'],
|
||||
'type' => $row['type'],
|
||||
'element' => $row['element'],
|
||||
'folder' => $row['folder'] ?: null,
|
||||
'client_id' => (int) $row['client_id'],
|
||||
'enabled' => (bool) $row['enabled'],
|
||||
'protected' => (bool) $row['protected'],
|
||||
'locked' => (bool) $row['locked'],
|
||||
'version' => $manifest['version'] ?? null,
|
||||
'author' => $manifest['author'] ?? null,
|
||||
'description' => $manifest['description'] ?? null,
|
||||
];
|
||||
|
||||
if (isset($updateSites[$extId]))
|
||||
{
|
||||
$ext['update_server'] = $updateSites[$extId];
|
||||
}
|
||||
|
||||
$extensions[] = $ext;
|
||||
}
|
||||
|
||||
$this->sendJson(200, [
|
||||
'status' => 'ok',
|
||||
'count' => count($extensions),
|
||||
'extensions' => $extensions,
|
||||
]);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->sendJson(500, [
|
||||
'error' => 'Failed to list extensions',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $code HTTP status code
|
||||
* @param array $payload Response data
|
||||
* @return void
|
||||
*/
|
||||
private function sendJson(int $code, array $payload): void
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$app->setHeader('Content-Type', 'application/json', true);
|
||||
$app->setHeader('Status', (string) $code, true);
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
$app->close();
|
||||
}
|
||||
}
|
||||
@@ -103,11 +103,13 @@ class ResetController extends BaseController
|
||||
|
||||
require_once $serviceFile;
|
||||
|
||||
$tablesRaw = $params->get('demo_snapshot_tables', '');
|
||||
$tables = array_filter(array_map('trim', explode("\n", $tablesRaw)));
|
||||
$media = (bool) $params->get('demo_snapshot_include_media', 1);
|
||||
$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 = [];
|
||||
|
||||
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, $media);
|
||||
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, (array) $media);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -130,11 +130,13 @@ class SnapshotController extends BaseController
|
||||
$plugin = PluginHelper::getPlugin('system', 'mokowaas');
|
||||
$params = $plugin ? new Registry($plugin->params) : new Registry;
|
||||
|
||||
$tablesRaw = $params->get('demo_snapshot_tables', '');
|
||||
$tables = array_filter(array_map('trim', explode("\n", $tablesRaw)));
|
||||
$media = (bool) $params->get('demo_snapshot_include_media', 1);
|
||||
$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 = [];
|
||||
|
||||
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, $media);
|
||||
return new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, (array) $media);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @package MokoWaaS
|
||||
* @subpackage com_mokowaas
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
*/
|
||||
|
||||
namespace Moko\Component\MokoWaaS\Api\Controller;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
/**
|
||||
* Content sync trigger API controller (sender side).
|
||||
*
|
||||
* POST /api/index.php/v1/mokowaas/sync
|
||||
*
|
||||
* Pushes content to all configured sync targets.
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
class SyncController extends BaseController
|
||||
{
|
||||
public function execute(): void
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
if ($app->input->getMethod() !== 'POST')
|
||||
{
|
||||
$this->sendJson(405, ['error' => 'POST required']);
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $app->getIdentity();
|
||||
|
||||
if (!$user->authorise('core.manage', 'com_plugins'))
|
||||
{
|
||||
$this->sendJson(403, ['error' => 'Not authorized']);
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin = PluginHelper::getPlugin('system', 'mokowaas');
|
||||
|
||||
if (!$plugin)
|
||||
{
|
||||
$this->sendJson(503, ['error' => 'MokoWaaS system plugin not enabled']);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$params = new Registry($plugin->params);
|
||||
$targets = json_decode($params->get('sync_targets', '[]'), true) ?: [];
|
||||
|
||||
$serviceFile = JPATH_PLUGINS . '/system/mokowaas/Service/ContentSyncService.php';
|
||||
require_once $serviceFile;
|
||||
|
||||
$service = new \Moko\Plugin\System\MokoWaaS\Service\ContentSyncService();
|
||||
$result = $service->syncAllTargets($targets);
|
||||
|
||||
$this->sendJson(200, $result);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->sendJson(500, ['error' => 'Sync failed', 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
private function sendJson(int $code, array $payload): void
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$app->setHeader('Content-Type', 'application/json', true);
|
||||
$app->setHeader('Status', (string) $code, true);
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
$app->close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* @package MokoWaaS
|
||||
* @subpackage com_mokowaas
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
*/
|
||||
|
||||
namespace Moko\Component\MokoWaaS\Api\Controller;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
|
||||
/**
|
||||
* Content sync receiver API controller (target side).
|
||||
*
|
||||
* POST /api/index.php/v1/mokowaas/sync-receive
|
||||
*
|
||||
* Accepts a JSON payload from a source site and applies the content locally.
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
class SyncReceiveController extends BaseController
|
||||
{
|
||||
public function execute(): void
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
if ($app->input->getMethod() !== 'POST')
|
||||
{
|
||||
$this->sendJson(405, ['error' => 'POST required']);
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $app->getIdentity();
|
||||
|
||||
if (!$user->authorise('core.manage', 'com_plugins'))
|
||||
{
|
||||
$this->sendJson(403, ['error' => 'Not authorized']);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$payload = json_decode($app->input->json->getRaw(), true);
|
||||
|
||||
if (empty($payload['mokowaas_sync']))
|
||||
{
|
||||
$this->sendJson(400, ['error' => 'Invalid payload — missing mokowaas_sync version']);
|
||||
return;
|
||||
}
|
||||
|
||||
$serviceFile = JPATH_PLUGINS . '/system/mokowaas/Service/ContentSyncReceiver.php';
|
||||
require_once $serviceFile;
|
||||
|
||||
$receiver = new \Moko\Plugin\System\MokoWaaS\Service\ContentSyncReceiver();
|
||||
$result = $receiver->receive($payload);
|
||||
|
||||
$this->sendJson(200, $result);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->sendJson(500, ['error' => 'Sync receive failed', 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
private function sendJson(int $code, array $payload): void
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$app->setHeader('Content-Type', 'application/json', true);
|
||||
$app->setHeader('Status', (string) $code, true);
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
|
||||
$app->close();
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
<license>GPL-3.0-or-later</license>
|
||||
<authorEmail>hello@mokoconsulting.tech</authorEmail>
|
||||
<authorUrl>https://mokoconsulting.tech</authorUrl>
|
||||
<version>02.21.02-dev</version>
|
||||
<version>02.26.00</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.21.02
|
||||
* VERSION: 02.26.00
|
||||
* PATH: /src/Extension/MokoWaaS.php
|
||||
* NOTE: Handles Joomla system events for rebranding functionality
|
||||
*/
|
||||
@@ -862,6 +862,23 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface
|
||||
);
|
||||
}
|
||||
|
||||
// Demo Mode: Calculate next reset time from cron schedule
|
||||
if ((int) $params->get('demo_mode_enabled', 0) === 1)
|
||||
{
|
||||
$schedule = $params->get('demo_reset_schedule', '0 0 * * *');
|
||||
$cron = ($schedule === 'custom')
|
||||
? $params->get('demo_reset_cron', '0 0 * * *')
|
||||
: $schedule;
|
||||
|
||||
$nextReset = $this->calculateNextCronRun($cron);
|
||||
|
||||
if ($nextReset)
|
||||
{
|
||||
$params->set('demo_next_reset', $nextReset);
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Demo Mode: Take Snapshot Now
|
||||
if ((int) $params->get('demo_take_snapshot_now', 0) === 1)
|
||||
{
|
||||
@@ -916,6 +933,35 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface
|
||||
}
|
||||
}
|
||||
|
||||
// Content Sync: Push Now
|
||||
if ((int) $params->get('sync_push_now', 0) === 1)
|
||||
{
|
||||
$params->set('sync_push_now', '0');
|
||||
$changed = true;
|
||||
|
||||
try
|
||||
{
|
||||
require_once __DIR__ . '/../Service/ContentSyncService.php';
|
||||
|
||||
$targets = json_decode($params->get('sync_targets', '[]'), true) ?: [];
|
||||
$service = new \Moko\Plugin\System\MokoWaaS\Service\ContentSyncService();
|
||||
$result = $service->syncAllTargets($targets);
|
||||
|
||||
$targetCount = count($result['targets'] ?? []);
|
||||
$app->enqueueMessage(
|
||||
sprintf('Content sync pushed to %d target(s).', $targetCount),
|
||||
'message'
|
||||
);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$app->enqueueMessage(
|
||||
'Content sync failed: ' . $e->getMessage(),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($changed)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
@@ -1057,25 +1103,60 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface
|
||||
$message = htmlspecialchars($this->params->get('demo_banner_message', 'This is a demo site. All changes will be reset periodically.'), ENT_QUOTES, 'UTF-8');
|
||||
$bgColor = htmlspecialchars($this->params->get('demo_banner_color', '#d9534f'), ENT_QUOTES, 'UTF-8');
|
||||
$showCountdown = (int) $this->params->get('demo_banner_show_countdown', 0);
|
||||
$intervalHours = (int) $this->params->get('demo_reset_interval_hours', 24);
|
||||
$resetAt = time() + ($intervalHours * 3600);
|
||||
|
||||
$countdownJs = '';
|
||||
// Use stored next-reset timestamp, or calculate on the fly from cron schedule
|
||||
$nextReset = $this->params->get('demo_next_reset', '');
|
||||
$resetAtMs = 0;
|
||||
|
||||
if ($showCountdown)
|
||||
{
|
||||
if (!empty($nextReset))
|
||||
{
|
||||
$ts = strtotime($nextReset);
|
||||
|
||||
// If stored timestamp is in the past, recalculate
|
||||
if ($ts > time())
|
||||
{
|
||||
$resetAtMs = $ts * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate on the fly if no valid stored timestamp
|
||||
if ($resetAtMs === 0)
|
||||
{
|
||||
$schedule = $this->params->get('demo_reset_schedule', '0 0 * * *');
|
||||
$cron = ($schedule === 'custom')
|
||||
? $this->params->get('demo_reset_cron', '0 0 * * *')
|
||||
: $schedule;
|
||||
|
||||
$calculated = $this->calculateNextCronRun($cron);
|
||||
|
||||
if ($calculated)
|
||||
{
|
||||
$resetAtMs = strtotime($calculated) * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$countdownJs = '';
|
||||
|
||||
if ($showCountdown && $resetAtMs > 0)
|
||||
{
|
||||
$countdownJs = "
|
||||
var resetAt = {$resetAt} * 1000;
|
||||
var resetAt = {$resetAtMs};
|
||||
var cdSpan = document.getElementById('mokowaas-demo-countdown');
|
||||
if (cdSpan) {
|
||||
setInterval(function() {
|
||||
var tick = function() {
|
||||
var now = Date.now();
|
||||
var diff = Math.max(0, Math.floor((resetAt - now) / 1000));
|
||||
if (diff <= 0) { cdSpan.textContent = ' — Reset imminent'; return; }
|
||||
var h = Math.floor(diff / 3600);
|
||||
var m = Math.floor((diff % 3600) / 60);
|
||||
var s = diff % 60;
|
||||
cdSpan.textContent = ' — Resets in ' + h + 'h ' + m + 'm ' + s + 's';
|
||||
}, 1000);
|
||||
};
|
||||
tick();
|
||||
setInterval(tick, 1000);
|
||||
}
|
||||
";
|
||||
}
|
||||
@@ -1532,11 +1613,20 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface
|
||||
case 'snapshot':
|
||||
$this->handleSnapshotAction();
|
||||
break;
|
||||
case 'sync':
|
||||
$this->handleSyncAction();
|
||||
break;
|
||||
case 'sync-receive':
|
||||
$this->handleSyncReceiveAction();
|
||||
break;
|
||||
case 'extensions':
|
||||
$this->handleExtensionsAction();
|
||||
break;
|
||||
default:
|
||||
$this->sendHealthResponse(400, [
|
||||
'error' => 'Unknown action',
|
||||
'action' => $action,
|
||||
'available' => ['health', 'install', 'update', 'cache', 'backup', 'info', 'reset', 'snapshot'],
|
||||
'available' => ['health', 'install', 'update', 'cache', 'backup', 'info', 'reset', 'snapshot', 'sync', 'sync-receive', 'extensions'],
|
||||
]);
|
||||
break;
|
||||
}
|
||||
@@ -1644,19 +1734,378 @@ class MokoWaaS extends CMSPlugin implements BootableExtensionInterface
|
||||
{
|
||||
require_once __DIR__ . '/../Service/DemoResetService.php';
|
||||
|
||||
$tablesRaw = $this->params->get('demo_snapshot_tables', '');
|
||||
$tables = array_filter(
|
||||
array_map('trim', explode("\n", $tablesRaw))
|
||||
);
|
||||
$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,
|
||||
$includeMedia
|
||||
(array) $mediaDirs
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the next run time from a crontab expression.
|
||||
*
|
||||
* Supports standard 5-field crontab: minute hour day month weekday.
|
||||
* Steps (e.g. every N), ranges, and wildcards are supported.
|
||||
*
|
||||
* @param string $cron Crontab expression
|
||||
*
|
||||
* @return string|null ISO datetime of next run, or null on invalid input
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
protected function calculateNextCronRun(string $cron): ?string
|
||||
{
|
||||
$parts = preg_split('/\s+/', trim($cron));
|
||||
|
||||
if (count($parts) !== 5)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
[$cronMin, $cronHour, $cronDay, $cronMonth, $cronWeekday] = $parts;
|
||||
|
||||
// Start from next minute
|
||||
$now = time();
|
||||
$check = $now - ($now % 60) + 60;
|
||||
|
||||
// Check up to 366 days ahead
|
||||
$maxChecks = 527040; // 366 * 24 * 60
|
||||
|
||||
for ($i = 0; $i < $maxChecks; $i++)
|
||||
{
|
||||
$min = (int) date('i', $check);
|
||||
$hour = (int) date('G', $check);
|
||||
$day = (int) date('j', $check);
|
||||
$month = (int) date('n', $check);
|
||||
$weekday = (int) date('w', $check);
|
||||
|
||||
if ($this->cronFieldMatches($cronMin, $min, 0, 59)
|
||||
&& $this->cronFieldMatches($cronHour, $hour, 0, 23)
|
||||
&& $this->cronFieldMatches($cronDay, $day, 1, 31)
|
||||
&& $this->cronFieldMatches($cronMonth, $month, 1, 12)
|
||||
&& $this->cronFieldMatches($cronWeekday, $weekday, 0, 6))
|
||||
{
|
||||
return gmdate('Y-m-d\TH:i:s\Z', $check);
|
||||
}
|
||||
|
||||
$check += 60;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a value matches a crontab field expression.
|
||||
*
|
||||
* @param string $field Cron field (e.g. every-5, 1-15 range, 0-23, wildcard)
|
||||
* @param int $value Current value to check
|
||||
* @param int $min Minimum allowed value
|
||||
* @param int $max Maximum allowed value
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function cronFieldMatches(string $field, int $value, int $min, int $max): bool
|
||||
{
|
||||
foreach (explode(',', $field) as $part)
|
||||
{
|
||||
$part = trim($part);
|
||||
|
||||
// Step: every-N or range-with-step
|
||||
if (str_contains($part, '/'))
|
||||
{
|
||||
[$range, $step] = explode('/', $part, 2);
|
||||
$step = (int) $step;
|
||||
|
||||
if ($step <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($range === '*')
|
||||
{
|
||||
if (($value - $min) % $step === 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
elseif (str_contains($range, '-'))
|
||||
{
|
||||
[$rangeMin, $rangeMax] = array_map('intval', explode('-', $range, 2));
|
||||
|
||||
if ($value >= $rangeMin && $value <= $rangeMax && ($value - $rangeMin) % $step === 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Wildcard
|
||||
if ($part === '*')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Range: N-M
|
||||
if (str_contains($part, '-'))
|
||||
{
|
||||
[$rangeMin, $rangeMax] = array_map('intval', explode('-', $part, 2));
|
||||
|
||||
if ($value >= $rangeMin && $value <= $rangeMax)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Exact value
|
||||
if ((int) $part === $value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle content sync push to configured targets.
|
||||
*
|
||||
* POST /?mokowaas=sync
|
||||
*
|
||||
* @return void
|
||||
* @since 02.21.00
|
||||
*/
|
||||
protected function handleSyncAction()
|
||||
{
|
||||
if ($this->app->input->getMethod() !== 'POST')
|
||||
{
|
||||
$this->sendHealthResponse(405, ['error' => 'POST required']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
require_once __DIR__ . '/../Service/ContentSyncService.php';
|
||||
|
||||
$targets = json_decode($this->params->get('sync_targets', '[]'), true) ?: [];
|
||||
|
||||
$service = new \Moko\Plugin\System\MokoWaaS\Service\ContentSyncService();
|
||||
$result = $service->syncAllTargets($targets);
|
||||
|
||||
$this->sendHealthResponse(200, $result);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->sendHealthResponse(500, [
|
||||
'error' => 'Sync failed',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming content sync payload (receiver side).
|
||||
*
|
||||
* POST /?mokowaas=sync-receive
|
||||
*
|
||||
* @return void
|
||||
* @since 02.21.00
|
||||
*/
|
||||
protected function handleSyncReceiveAction()
|
||||
{
|
||||
if ($this->app->input->getMethod() !== 'POST')
|
||||
{
|
||||
$this->sendHealthResponse(405, ['error' => 'POST required']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$payload = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (empty($payload['mokowaas_sync']))
|
||||
{
|
||||
$this->sendHealthResponse(400, ['error' => 'Invalid payload — missing mokowaas_sync version']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../Service/ContentSyncReceiver.php';
|
||||
|
||||
$receiver = new \Moko\Plugin\System\MokoWaaS\Service\ContentSyncReceiver();
|
||||
$result = $receiver->receive($payload);
|
||||
|
||||
$this->sendHealthResponse(200, $result);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->sendHealthResponse(500, [
|
||||
'error' => 'Sync receive failed',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List installed extensions with version, status, and update server info.
|
||||
*
|
||||
* GET /?mokowaas=extensions
|
||||
* Optional: ?type=plugin&search=moko&enabled=1
|
||||
*
|
||||
* @return void
|
||||
* @since 02.21.00
|
||||
*/
|
||||
protected function handleExtensionsAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$input = $this->app->input;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('e.extension_id'),
|
||||
$db->quoteName('e.name'),
|
||||
$db->quoteName('e.type'),
|
||||
$db->quoteName('e.element'),
|
||||
$db->quoteName('e.folder'),
|
||||
$db->quoteName('e.client_id'),
|
||||
$db->quoteName('e.enabled'),
|
||||
$db->quoteName('e.protected'),
|
||||
$db->quoteName('e.locked'),
|
||||
$db->quoteName('e.manifest_cache'),
|
||||
])
|
||||
->from($db->quoteName('#__extensions', 'e'))
|
||||
->order($db->quoteName('e.type') . ' ASC, ' . $db->quoteName('e.name') . ' ASC');
|
||||
|
||||
$typeFilter = $input->get('type', '', 'CMD');
|
||||
|
||||
if ($typeFilter !== '')
|
||||
{
|
||||
$query->where($db->quoteName('e.type') . ' = ' . $db->quote($typeFilter));
|
||||
}
|
||||
|
||||
$enabledFilter = $input->get('enabled', '', 'CMD');
|
||||
|
||||
if ($enabledFilter !== '')
|
||||
{
|
||||
$query->where($db->quoteName('e.enabled') . ' = ' . (int) $enabledFilter);
|
||||
}
|
||||
|
||||
$search = $input->get('search', '', 'STRING');
|
||||
|
||||
if ($search !== '')
|
||||
{
|
||||
$like = $db->quote('%' . $db->escape($search, true) . '%');
|
||||
$query->where(
|
||||
'(' . $db->quoteName('e.name') . ' LIKE ' . $like
|
||||
. ' OR ' . $db->quoteName('e.element') . ' LIKE ' . $like . ')'
|
||||
);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadAssocList();
|
||||
|
||||
// Get update sites
|
||||
$usQuery = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('us.name', 'site_name'),
|
||||
$db->quoteName('us.location'),
|
||||
$db->quoteName('us.enabled', 'site_enabled'),
|
||||
$db->quoteName('usm.extension_id'),
|
||||
])
|
||||
->from($db->quoteName('#__update_sites', 'us'))
|
||||
->innerJoin(
|
||||
$db->quoteName('#__update_sites_extensions', 'usm')
|
||||
. ' ON ' . $db->quoteName('us.update_site_id')
|
||||
. ' = ' . $db->quoteName('usm.update_site_id')
|
||||
);
|
||||
$db->setQuery($usQuery);
|
||||
$updateSites = [];
|
||||
|
||||
foreach ($db->loadAssocList() ?: [] as $us)
|
||||
{
|
||||
$updateSites[(int) $us['extension_id']] = [
|
||||
'name' => $us['site_name'],
|
||||
'location' => $us['location'],
|
||||
'enabled' => (bool) $us['site_enabled'],
|
||||
];
|
||||
}
|
||||
|
||||
$extensions = [];
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$manifest = json_decode($row['manifest_cache'] ?: '{}', true);
|
||||
$extId = (int) $row['extension_id'];
|
||||
|
||||
$ext = [
|
||||
'extension_id' => $extId,
|
||||
'name' => $row['name'],
|
||||
'type' => $row['type'],
|
||||
'element' => $row['element'],
|
||||
'folder' => $row['folder'] ?: null,
|
||||
'client_id' => (int) $row['client_id'],
|
||||
'enabled' => (bool) $row['enabled'],
|
||||
'protected' => (bool) $row['protected'],
|
||||
'locked' => (bool) $row['locked'],
|
||||
'version' => $manifest['version'] ?? null,
|
||||
'author' => $manifest['author'] ?? null,
|
||||
];
|
||||
|
||||
if (isset($updateSites[$extId]))
|
||||
{
|
||||
$ext['update_server'] = $updateSites[$extId];
|
||||
}
|
||||
|
||||
$extensions[] = $ext;
|
||||
}
|
||||
|
||||
$this->sendHealthResponse(200, [
|
||||
'status' => 'ok',
|
||||
'count' => count($extensions),
|
||||
'extensions' => $extensions,
|
||||
]);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->sendHealthResponse(500, [
|
||||
'error' => 'Failed to list extensions',
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Joomla update finder check.
|
||||
*
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: Joomla.Plugin
|
||||
* INGROUP: MokoWaaS
|
||||
* VERSION: 02.21.02
|
||||
* VERSION: 02.26.00
|
||||
* PATH: /src/Field/AllowedIpsField.php
|
||||
* BRIEF: Custom form field that displays the current IP whitelist
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @package MokoWaaS
|
||||
* @subpackage plg_system_mokowaas
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: Joomla.Plugin
|
||||
* INGROUP: MokoWaaS
|
||||
* VERSION: 02.26.00
|
||||
* PATH: /src/Field/CopyableTokenField.php
|
||||
* BRIEF: Read-only token field with a copy-to-clipboard button
|
||||
*/
|
||||
|
||||
namespace Moko\Plugin\System\MokoWaaS\Field;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Form\FormField;
|
||||
|
||||
/**
|
||||
* Renders a read-only text input with a "Copy" button, similar to
|
||||
* Joomla's API token field in the user profile.
|
||||
*
|
||||
* @since 02.25.00
|
||||
*/
|
||||
class CopyableTokenField extends FormField
|
||||
{
|
||||
protected $type = 'CopyableToken';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
$value = htmlspecialchars($this->value ?? '', ENT_QUOTES, 'UTF-8');
|
||||
$id = $this->id;
|
||||
|
||||
if (empty($this->value))
|
||||
{
|
||||
return '<div class="alert alert-warning mb-0 py-2">Token will be generated automatically on first save.</div>';
|
||||
}
|
||||
|
||||
return <<<HTML
|
||||
<div class="input-group">
|
||||
<input type="text" id="{$id}" name="{$this->name}" value="{$value}"
|
||||
class="form-control" readonly="readonly" style="font-family:monospace;font-size:0.85em" />
|
||||
<button type="button" class="btn btn-outline-secondary" onclick="
|
||||
var inp = document.getElementById('{$id}');
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(inp.value).then(function() {
|
||||
var btn = inp.nextElementSibling;
|
||||
var orig = btn.innerHTML;
|
||||
btn.innerHTML = '<span class="icon-check" aria-hidden="true"></span> Copied';
|
||||
btn.classList.replace('btn-outline-secondary','btn-success');
|
||||
setTimeout(function(){ btn.innerHTML = orig; btn.classList.replace('btn-success','btn-outline-secondary'); }, 2000);
|
||||
});
|
||||
} else {
|
||||
inp.select(); document.execCommand('copy');
|
||||
}
|
||||
"><span class="icon-copy" aria-hidden="true"></span> Copy</button>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: Joomla.Plugin
|
||||
* INGROUP: MokoWaaS
|
||||
* VERSION: 02.21.02
|
||||
* VERSION: 02.26.00
|
||||
* PATH: /src/Field/CurrentIpField.php
|
||||
* BRIEF: Read-only field that displays the current user's IP address
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* @package MokoWaaS
|
||||
* @subpackage plg_system_mokowaas
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: Joomla.Plugin
|
||||
* INGROUP: MokoWaaS
|
||||
* VERSION: 02.26.00
|
||||
* PATH: /src/Field/SnapshotTablesField.php
|
||||
* BRIEF: Multi-select field that loads DB tables with sensible defaults pre-checked
|
||||
*/
|
||||
|
||||
namespace Moko\Plugin\System\MokoWaaS\Field;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Field\CheckboxesField;
|
||||
|
||||
/**
|
||||
* Renders a checkbox list of all Joomla database tables, with content-related
|
||||
* tables pre-selected by default. Tables are grouped by category (content,
|
||||
* users, menus, modules, other).
|
||||
*
|
||||
* @since 02.25.00
|
||||
*/
|
||||
class SnapshotTablesField extends CheckboxesField
|
||||
{
|
||||
protected $type = 'SnapshotTables';
|
||||
|
||||
/**
|
||||
* Tables selected by default when no value is stored yet.
|
||||
*
|
||||
* @var array
|
||||
* @since 02.25.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',
|
||||
];
|
||||
|
||||
/**
|
||||
* Group labels for table categorisation.
|
||||
*
|
||||
* @var array
|
||||
* @since 02.25.00
|
||||
*/
|
||||
private const TABLE_GROUPS = [
|
||||
'content' => ['content', 'categories', 'fields', 'tags', 'contentitem_tag_map', 'ucm_content', 'ucm_history'],
|
||||
'users' => ['users', 'user_usergroup_map', 'user_profiles', 'usergroups', 'user_keys', 'user_mfa'],
|
||||
'menus' => ['menu', 'menu_types'],
|
||||
'modules' => ['modules', 'modules_menu'],
|
||||
'assets' => ['assets'],
|
||||
];
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$prefix = $db->getPrefix();
|
||||
$tables = $db->getTableList();
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
// Only show tables with the site's prefix
|
||||
if (strpos($table, $prefix) !== 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert real table name to #__ notation
|
||||
$logical = '#__' . substr($table, strlen($prefix));
|
||||
|
||||
// Determine group for display ordering
|
||||
$group = 'Other';
|
||||
|
||||
foreach (self::TABLE_GROUPS as $groupName => $patterns)
|
||||
{
|
||||
$suffix = substr($table, strlen($prefix));
|
||||
|
||||
foreach ($patterns as $pattern)
|
||||
{
|
||||
if ($suffix === $pattern)
|
||||
{
|
||||
$group = ucfirst($groupName);
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$obj = (object) [
|
||||
'value' => $logical,
|
||||
'text' => $logical,
|
||||
'disable' => false,
|
||||
'class' => '',
|
||||
'onclick' => '',
|
||||
];
|
||||
|
||||
$options[$group][] = $obj;
|
||||
}
|
||||
|
||||
// Flatten with group headers: content tables first, then alphabetical
|
||||
$priority = ['Content', 'Users', 'Menus', 'Modules', 'Assets'];
|
||||
$sorted = [];
|
||||
|
||||
foreach ($priority as $g)
|
||||
{
|
||||
if (isset($options[$g]))
|
||||
{
|
||||
$sorted = array_merge($sorted, $options[$g]);
|
||||
unset($options[$g]);
|
||||
}
|
||||
}
|
||||
|
||||
// Remaining tables (Other)
|
||||
if (isset($options['Other']))
|
||||
{
|
||||
sort($options['Other']);
|
||||
$sorted = array_merge($sorted, $options['Other']);
|
||||
}
|
||||
|
||||
return $sorted;
|
||||
}
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
// If no value stored yet, use defaults
|
||||
if ($this->value === null || $this->value === '')
|
||||
{
|
||||
$this->value = self::DEFAULT_TABLES;
|
||||
}
|
||||
elseif (is_string($this->value))
|
||||
{
|
||||
// Handle legacy textarea format (newline-separated)
|
||||
$this->value = array_filter(array_map('trim', explode("\n", $this->value)));
|
||||
}
|
||||
|
||||
return parent::getInput();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,819 @@
|
||||
<?php
|
||||
/**
|
||||
* @package MokoWaaS
|
||||
* @subpackage plg_system_mokowaas
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: Joomla.Plugin
|
||||
* INGROUP: MokoWaaS
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
|
||||
* PATH: /src/packages/plg_system_mokowaas/Service/ContentSyncReceiver.php
|
||||
* VERSION: 02.26.00
|
||||
* BRIEF: Receiver-side content sync — applies incoming payload to local DB
|
||||
*/
|
||||
|
||||
namespace Moko\Plugin\System\MokoWaaS\Service;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Log\Log;
|
||||
|
||||
/**
|
||||
* Content Sync Receiver — applies incoming sync payload to the local site.
|
||||
*
|
||||
* Processes categories, articles, menu types, menu items, and modules
|
||||
* from a JSON payload sent by a source MokoWaaS site. Content is matched
|
||||
* by alias (upsert pattern): existing content is updated, new content
|
||||
* is inserted.
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
class ContentSyncReceiver
|
||||
{
|
||||
/**
|
||||
* @var \Joomla\Database\DatabaseInterface
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* Warnings collected during sync.
|
||||
*
|
||||
* @var array
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private array $warnings = [];
|
||||
|
||||
/**
|
||||
* Cache of resolved category paths → local IDs.
|
||||
*
|
||||
* @var array
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private array $catPathCache = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \Joomla\Database\DatabaseInterface|null $db Database driver
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function __construct($db = null)
|
||||
{
|
||||
$this->db = $db ?: Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an incoming sync payload.
|
||||
*
|
||||
* @param array $payload Decoded JSON payload from the source site
|
||||
*
|
||||
* @return array Result summary with per-type counts and warnings
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function receive(array $payload): array
|
||||
{
|
||||
if (empty($payload['mokowaas_sync']))
|
||||
{
|
||||
return ['status' => 'error', 'message' => 'Invalid payload — missing mokowaas_sync version'];
|
||||
}
|
||||
|
||||
$this->warnings = [];
|
||||
$results = [];
|
||||
|
||||
// Apply in dependency order
|
||||
try
|
||||
{
|
||||
$results['categories'] = $this->applyCategories($payload['categories'] ?? []);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$results['categories'] = ['error' => $e->getMessage()];
|
||||
$this->warnings[] = 'Categories failed: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$results['articles'] = $this->applyArticles($payload['articles'] ?? []);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$results['articles'] = ['error' => $e->getMessage()];
|
||||
$this->warnings[] = 'Articles failed: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$results['menu_types'] = $this->applyMenuTypes($payload['menu_types'] ?? []);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$results['menu_types'] = ['error' => $e->getMessage()];
|
||||
$this->warnings[] = 'Menu types failed: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$results['menu_items'] = $this->applyMenuItems($payload['menu_items'] ?? []);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$results['menu_items'] = ['error' => $e->getMessage()];
|
||||
$this->warnings[] = 'Menu items failed: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$results['modules'] = $this->applyModules($payload['modules'] ?? []);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$results['modules'] = ['error' => $e->getMessage()];
|
||||
$this->warnings[] = 'Modules failed: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
Log::add(
|
||||
sprintf('Content sync received from %s', $payload['source_site'] ?? 'unknown'),
|
||||
Log::INFO,
|
||||
'mokowaas'
|
||||
);
|
||||
|
||||
return [
|
||||
'status' => 'ok',
|
||||
'message' => 'Sync applied',
|
||||
'source_site' => $payload['source_site'] ?? '',
|
||||
'results' => $results,
|
||||
'warnings' => $this->warnings,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply categories — sorted by path depth (shallow first).
|
||||
*
|
||||
* @param array $categories Category data from payload
|
||||
*
|
||||
* @return array ['inserted' => N, 'updated' => N]
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function applyCategories(array $categories): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$inserted = 0;
|
||||
$updated = 0;
|
||||
|
||||
// Sort by path depth — parents before children
|
||||
usort($categories, function ($a, $b) {
|
||||
return substr_count($a['path'], '/') - substr_count($b['path'], '/');
|
||||
});
|
||||
|
||||
foreach ($categories as $cat)
|
||||
{
|
||||
$alias = $cat['alias'] ?? '';
|
||||
$path = $cat['path'] ?? $alias;
|
||||
|
||||
if (empty($alias) || !preg_match('/^[a-z0-9\-\/]+$/i', $path))
|
||||
{
|
||||
$this->warnings[] = 'Skipped category with invalid alias/path: ' . $alias;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resolve parent ID from path
|
||||
$parentId = 1; // Root
|
||||
$pathParts = explode('/', $path);
|
||||
|
||||
if (count($pathParts) > 1)
|
||||
{
|
||||
$parentPath = implode('/', array_slice($pathParts, 0, -1));
|
||||
$parentId = $this->resolveCategoryPath($parentPath);
|
||||
|
||||
if ($parentId === 0)
|
||||
{
|
||||
$this->warnings[] = 'Parent category not found for: ' . $path;
|
||||
$parentId = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if category exists
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__categories'))
|
||||
->where($db->quoteName('alias') . ' = ' . $db->quote($alias))
|
||||
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'))
|
||||
->where($db->quoteName('parent_id') . ' = ' . (int) $parentId);
|
||||
|
||||
$db->setQuery($query);
|
||||
$existingId = (int) $db->loadResult();
|
||||
|
||||
$now = Factory::getDate()->toSql();
|
||||
|
||||
if ($existingId)
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__categories'))
|
||||
->set($db->quoteName('title') . ' = ' . $db->quote($cat['title']))
|
||||
->set($db->quoteName('description') . ' = ' . $db->quote($cat['description'] ?? ''))
|
||||
->set($db->quoteName('published') . ' = ' . (int) ($cat['published'] ?? 1))
|
||||
->set($db->quoteName('access') . ' = ' . (int) ($cat['access'] ?? 1))
|
||||
->set($db->quoteName('language') . ' = ' . $db->quote($cat['language'] ?? '*'))
|
||||
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($cat['params'] ?? new \stdClass)))
|
||||
->set($db->quoteName('metadata') . ' = ' . $db->quote(json_encode($cat['metadata'] ?? new \stdClass)))
|
||||
->set($db->quoteName('modified_time') . ' = ' . $db->quote($now))
|
||||
->where($db->quoteName('id') . ' = ' . $existingId);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
$updated++;
|
||||
|
||||
$this->catPathCache[$path] = $existingId;
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj = (object) [
|
||||
'title' => $cat['title'],
|
||||
'alias' => $alias,
|
||||
'path' => $path,
|
||||
'extension' => 'com_content',
|
||||
'description' => $cat['description'] ?? '',
|
||||
'published' => (int) ($cat['published'] ?? 1),
|
||||
'access' => (int) ($cat['access'] ?? 1),
|
||||
'language' => $cat['language'] ?? '*',
|
||||
'params' => json_encode($cat['params'] ?? new \stdClass),
|
||||
'metadata' => json_encode($cat['metadata'] ?? new \stdClass),
|
||||
'parent_id' => $parentId,
|
||||
'level' => count($pathParts),
|
||||
'lft' => 0,
|
||||
'rgt' => 0,
|
||||
'created_time' => $now,
|
||||
'modified_time' => $now,
|
||||
];
|
||||
|
||||
$db->insertObject('#__categories', $obj, 'id');
|
||||
$inserted++;
|
||||
|
||||
$this->catPathCache[$path] = (int) $obj->id;
|
||||
|
||||
// Rebuild category tree for this extension
|
||||
$this->rebuildCategoryTree();
|
||||
}
|
||||
}
|
||||
|
||||
return ['inserted' => $inserted, 'updated' => $updated];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply articles — resolve category by alias path, upsert by alias.
|
||||
*
|
||||
* @param array $articles Article data from payload
|
||||
*
|
||||
* @return array ['inserted' => N, 'updated' => N]
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function applyArticles(array $articles): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$inserted = 0;
|
||||
$updated = 0;
|
||||
|
||||
foreach ($articles as $article)
|
||||
{
|
||||
$alias = $article['alias'] ?? '';
|
||||
|
||||
if (empty($alias))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resolve category
|
||||
$catPath = $article['catid_alias_path'] ?? 'uncategorised';
|
||||
$catId = $this->resolveCategoryPath($catPath);
|
||||
|
||||
if ($catId === 0)
|
||||
{
|
||||
$catId = 2; // Joomla's built-in Uncategorised
|
||||
$this->warnings[] = 'Category "' . $catPath . '" not found for article "' . $alias . '" — assigned to Uncategorised';
|
||||
}
|
||||
|
||||
// Check if article exists
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__content'))
|
||||
->where($db->quoteName('alias') . ' = ' . $db->quote($alias));
|
||||
|
||||
$db->setQuery($query);
|
||||
$existingId = (int) $db->loadResult();
|
||||
|
||||
$now = Factory::getDate()->toSql();
|
||||
|
||||
if ($existingId)
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__content'))
|
||||
->set($db->quoteName('title') . ' = ' . $db->quote($article['title']))
|
||||
->set($db->quoteName('introtext') . ' = ' . $db->quote($article['introtext'] ?? ''))
|
||||
->set($db->quoteName('fulltext') . ' = ' . $db->quote($article['fulltext'] ?? ''))
|
||||
->set($db->quoteName('state') . ' = ' . (int) ($article['state'] ?? 1))
|
||||
->set($db->quoteName('catid') . ' = ' . $catId)
|
||||
->set($db->quoteName('access') . ' = ' . (int) ($article['access'] ?? 1))
|
||||
->set($db->quoteName('language') . ' = ' . $db->quote($article['language'] ?? '*'))
|
||||
->set($db->quoteName('featured') . ' = ' . (int) ($article['featured'] ?? 0))
|
||||
->set($db->quoteName('metadata') . ' = ' . $db->quote(json_encode($article['metadata'] ?? new \stdClass)))
|
||||
->set($db->quoteName('attribs') . ' = ' . $db->quote(json_encode($article['attribs'] ?? new \stdClass)))
|
||||
->set($db->quoteName('images') . ' = ' . $db->quote(json_encode($article['images'] ?? new \stdClass)))
|
||||
->set($db->quoteName('urls') . ' = ' . $db->quote(json_encode($article['urls'] ?? new \stdClass)))
|
||||
->set($db->quoteName('modified') . ' = ' . $db->quote($now))
|
||||
->where($db->quoteName('id') . ' = ' . $existingId);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
$updated++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj = (object) [
|
||||
'title' => $article['title'],
|
||||
'alias' => $alias,
|
||||
'introtext' => $article['introtext'] ?? '',
|
||||
'fulltext' => $article['fulltext'] ?? '',
|
||||
'state' => (int) ($article['state'] ?? 1),
|
||||
'catid' => $catId,
|
||||
'access' => (int) ($article['access'] ?? 1),
|
||||
'language' => $article['language'] ?? '*',
|
||||
'featured' => (int) ($article['featured'] ?? 0),
|
||||
'publish_up' => $article['publish_up'] ?? $now,
|
||||
'publish_down' => $article['publish_down'],
|
||||
'metadata' => json_encode($article['metadata'] ?? new \stdClass),
|
||||
'attribs' => json_encode($article['attribs'] ?? new \stdClass),
|
||||
'images' => json_encode($article['images'] ?? new \stdClass),
|
||||
'urls' => json_encode($article['urls'] ?? new \stdClass),
|
||||
'created' => $now,
|
||||
'modified' => $now,
|
||||
];
|
||||
|
||||
$db->insertObject('#__content', $obj, 'id');
|
||||
$inserted++;
|
||||
}
|
||||
}
|
||||
|
||||
return ['inserted' => $inserted, 'updated' => $updated];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply menu types — insert if not exists.
|
||||
*
|
||||
* @param array $menuTypes Menu type data from payload
|
||||
*
|
||||
* @return array ['inserted' => N, 'updated' => N]
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function applyMenuTypes(array $menuTypes): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$inserted = 0;
|
||||
$updated = 0;
|
||||
|
||||
foreach ($menuTypes as $mt)
|
||||
{
|
||||
$menutype = $mt['menutype'] ?? '';
|
||||
|
||||
if (empty($menutype))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__menu_types'))
|
||||
->where($db->quoteName('menutype') . ' = ' . $db->quote($menutype));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
if ($db->loadResult())
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__menu_types'))
|
||||
->set($db->quoteName('title') . ' = ' . $db->quote($mt['title'] ?? $menutype))
|
||||
->set($db->quoteName('description') . ' = ' . $db->quote($mt['description'] ?? ''))
|
||||
->where($db->quoteName('menutype') . ' = ' . $db->quote($menutype));
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
$updated++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj = (object) [
|
||||
'title' => $mt['title'] ?? $menutype,
|
||||
'menutype' => $menutype,
|
||||
'description' => $mt['description'] ?? '',
|
||||
];
|
||||
|
||||
$db->insertObject('#__menu_types', $obj);
|
||||
$inserted++;
|
||||
}
|
||||
}
|
||||
|
||||
return ['inserted' => $inserted, 'updated' => $updated];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply menu items — resolve parent aliases and {catid:path} tokens.
|
||||
*
|
||||
* @param array $items Menu item data from payload
|
||||
*
|
||||
* @return array ['inserted' => N, 'updated' => N]
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function applyMenuItems(array $items): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$inserted = 0;
|
||||
$updated = 0;
|
||||
|
||||
// Sort: root items first, then children
|
||||
usort($items, function ($a, $b) {
|
||||
$aIsRoot = empty($a['parent_alias']);
|
||||
$bIsRoot = empty($b['parent_alias']);
|
||||
|
||||
if ($aIsRoot && !$bIsRoot) return -1;
|
||||
if (!$aIsRoot && $bIsRoot) return 1;
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
// Resolve component IDs
|
||||
$compQuery = $db->getQuery(true)
|
||||
->select([$db->quoteName('extension_id'), $db->quoteName('element')])
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('component'));
|
||||
$db->setQuery($compQuery);
|
||||
$compMap = [];
|
||||
|
||||
foreach ($db->loadAssocList() ?: [] as $c)
|
||||
{
|
||||
$compMap[$c['element']] = (int) $c['extension_id'];
|
||||
}
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$alias = $item['alias'] ?? '';
|
||||
$menutype = $item['menutype'] ?? '';
|
||||
|
||||
if (empty($alias) || empty($menutype))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resolve parent
|
||||
$parentId = 1; // Root menu item
|
||||
|
||||
if (!empty($item['parent_alias']))
|
||||
{
|
||||
$parentId = $this->resolveMenuAlias($menutype, $item['parent_alias']);
|
||||
|
||||
if ($parentId === 0)
|
||||
{
|
||||
$this->warnings[] = 'Parent menu item "' . $item['parent_alias'] . '" not found for "' . $alias . '"';
|
||||
$parentId = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve {catid:path} tokens in link
|
||||
$link = $item['link'] ?? '';
|
||||
|
||||
if (preg_match_all('/\{catid:([^}]+)\}/', $link, $matches))
|
||||
{
|
||||
foreach ($matches[1] as $i => $catPath)
|
||||
{
|
||||
$localCatId = $this->resolveCategoryPath($catPath);
|
||||
|
||||
if ($localCatId > 0)
|
||||
{
|
||||
$link = str_replace($matches[0][$i], (string) $localCatId, $link);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->warnings[] = 'Could not resolve {catid:' . $catPath . '} in menu item "' . $alias . '"';
|
||||
$link = str_replace($matches[0][$i], '0', $link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$componentId = $compMap[$item['component_name'] ?? ''] ?? 0;
|
||||
|
||||
// Check if menu item exists
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__menu'))
|
||||
->where($db->quoteName('alias') . ' = ' . $db->quote($alias))
|
||||
->where($db->quoteName('menutype') . ' = ' . $db->quote($menutype))
|
||||
->where($db->quoteName('client_id') . ' = 0');
|
||||
|
||||
$db->setQuery($query);
|
||||
$existingId = (int) $db->loadResult();
|
||||
|
||||
if ($existingId)
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__menu'))
|
||||
->set($db->quoteName('title') . ' = ' . $db->quote($item['title']))
|
||||
->set($db->quoteName('link') . ' = ' . $db->quote($link))
|
||||
->set($db->quoteName('type') . ' = ' . $db->quote($item['type'] ?? 'component'))
|
||||
->set($db->quoteName('published') . ' = ' . (int) ($item['published'] ?? 1))
|
||||
->set($db->quoteName('access') . ' = ' . (int) ($item['access'] ?? 1))
|
||||
->set($db->quoteName('language') . ' = ' . $db->quote($item['language'] ?? '*'))
|
||||
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($item['params'] ?? new \stdClass)))
|
||||
->set($db->quoteName('parent_id') . ' = ' . $parentId)
|
||||
->set($db->quoteName('component_id') . ' = ' . $componentId)
|
||||
->set($db->quoteName('home') . ' = ' . (int) ($item['home'] ?? 0))
|
||||
->where($db->quoteName('id') . ' = ' . $existingId);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
$updated++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj = (object) [
|
||||
'menutype' => $menutype,
|
||||
'title' => $item['title'],
|
||||
'alias' => $alias,
|
||||
'path' => $alias,
|
||||
'link' => $link,
|
||||
'type' => $item['type'] ?? 'component',
|
||||
'published' => (int) ($item['published'] ?? 1),
|
||||
'parent_id' => $parentId,
|
||||
'level' => $parentId <= 1 ? 1 : 2,
|
||||
'component_id' => $componentId,
|
||||
'access' => (int) ($item['access'] ?? 1),
|
||||
'language' => $item['language'] ?? '*',
|
||||
'params' => json_encode($item['params'] ?? new \stdClass),
|
||||
'home' => (int) ($item['home'] ?? 0),
|
||||
'client_id' => 0,
|
||||
'lft' => 0,
|
||||
'rgt' => 0,
|
||||
];
|
||||
|
||||
$db->insertObject('#__menu', $obj, 'id');
|
||||
$inserted++;
|
||||
}
|
||||
}
|
||||
|
||||
// Rebuild menu tree for each affected menutype
|
||||
$affectedMenuTypes = array_unique(array_column($items, 'menutype'));
|
||||
|
||||
foreach ($affectedMenuTypes as $mt)
|
||||
{
|
||||
$this->rebuildMenuTree($mt);
|
||||
}
|
||||
|
||||
return ['inserted' => $inserted, 'updated' => $updated];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply modules — upsert by title+position+client_id, rebuild menu assignments.
|
||||
*
|
||||
* @param array $modules Module data from payload
|
||||
*
|
||||
* @return array ['inserted' => N, 'updated' => N]
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function applyModules(array $modules): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$inserted = 0;
|
||||
$updated = 0;
|
||||
|
||||
foreach ($modules as $mod)
|
||||
{
|
||||
$title = $mod['title'] ?? '';
|
||||
$position = $mod['position'] ?? '';
|
||||
$clientId = (int) ($mod['client_id'] ?? 0);
|
||||
|
||||
if (empty($title))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check existence by title + position + client_id
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__modules'))
|
||||
->where($db->quoteName('title') . ' = ' . $db->quote($title))
|
||||
->where($db->quoteName('position') . ' = ' . $db->quote($position))
|
||||
->where($db->quoteName('client_id') . ' = ' . $clientId);
|
||||
|
||||
$db->setQuery($query);
|
||||
$existingId = (int) $db->loadResult();
|
||||
|
||||
if ($existingId)
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__modules'))
|
||||
->set($db->quoteName('module') . ' = ' . $db->quote($mod['module'] ?? ''))
|
||||
->set($db->quoteName('content') . ' = ' . $db->quote($mod['content'] ?? ''))
|
||||
->set($db->quoteName('published') . ' = ' . (int) ($mod['published'] ?? 1))
|
||||
->set($db->quoteName('access') . ' = ' . (int) ($mod['access'] ?? 1))
|
||||
->set($db->quoteName('language') . ' = ' . $db->quote($mod['language'] ?? '*'))
|
||||
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($mod['params'] ?? new \stdClass)))
|
||||
->where($db->quoteName('id') . ' = ' . $existingId);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
$updated++;
|
||||
|
||||
$moduleId = $existingId;
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj = (object) [
|
||||
'title' => $title,
|
||||
'module' => $mod['module'] ?? '',
|
||||
'position' => $position,
|
||||
'content' => $mod['content'] ?? '',
|
||||
'published' => (int) ($mod['published'] ?? 1),
|
||||
'access' => (int) ($mod['access'] ?? 1),
|
||||
'language' => $mod['language'] ?? '*',
|
||||
'params' => json_encode($mod['params'] ?? new \stdClass),
|
||||
'client_id' => $clientId,
|
||||
'ordering' => 0,
|
||||
];
|
||||
|
||||
$db->insertObject('#__modules', $obj, 'id');
|
||||
$inserted++;
|
||||
$moduleId = (int) $obj->id;
|
||||
}
|
||||
|
||||
// Rebuild menu assignments
|
||||
$query = $db->getQuery(true)
|
||||
->delete($db->quoteName('#__modules_menu'))
|
||||
->where($db->quoteName('moduleid') . ' = ' . $moduleId);
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
$assignment = $mod['menu_assignment'] ?? [];
|
||||
$assignType = (int) ($assignment['assignment'] ?? 0);
|
||||
$aliases = $assignment['menu_item_aliases'] ?? [];
|
||||
|
||||
if ($assignType === 0 || empty($aliases))
|
||||
{
|
||||
// All pages
|
||||
$obj = (object) ['moduleid' => $moduleId, 'menuid' => 0];
|
||||
$db->insertObject('#__modules_menu', $obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($aliases as $aliasRef)
|
||||
{
|
||||
// Format: "menutype:alias"
|
||||
$parts = explode(':', $aliasRef, 2);
|
||||
|
||||
if (count($parts) !== 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$menuId = $this->resolveMenuAlias($parts[0], $parts[1]);
|
||||
|
||||
if ($menuId > 0)
|
||||
{
|
||||
$menuidValue = $assignType === -1 ? -$menuId : $menuId;
|
||||
$obj = (object) ['moduleid' => $moduleId, 'menuid' => $menuidValue];
|
||||
$db->insertObject('#__modules_menu', $obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->warnings[] = 'Module "' . $title . '": menu item "' . $aliasRef . '" not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['inserted' => $inserted, 'updated' => $updated];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a category alias path to a local category ID.
|
||||
*
|
||||
* @param string $path Slash-delimited alias path (e.g. "blog/news")
|
||||
*
|
||||
* @return int Category ID, or 0 if not found
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function resolveCategoryPath(string $path): int
|
||||
{
|
||||
if (isset($this->catPathCache[$path]))
|
||||
{
|
||||
return $this->catPathCache[$path];
|
||||
}
|
||||
|
||||
$db = $this->db;
|
||||
$segments = explode('/', $path);
|
||||
$parentId = 1;
|
||||
|
||||
foreach ($segments as $segment)
|
||||
{
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__categories'))
|
||||
->where($db->quoteName('alias') . ' = ' . $db->quote($segment))
|
||||
->where($db->quoteName('parent_id') . ' = ' . $parentId)
|
||||
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'));
|
||||
|
||||
$db->setQuery($query);
|
||||
$id = (int) $db->loadResult();
|
||||
|
||||
if ($id === 0)
|
||||
{
|
||||
$this->catPathCache[$path] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$parentId = $id;
|
||||
}
|
||||
|
||||
$this->catPathCache[$path] = $parentId;
|
||||
|
||||
return $parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a menu item alias to a local menu ID.
|
||||
*
|
||||
* @param string $menutype Menu type key
|
||||
* @param string $alias Menu item alias
|
||||
*
|
||||
* @return int Menu item ID, or 0 if not found
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function resolveMenuAlias(string $menutype, string $alias): int
|
||||
{
|
||||
$db = $this->db;
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__menu'))
|
||||
->where($db->quoteName('alias') . ' = ' . $db->quote($alias))
|
||||
->where($db->quoteName('menutype') . ' = ' . $db->quote($menutype))
|
||||
->where($db->quoteName('client_id') . ' = 0');
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return (int) $db->loadResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the nested set (lft/rgt) for the category tree.
|
||||
*
|
||||
* Uses Joomla's built-in Table rebuild method.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function rebuildCategoryTree(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
$table = \Joomla\CMS\Table\Table::getInstance('Category');
|
||||
$table->rebuild();
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->warnings[] = 'Category tree rebuild failed: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the nested set (lft/rgt) for a menu type.
|
||||
*
|
||||
* @param string $menutype Menu type to rebuild
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function rebuildMenuTree(string $menutype): void
|
||||
{
|
||||
try
|
||||
{
|
||||
$table = \Joomla\CMS\Table\Table::getInstance('Menu');
|
||||
$table->rebuild();
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$this->warnings[] = 'Menu tree rebuild failed for "' . $menutype . '": ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,634 @@
|
||||
<?php
|
||||
/**
|
||||
* @package MokoWaaS
|
||||
* @subpackage plg_system_mokowaas
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
*
|
||||
* FILE INFORMATION
|
||||
* DEFGROUP: Joomla.Plugin
|
||||
* INGROUP: MokoWaaS
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
|
||||
* PATH: /src/packages/plg_system_mokowaas/Service/ContentSyncService.php
|
||||
* VERSION: 02.26.00
|
||||
* BRIEF: Sender-side content sync — builds payload and pushes to remote sites
|
||||
*/
|
||||
|
||||
namespace Moko\Plugin\System\MokoWaaS\Service;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Log\Log;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
/**
|
||||
* Content Sync Service — builds a JSON payload of site content and pushes
|
||||
* it to one or more remote MokoWaaS sites.
|
||||
*
|
||||
* Content is matched by alias on the receiving end (upsert-by-alias).
|
||||
* Category IDs in menu item links are encoded as {catid:alias/path} tokens
|
||||
* so the receiver can resolve them to local IDs.
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
class ContentSyncService
|
||||
{
|
||||
/**
|
||||
* Maximum items per content type to prevent unbounded memory.
|
||||
*
|
||||
* @var int
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private const MAX_ITEMS = 2000;
|
||||
|
||||
/**
|
||||
* HTTP timeout for push requests in seconds.
|
||||
*
|
||||
* @var int
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private const HTTP_TIMEOUT = 60;
|
||||
|
||||
/**
|
||||
* @var \Joomla\Database\DatabaseInterface
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* Category ID → alias path map cache.
|
||||
*
|
||||
* @var array
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private array $catPathMap = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \Joomla\Database\DatabaseInterface|null $db Database driver
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function __construct($db = null)
|
||||
{
|
||||
$this->db = $db ?: Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the full sync payload from local content.
|
||||
*
|
||||
* @return array Structured payload ready for JSON encoding
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function buildPayload(): array
|
||||
{
|
||||
$this->catPathMap = $this->buildCategoryPathMap();
|
||||
|
||||
return [
|
||||
'mokowaas_sync' => '1.0',
|
||||
'source_site' => rtrim(Uri::root(), '/'),
|
||||
'generated_at' => gmdate('Y-m-d\TH:i:s\Z'),
|
||||
'categories' => $this->buildCategoryPayload(),
|
||||
'articles' => $this->buildArticlePayload(),
|
||||
'menu_types' => $this->buildMenuTypePayload(),
|
||||
'menu_items' => $this->buildMenuItemPayload(),
|
||||
'modules' => $this->buildModulePayload(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the sync payload to a single target site.
|
||||
*
|
||||
* @param string $targetUrl Base URL of the target site
|
||||
* @param string $token health_api_token for the target
|
||||
*
|
||||
* @return array Result with status, message, and per-type counts
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function pushToTarget(string $targetUrl, string $token): array
|
||||
{
|
||||
$payload = $this->buildPayload();
|
||||
$jsonBody = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
$endpoint = rtrim($targetUrl, '/') . '/?mokowaas=sync-receive';
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Authorization: Bearer {$token}\r\nContent-Type: application/json\r\n",
|
||||
'content' => $jsonBody,
|
||||
'timeout' => self::HTTP_TIMEOUT,
|
||||
'ignore_errors' => true,
|
||||
],
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
]);
|
||||
|
||||
$response = @file_get_contents($endpoint, false, $context);
|
||||
|
||||
if ($response === false)
|
||||
{
|
||||
return [
|
||||
'status' => 'error',
|
||||
'target' => $targetUrl,
|
||||
'message' => 'Connection failed — target unreachable',
|
||||
];
|
||||
}
|
||||
|
||||
// Parse HTTP status from response headers
|
||||
$httpCode = 0;
|
||||
|
||||
if (isset($http_response_header[0]))
|
||||
{
|
||||
preg_match('/\d{3}/', $http_response_header[0], $matches);
|
||||
$httpCode = (int) ($matches[0] ?? 0);
|
||||
}
|
||||
|
||||
$result = json_decode($response, true);
|
||||
|
||||
if ($httpCode >= 400 || !$result)
|
||||
{
|
||||
return [
|
||||
'status' => 'error',
|
||||
'target' => $targetUrl,
|
||||
'http_code' => $httpCode,
|
||||
'message' => $result['error'] ?? $result['message'] ?? 'Unknown error from target',
|
||||
];
|
||||
}
|
||||
|
||||
$result['target'] = $targetUrl;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push content to all configured sync targets.
|
||||
*
|
||||
* @param array $targets Array of ['url' => ..., 'token' => ..., 'label' => ...]
|
||||
*
|
||||
* @return array Per-target results
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function syncAllTargets(array $targets): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($targets as $target)
|
||||
{
|
||||
$url = $target['url'] ?? '';
|
||||
$token = $target['token'] ?? '';
|
||||
$label = $target['label'] ?? $url;
|
||||
|
||||
if (empty($url) || empty($token))
|
||||
{
|
||||
$results[] = [
|
||||
'status' => 'skipped',
|
||||
'target' => $label,
|
||||
'message' => 'Missing URL or token',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$result = $this->pushToTarget($url, $token);
|
||||
$result['label'] = $label;
|
||||
$results[] = $result;
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
$results[] = [
|
||||
'status' => 'error',
|
||||
'target' => $label,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Log::add(
|
||||
sprintf('Content sync pushed to %d target(s)', count($targets)),
|
||||
Log::INFO,
|
||||
'mokowaas'
|
||||
);
|
||||
|
||||
return [
|
||||
'status' => 'ok',
|
||||
'message' => sprintf('Sync completed for %d target(s)', count($results)),
|
||||
'targets' => $results,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build category ID → alias path map.
|
||||
*
|
||||
* @return array [id => 'parent-alias/child-alias']
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function buildCategoryPathMap(): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$query = $db->getQuery(true)
|
||||
->select([$db->quoteName('id'), $db->quoteName('alias'), $db->quoteName('parent_id')])
|
||||
->from($db->quoteName('#__categories'))
|
||||
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'))
|
||||
->where($db->quoteName('published') . ' != -2')
|
||||
->where($db->quoteName('id') . ' > 1');
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadAssocList('id');
|
||||
|
||||
$map = [];
|
||||
|
||||
foreach ($rows as $id => $row)
|
||||
{
|
||||
$map[$id] = $this->resolvePathFromRows($id, $rows);
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively build alias path for a category ID.
|
||||
*
|
||||
* @param int $id Category ID
|
||||
* @param array $rows All category rows keyed by ID
|
||||
*
|
||||
* @return string Slash-delimited alias path
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function resolvePathFromRows(int $id, array $rows): string
|
||||
{
|
||||
if (!isset($rows[$id]))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$row = $rows[$id];
|
||||
$parentId = (int) $row['parent_id'];
|
||||
|
||||
if ($parentId <= 1 || !isset($rows[$parentId]))
|
||||
{
|
||||
return $row['alias'];
|
||||
}
|
||||
|
||||
return $this->resolvePathFromRows($parentId, $rows) . '/' . $row['alias'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build category payload.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function buildCategoryPayload(): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('id'),
|
||||
$db->quoteName('title'),
|
||||
$db->quoteName('alias'),
|
||||
$db->quoteName('description'),
|
||||
$db->quoteName('published'),
|
||||
$db->quoteName('access'),
|
||||
$db->quoteName('language'),
|
||||
$db->quoteName('params'),
|
||||
$db->quoteName('metadata'),
|
||||
])
|
||||
->from($db->quoteName('#__categories'))
|
||||
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'))
|
||||
->where($db->quoteName('published') . ' != -2')
|
||||
->where($db->quoteName('id') . ' > 1')
|
||||
->order($db->quoteName('lft') . ' ASC')
|
||||
->setLimit(self::MAX_ITEMS);
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadAssocList();
|
||||
|
||||
$categories = [];
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$categories[] = [
|
||||
'title' => $row['title'],
|
||||
'alias' => $row['alias'],
|
||||
'path' => $this->catPathMap[(int) $row['id']] ?? $row['alias'],
|
||||
'description' => $row['description'] ?? '',
|
||||
'published' => (int) $row['published'],
|
||||
'access' => (int) $row['access'],
|
||||
'language' => $row['language'],
|
||||
'params' => json_decode($row['params'] ?: '{}', true),
|
||||
'metadata' => json_decode($row['metadata'] ?: '{}', true),
|
||||
];
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build article payload.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function buildArticlePayload(): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('title'),
|
||||
$db->quoteName('alias'),
|
||||
$db->quoteName('introtext'),
|
||||
$db->quoteName('fulltext'),
|
||||
$db->quoteName('state'),
|
||||
$db->quoteName('catid'),
|
||||
$db->quoteName('access'),
|
||||
$db->quoteName('language'),
|
||||
$db->quoteName('featured'),
|
||||
$db->quoteName('publish_up'),
|
||||
$db->quoteName('publish_down'),
|
||||
$db->quoteName('metadata'),
|
||||
$db->quoteName('attribs'),
|
||||
$db->quoteName('images'),
|
||||
$db->quoteName('urls'),
|
||||
])
|
||||
->from($db->quoteName('#__content'))
|
||||
->where($db->quoteName('state') . ' != -2')
|
||||
->order($db->quoteName('id') . ' ASC')
|
||||
->setLimit(self::MAX_ITEMS);
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadAssocList();
|
||||
|
||||
$articles = [];
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$articles[] = [
|
||||
'title' => $row['title'],
|
||||
'alias' => $row['alias'],
|
||||
'introtext' => $row['introtext'],
|
||||
'fulltext' => $row['fulltext'],
|
||||
'state' => (int) $row['state'],
|
||||
'catid_alias_path' => $this->catPathMap[(int) $row['catid']] ?? 'uncategorised',
|
||||
'access' => (int) $row['access'],
|
||||
'language' => $row['language'],
|
||||
'featured' => (int) $row['featured'],
|
||||
'publish_up' => $row['publish_up'],
|
||||
'publish_down' => $row['publish_down'],
|
||||
'metadata' => json_decode($row['metadata'] ?: '{}', true),
|
||||
'attribs' => json_decode($row['attribs'] ?: '{}', true),
|
||||
'images' => json_decode($row['images'] ?: '{}', true),
|
||||
'urls' => json_decode($row['urls'] ?: '{}', true),
|
||||
];
|
||||
}
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build menu type payload.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function buildMenuTypePayload(): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('title'),
|
||||
$db->quoteName('menutype'),
|
||||
$db->quoteName('description'),
|
||||
])
|
||||
->from($db->quoteName('#__menu_types'));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadAssocList() ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build menu item payload with {catid:path} tokens in links.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function buildMenuItemPayload(): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('a.title'),
|
||||
$db->quoteName('a.alias'),
|
||||
$db->quoteName('a.menutype'),
|
||||
$db->quoteName('a.parent_id'),
|
||||
$db->quoteName('a.link'),
|
||||
$db->quoteName('a.type'),
|
||||
$db->quoteName('a.published'),
|
||||
$db->quoteName('a.access'),
|
||||
$db->quoteName('a.language'),
|
||||
$db->quoteName('a.params'),
|
||||
$db->quoteName('a.home'),
|
||||
$db->quoteName('a.component_id'),
|
||||
$db->quoteName('b.alias', 'parent_alias'),
|
||||
])
|
||||
->from($db->quoteName('#__menu', 'a'))
|
||||
->leftJoin(
|
||||
$db->quoteName('#__menu', 'b') . ' ON '
|
||||
. $db->quoteName('a.parent_id') . ' = ' . $db->quoteName('b.id')
|
||||
)
|
||||
->where($db->quoteName('a.published') . ' != -2')
|
||||
->where($db->quoteName('a.client_id') . ' = 0')
|
||||
->where($db->quoteName('a.level') . ' >= 1')
|
||||
->order($db->quoteName('a.lft') . ' ASC')
|
||||
->setLimit(self::MAX_ITEMS);
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadAssocList();
|
||||
|
||||
// Get component name map
|
||||
$compQuery = $db->getQuery(true)
|
||||
->select([$db->quoteName('extension_id'), $db->quoteName('element')])
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('component'));
|
||||
$db->setQuery($compQuery);
|
||||
$components = $db->loadAssocList('extension_id') ?: [];
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$link = $row['link'];
|
||||
|
||||
// Encode category IDs in com_content links as {catid:path} tokens
|
||||
if (preg_match('/option=com_content/', $link) && preg_match('/&id=(\d+)/', $link, $m))
|
||||
{
|
||||
$catId = (int) $m[1];
|
||||
|
||||
if (isset($this->catPathMap[$catId]))
|
||||
{
|
||||
$link = preg_replace('/&id=\d+/', '&id={catid:' . $this->catPathMap[$catId] . '}', $link);
|
||||
}
|
||||
}
|
||||
|
||||
$compName = '';
|
||||
|
||||
if (!empty($row['component_id']) && isset($components[$row['component_id']]))
|
||||
{
|
||||
$compName = $components[$row['component_id']]['element'];
|
||||
}
|
||||
|
||||
// Root-level items have parent_id=1 (Joomla's root menu item)
|
||||
$parentAlias = ((int) $row['parent_id'] <= 1) ? '' : ($row['parent_alias'] ?? '');
|
||||
|
||||
$items[] = [
|
||||
'title' => $row['title'],
|
||||
'alias' => $row['alias'],
|
||||
'menutype' => $row['menutype'],
|
||||
'parent_alias' => $parentAlias,
|
||||
'link' => $link,
|
||||
'type' => $row['type'],
|
||||
'component_name' => $compName,
|
||||
'published' => (int) $row['published'],
|
||||
'access' => (int) $row['access'],
|
||||
'language' => $row['language'],
|
||||
'params' => json_decode($row['params'] ?: '{}', true),
|
||||
'home' => (int) $row['home'],
|
||||
];
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build module payload with menu assignments.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function buildModulePayload(): array
|
||||
{
|
||||
$db = $this->db;
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('id'),
|
||||
$db->quoteName('title'),
|
||||
$db->quoteName('module'),
|
||||
$db->quoteName('position'),
|
||||
$db->quoteName('content'),
|
||||
$db->quoteName('published'),
|
||||
$db->quoteName('access'),
|
||||
$db->quoteName('language'),
|
||||
$db->quoteName('params'),
|
||||
$db->quoteName('client_id'),
|
||||
])
|
||||
->from($db->quoteName('#__modules'))
|
||||
->where($db->quoteName('client_id') . ' = 0')
|
||||
->where($db->quoteName('published') . ' != -2')
|
||||
->order($db->quoteName('ordering') . ' ASC')
|
||||
->setLimit(self::MAX_ITEMS);
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadAssocList();
|
||||
|
||||
// Get all module-menu assignments
|
||||
$mmQuery = $db->getQuery(true)
|
||||
->select([
|
||||
$db->quoteName('mm.moduleid'),
|
||||
$db->quoteName('mm.menuid'),
|
||||
$db->quoteName('m.alias', 'menu_alias'),
|
||||
$db->quoteName('m.menutype'),
|
||||
])
|
||||
->from($db->quoteName('#__modules_menu', 'mm'))
|
||||
->leftJoin(
|
||||
$db->quoteName('#__menu', 'm') . ' ON '
|
||||
. $db->quoteName('mm.menuid') . ' = ' . $db->quoteName('m.id')
|
||||
);
|
||||
$db->setQuery($mmQuery);
|
||||
$allAssignments = $db->loadAssocList();
|
||||
|
||||
// Group assignments by module ID
|
||||
$assignmentsByModule = [];
|
||||
|
||||
foreach ($allAssignments as $a)
|
||||
{
|
||||
$assignmentsByModule[(int) $a['moduleid']][] = $a;
|
||||
}
|
||||
|
||||
$modules = [];
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$moduleId = (int) $row['id'];
|
||||
$assignments = $assignmentsByModule[$moduleId] ?? [];
|
||||
|
||||
// Determine assignment type: 0 = all pages, positive = selected, negative = excluded
|
||||
$menuAliases = [];
|
||||
$assignType = 0;
|
||||
|
||||
if (!empty($assignments))
|
||||
{
|
||||
$firstMenuId = (int) $assignments[0]['menuid'];
|
||||
|
||||
if ($firstMenuId === 0)
|
||||
{
|
||||
$assignType = 0; // All pages
|
||||
}
|
||||
elseif ($firstMenuId < 0)
|
||||
{
|
||||
$assignType = -1; // All except selected
|
||||
foreach ($assignments as $a)
|
||||
{
|
||||
if (!empty($a['menu_alias']))
|
||||
{
|
||||
$menuAliases[] = $a['menutype'] . ':' . $a['menu_alias'];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$assignType = 1; // Selected only
|
||||
foreach ($assignments as $a)
|
||||
{
|
||||
if (!empty($a['menu_alias']))
|
||||
{
|
||||
$menuAliases[] = $a['menutype'] . ':' . $a['menu_alias'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$modules[] = [
|
||||
'title' => $row['title'],
|
||||
'module' => $row['module'],
|
||||
'position' => $row['position'],
|
||||
'content' => $row['content'],
|
||||
'published' => (int) $row['published'],
|
||||
'access' => (int) $row['access'],
|
||||
'language' => $row['language'],
|
||||
'params' => json_decode($row['params'] ?: '{}', true),
|
||||
'client_id' => (int) $row['client_id'],
|
||||
'menu_assignment' => [
|
||||
'assignment' => $assignType,
|
||||
'menu_item_aliases' => $menuAliases,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
* INGROUP: MokoWaaS
|
||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS
|
||||
* PATH: /src/packages/plg_system_mokowaas/Service/DemoResetService.php
|
||||
* VERSION: 02.21.02
|
||||
* VERSION: 02.26.00
|
||||
* BRIEF: Core snapshot/restore service for demo site reset
|
||||
*/
|
||||
|
||||
@@ -91,27 +91,39 @@ class DemoResetService
|
||||
private array $tables;
|
||||
|
||||
/**
|
||||
* Whether to include media files in snapshots.
|
||||
* Directories to include in media snapshot (e.g. ['images', 'media']).
|
||||
*
|
||||
* @var bool
|
||||
* @since 02.21.00
|
||||
* @var array
|
||||
* @since 02.25.00
|
||||
*/
|
||||
private bool $includeMedia;
|
||||
private array $mediaDirs;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $tables Table names with #__ prefix
|
||||
* @param bool $includeMedia Include /images/ directory in snapshot
|
||||
* @param string $baseDir Override snapshot root (for testing)
|
||||
* @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)
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
public function __construct(array $tables = [], bool $includeMedia = true, string $baseDir = '')
|
||||
public function __construct(array $tables = [], $mediaDirs = ['images'], string $baseDir = '')
|
||||
{
|
||||
$this->tables = !empty($tables) ? $tables : self::DEFAULT_TABLES;
|
||||
$this->includeMedia = $includeMedia;
|
||||
$this->snapshotDir = $baseDir ?: JPATH_ROOT . '/mokowaas-snapshots';
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,12 +205,22 @@ class DemoResetService
|
||||
$dumped++;
|
||||
}
|
||||
|
||||
// Media snapshot
|
||||
$hasMedia = false;
|
||||
// Media snapshot — one ZIP per directory
|
||||
$mediaDirs = [];
|
||||
|
||||
if ($this->includeMedia)
|
||||
foreach ($this->mediaDirs as $dir)
|
||||
{
|
||||
$hasMedia = $this->snapshotMedia($path);
|
||||
$fullPath = JPATH_ROOT . '/' . $dir;
|
||||
|
||||
if (is_dir($fullPath))
|
||||
{
|
||||
$zipName = 'media_' . $dir . '.zip';
|
||||
|
||||
if ($this->snapshotDirectory($fullPath, $path . '/' . $zipName))
|
||||
{
|
||||
$mediaDirs[] = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write manifest
|
||||
@@ -207,7 +229,8 @@ class DemoResetService
|
||||
'created_at' => gmdate('Y-m-d\TH:i:s\Z'),
|
||||
'tables' => $dumped,
|
||||
'table_list' => $this->tables,
|
||||
'has_media' => $hasMedia,
|
||||
'has_media' => !empty($mediaDirs),
|
||||
'media_dirs' => $mediaDirs,
|
||||
'joomla_version' => JVERSION,
|
||||
];
|
||||
|
||||
@@ -308,12 +331,41 @@ class DemoResetService
|
||||
}
|
||||
}
|
||||
|
||||
// Restore media
|
||||
// Restore media directories
|
||||
$mediaRestored = false;
|
||||
$restoredDirs = $manifest['media_dirs'] ?? [];
|
||||
|
||||
if ($manifest['has_media'] ?? false)
|
||||
// Legacy support: old manifests used has_media=true with a single media.zip for /images/
|
||||
if (empty($restoredDirs) && ($manifest['has_media'] ?? false))
|
||||
{
|
||||
$mediaRestored = $this->restoreMedia($path);
|
||||
$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';
|
||||
}
|
||||
|
||||
if (file_exists($zipPath))
|
||||
{
|
||||
$targetDir = JPATH_ROOT . '/' . $dir;
|
||||
$this->clearDirectory($targetDir);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
if ($zip->open($zipPath) === true)
|
||||
{
|
||||
$zip->extractTo($targetDir);
|
||||
$zip->close();
|
||||
$mediaRestored = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log::add(
|
||||
@@ -495,25 +547,23 @@ class DemoResetService
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ZIP archive of the /images/ directory.
|
||||
* Create a ZIP archive of a directory.
|
||||
*
|
||||
* @param string $snapshotDir Snapshot directory path
|
||||
* @param string $sourceDir Full path to the directory to archive
|
||||
* @param string $zipPath Full path for the output ZIP file
|
||||
*
|
||||
* @return bool True if media was archived
|
||||
* @return bool True if archived successfully
|
||||
*
|
||||
* @since 02.21.00
|
||||
* @since 02.25.00
|
||||
*/
|
||||
private function snapshotMedia(string $snapshotDir): bool
|
||||
private function snapshotDirectory(string $sourceDir, string $zipPath): bool
|
||||
{
|
||||
$imagesDir = JPATH_ROOT . '/images';
|
||||
|
||||
if (!is_dir($imagesDir))
|
||||
if (!is_dir($sourceDir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$zipPath = $snapshotDir . '/media.zip';
|
||||
$zip = new \ZipArchive();
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
if ($zip->open($zipPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true)
|
||||
{
|
||||
@@ -521,13 +571,13 @@ class DemoResetService
|
||||
}
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($imagesDir, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
new \RecursiveDirectoryIterator($sourceDir, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
|
||||
foreach ($iterator as $item)
|
||||
{
|
||||
$relativePath = substr($item->getPathname(), strlen($imagesDir) + 1);
|
||||
$relativePath = substr($item->getPathname(), strlen($sourceDir) + 1);
|
||||
$relativePath = str_replace('\\', '/', $relativePath);
|
||||
|
||||
if ($item->isDir())
|
||||
@@ -545,41 +595,6 @@ class DemoResetService
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore media files from a snapshot ZIP.
|
||||
*
|
||||
* @param string $snapshotDir Snapshot directory path
|
||||
*
|
||||
* @return bool True if media was restored
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function restoreMedia(string $snapshotDir): bool
|
||||
{
|
||||
$zipPath = $snapshotDir . '/media.zip';
|
||||
$imagesDir = JPATH_ROOT . '/images';
|
||||
|
||||
if (!file_exists($zipPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear existing images directory contents (keep the directory itself)
|
||||
$this->clearDirectory($imagesDir);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
if ($zip->open($zipPath) !== true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$zip->extractTo($imagesDir);
|
||||
$zip->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the snapshot root directory exists with .htaccess protection.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<field name="url" type="url"
|
||||
label="PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_URL_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_URL_DESC"
|
||||
required="true" hint="https://client.example.com" />
|
||||
<field name="token" type="text"
|
||||
label="PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_TOKEN_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_TOKEN_DESC"
|
||||
required="true" hint="health_api_token from target site" />
|
||||
<field name="label" type="text"
|
||||
label="PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_LABEL_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_LABEL_DESC"
|
||||
hint="e.g. Client A" />
|
||||
</form>
|
||||
@@ -16,7 +16,7 @@
|
||||
; Variables: (none)
|
||||
; -----------------------------------------------------------------------------
|
||||
|
||||
PLG_SYSTEM_MOKOWAAS="System - Moko WaaS"
|
||||
PLG_SYSTEM_MOKOWAAS="System - MokoWaaS"
|
||||
PLG_SYSTEM_MOKOWAAS_XML_DESCRIPTION="This plugin rebrands the Joomla system interface with MokoWaaS identity. It applies language overrides and ensures consistent branding across the platform."
|
||||
|
||||
PLG_SYSTEM_MOKOWAAS_ENABLE_BRANDING_LABEL="Enable Branding"
|
||||
@@ -99,6 +99,20 @@ PLG_SYSTEM_MOKOWAAS_DISABLE_INSTALL_URL_DESC="Block installing extensions from U
|
||||
PLG_SYSTEM_MOKOWAAS_HIDDEN_MENUS_LABEL="Hidden Menu Items"
|
||||
PLG_SYSTEM_MOKOWAAS_HIDDEN_MENUS_DESC="Components to hide from admin menu for non-master users. One per line (e.g., com_installer)."
|
||||
|
||||
; ===== Content Sync fieldset =====
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_SYNC_LABEL="Content Sync"
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_SYNC_DESC="One-way content push to remote MokoWaaS sites. Syncs articles, categories, menus, and modules by alias."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGETS_LABEL="Sync Targets"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGETS_DESC="Remote sites to push content to. Each target requires the site URL and that site's health API token."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_PUSH_NOW_LABEL="Push Content Now"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_PUSH_NOW_DESC="Set to Yes and save to immediately push all content to all configured targets. Resets to No automatically."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_URL_LABEL="Site URL"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_URL_DESC="Full URL of the remote Joomla site (e.g. https://client.example.com)."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_TOKEN_LABEL="API Token"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_TOKEN_DESC="The health_api_token from the remote site's MokoWaaS plugin settings."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_LABEL_LABEL="Label"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_LABEL_DESC="Friendly name for this target (for identification only)."
|
||||
|
||||
; ===== Diagnostics fieldset =====
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_LABEL="Diagnostics & Monitoring"
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_DESC="Health check endpoint for external monitoring systems (e.g. Grafana). Exposes system status via a token-authenticated JSON API."
|
||||
@@ -149,12 +163,16 @@ PLG_SYSTEM_MOKOWAAS_DEMO_BANNER_COLOR_LABEL="Banner Color"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_BANNER_COLOR_DESC="Background color for the demo warning banner."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_COUNTDOWN_LABEL="Show Reset Countdown"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_COUNTDOWN_DESC="Display a countdown timer in the banner showing time until the next scheduled reset."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_INTERVAL_LABEL="Reset Interval (Hours)"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_INTERVAL_DESC="Hours between scheduled demo resets. Used for countdown display and scheduled task interval."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_SCHEDULE_LABEL="Reset Schedule"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_SCHEDULE_DESC="How often the demo site resets. Select a preset or choose Custom to enter a crontab expression."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_CRON_LABEL="Custom Crontab"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_CRON_DESC="Crontab expression for the reset schedule. Format: minute hour day month weekday (e.g. 0 */6 * * * for every 6 hours)."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_LABEL="Next Scheduled Reset"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_DESC="Calculated automatically from the reset schedule. The banner countdown uses this timestamp."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_LABEL="Snapshot Tables"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_DESC="Database tables to include in snapshots. One per line, using #__ prefix. These tables will be truncated and restored during a reset."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_LABEL="Include Media Files"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC="Include the /images/ directory in snapshots. Disabling this speeds up snapshot/restore for sites with large media libraries."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_LABEL="Include Directories"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC="Select which directories to include in the snapshot. Images contains uploaded media, Media contains extension assets."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_ACTIVE_BASELINE_LABEL="Active Baseline Name"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_ACTIVE_BASELINE_DESC="Name of the baseline snapshot used by admin toggles and scheduled tasks. Alphanumeric, hyphens, and underscores only."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_TAKE_SNAPSHOT_LABEL="Take Snapshot Now"
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
; Variables: (none)
|
||||
; -----------------------------------------------------------------------------
|
||||
|
||||
PLG_SYSTEM_MOKOWAAS="System - Moko WaaS"
|
||||
PLG_SYSTEM_MOKOWAAS="System - MokoWaaS"
|
||||
PLG_SYSTEM_MOKOWAAS_XML_DESCRIPTION="This plugin rebrands the Joomla system interface with MokoWaaS identity. It applies language overrides and ensures consistent branding across the platform."
|
||||
|
||||
@@ -99,6 +99,20 @@ PLG_SYSTEM_MOKOWAAS_DISABLE_INSTALL_URL_DESC="Block installing extensions from U
|
||||
PLG_SYSTEM_MOKOWAAS_HIDDEN_MENUS_LABEL="Hidden Menu Items"
|
||||
PLG_SYSTEM_MOKOWAAS_HIDDEN_MENUS_DESC="Components to hide from admin menu for non-master users. One per line (e.g., com_installer)."
|
||||
|
||||
; ===== Content Sync fieldset =====
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_SYNC_LABEL="Content Sync"
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_SYNC_DESC="One-way content push to remote MokoWaaS sites. Syncs articles, categories, menus, and modules by alias."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGETS_LABEL="Sync Targets"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGETS_DESC="Remote sites to push content to. Each target requires the site URL and that site's health API token."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_PUSH_NOW_LABEL="Push Content Now"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_PUSH_NOW_DESC="Set to Yes and save to immediately push all content to all configured targets. Resets to No automatically."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_URL_LABEL="Site URL"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_URL_DESC="Full URL of the remote Joomla site (e.g. https://client.example.com)."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_TOKEN_LABEL="API Token"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_TOKEN_DESC="The health_api_token from the remote site's MokoWaaS plugin settings."
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_LABEL_LABEL="Label"
|
||||
PLG_SYSTEM_MOKOWAAS_SYNC_TARGET_LABEL_DESC="Friendly name for this target (for identification only)."
|
||||
|
||||
; ===== Diagnostics fieldset =====
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_LABEL="Diagnostics & Monitoring"
|
||||
PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_DESC="Health check endpoint for external monitoring systems (e.g. Grafana). Exposes system status via a token-authenticated JSON API."
|
||||
@@ -149,12 +163,16 @@ PLG_SYSTEM_MOKOWAAS_DEMO_BANNER_COLOR_LABEL="Banner Color"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_BANNER_COLOR_DESC="Background color for the demo warning banner."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_COUNTDOWN_LABEL="Show Reset Countdown"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_COUNTDOWN_DESC="Display a countdown timer in the banner showing time until the next scheduled reset."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_INTERVAL_LABEL="Reset Interval (Hours)"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_INTERVAL_DESC="Hours between scheduled demo resets. Used for countdown display and scheduled task interval."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_SCHEDULE_LABEL="Reset Schedule"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_SCHEDULE_DESC="How often the demo site resets. Select a preset or choose Custom to enter a crontab expression."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_CRON_LABEL="Custom Crontab"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_CRON_DESC="Crontab expression for the reset schedule. Format: minute hour day month weekday (e.g. 0 */6 * * * for every 6 hours)."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_LABEL="Next Scheduled Reset"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_DESC="Calculated automatically from the reset schedule. The banner countdown uses this timestamp."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_LABEL="Snapshot Tables"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_DESC="Database tables to include in snapshots. One per line, using #__ prefix. These tables will be truncated and restored during a reset."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_LABEL="Include Media Files"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC="Include the /images/ directory in snapshots. Disabling this speeds up snapshot/restore for sites with large media libraries."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_LABEL="Include Directories"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC="Select which directories to include in the snapshot. Images contains uploaded media, Media contains extension assets."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_ACTIVE_BASELINE_LABEL="Active Baseline Name"
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_ACTIVE_BASELINE_DESC="Name of the baseline snapshot used by admin toggles and scheduled tasks. Alphanumeric, hyphens, and underscores only."
|
||||
PLG_SYSTEM_MOKOWAAS_DEMO_TAKE_SNAPSHOT_LABEL="Take Snapshot Now"
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
; Variables: (none)
|
||||
; -----------------------------------------------------------------------------
|
||||
|
||||
PLG_SYSTEM_MOKOWAAS="System - Moko WaaS"
|
||||
PLG_SYSTEM_MOKOWAAS="System - MokoWaaS"
|
||||
PLG_SYSTEM_MOKOWAAS_XML_DESCRIPTION="This plugin rebrands the Joomla system interface with MokoWaaS identity. It applies language overrides and ensures consistent branding across the platform."
|
||||
|
||||
@@ -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.21.02-dev</version>
|
||||
<version>02.26.00</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>
|
||||
@@ -268,6 +268,7 @@
|
||||
<fieldset name="demo_mode"
|
||||
label="PLG_SYSTEM_MOKOWAAS_FIELDSET_DEMO_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_FIELDSET_DEMO_DESC"
|
||||
addfieldprefix="Moko\Plugin\System\MokoWaaS\Field"
|
||||
>
|
||||
<field name="demo_mode_enabled" type="radio" default="0"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_ENABLED_LABEL"
|
||||
@@ -291,21 +292,41 @@
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
<field name="demo_reset_interval_hours" type="number"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_INTERVAL_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_DEMO_INTERVAL_DESC"
|
||||
default="24" hint="Hours between scheduled resets" />
|
||||
<field name="demo_snapshot_tables" type="textarea"
|
||||
<field name="demo_reset_schedule" type="list"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_SCHEDULE_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_DEMO_SCHEDULE_DESC"
|
||||
default="0 0 * * *">
|
||||
<option value="*/5 * * * *">Every 5 minutes</option>
|
||||
<option value="*/15 * * * *">Every 15 minutes</option>
|
||||
<option value="*/30 * * * *">Every 30 minutes</option>
|
||||
<option value="0 */1 * * *">Every hour</option>
|
||||
<option value="0 */4 * * *">Every 4 hours</option>
|
||||
<option value="0 */6 * * *">Every 6 hours</option>
|
||||
<option value="0 */12 * * *">Every 12 hours</option>
|
||||
<option value="0 0 * * *">Daily at midnight</option>
|
||||
<option value="0 6 * * *">Daily at 6:00 AM</option>
|
||||
<option value="0 0 * * 0">Weekly (Sunday midnight)</option>
|
||||
<option value="0 0 1 * *">Monthly (1st at midnight)</option>
|
||||
<option value="custom">Custom crontab...</option>
|
||||
</field>
|
||||
<field name="demo_reset_cron" type="text"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_CRON_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_DEMO_CRON_DESC"
|
||||
default="" hint="min hour day month weekday (e.g. 0 */6 * * *)"
|
||||
showon="demo_reset_schedule:custom" />
|
||||
<field name="demo_next_reset" type="text"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_DEMO_NEXT_RESET_DESC"
|
||||
readonly="true" default="" />
|
||||
<field name="demo_snapshot_tables" type="SnapshotTables"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_DEMO_TABLES_DESC"
|
||||
rows="8" filter="raw"
|
||||
default="#__content #__categories #__fields #__fields_values #__fields_groups #__menu #__menu_types #__modules #__modules_menu #__users #__user_usergroup_map #__user_profiles #__tags #__contentitem_tag_map #__assets" />
|
||||
<field name="demo_snapshot_include_media" type="radio" default="1"
|
||||
/>
|
||||
<field name="demo_snapshot_include_media" type="checkboxes"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC"
|
||||
class="btn-group btn-group-yesno">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
description="PLG_SYSTEM_MOKOWAAS_DEMO_MEDIA_DESC">
|
||||
<option value="images">Images (/images/)</option>
|
||||
<option value="media">Media (/media/)</option>
|
||||
</field>
|
||||
<field name="demo_active_baseline" type="text"
|
||||
label="PLG_SYSTEM_MOKOWAAS_DEMO_ACTIVE_BASELINE_LABEL"
|
||||
@@ -350,13 +371,37 @@
|
||||
buttons="add,remove,move"
|
||||
/>
|
||||
</fieldset>
|
||||
<fieldset name="diagnostics"
|
||||
<fieldset name="content_sync"
|
||||
label="PLG_SYSTEM_MOKOWAAS_FIELDSET_SYNC_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_FIELDSET_SYNC_DESC"
|
||||
>
|
||||
<field
|
||||
name="sync_targets"
|
||||
type="subform"
|
||||
label="PLG_SYSTEM_MOKOWAAS_SYNC_TARGETS_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_SYNC_TARGETS_DESC"
|
||||
formsource="plugins/system/mokowaas/forms/sync_target_entry.xml"
|
||||
multiple="true"
|
||||
layout="joomla.form.field.subform.repeatable-table"
|
||||
groupByFieldset="false"
|
||||
buttons="add,remove,move"
|
||||
/>
|
||||
<field name="sync_push_now" type="radio" default="0"
|
||||
label="PLG_SYSTEM_MOKOWAAS_SYNC_PUSH_NOW_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_SYNC_PUSH_NOW_DESC"
|
||||
class="btn-group btn-group-yesno">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
<fieldset name="diagnostics"
|
||||
label="PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_FIELDSET_DIAGNOSTICS_DESC"
|
||||
addfieldprefix="Moko\Plugin\System\MokoWaaS\Field"
|
||||
>
|
||||
<field
|
||||
name="health_api_token"
|
||||
type="text"
|
||||
type="CopyableToken"
|
||||
label="PLG_SYSTEM_MOKOWAAS_HEALTH_TOKEN_LABEL"
|
||||
description="PLG_SYSTEM_MOKOWAAS_HEALTH_TOKEN_DESC"
|
||||
default=""
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* DEFGROUP: Joomla.Plugin
|
||||
* INGROUP: MokoWaaS
|
||||
* REPO: https://github.com/mokoconsulting-tech/mokowaas
|
||||
* VERSION: 02.21.02
|
||||
* VERSION: 02.26.00
|
||||
* 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.21.02
|
||||
* VERSION: 02.26.00
|
||||
* PATH: /src/services/provider.php
|
||||
* BRIEF: Service provider for dependency injection in Joomla 5.x
|
||||
* NOTE: Registers the plugin with Joomla's DI container
|
||||
|
||||
+2
-1
@@ -12,11 +12,12 @@
|
||||
<license>GNU General Public License version 3 or later; see LICENSE</license>
|
||||
<authorEmail>hello@mokoconsulting.tech</authorEmail>
|
||||
<authorUrl>https://mokoconsulting.tech</authorUrl>
|
||||
<version>02.21.02-dev</version>
|
||||
<version>02.26.00</version>
|
||||
<description>PLG_TASK_MOKOWAASDEMO_DESC</description>
|
||||
<namespace path="src">Moko\Plugin\Task\MokoWaaSDemo</namespace>
|
||||
|
||||
<files>
|
||||
<filename plugin="mokowaasdemo">mokowaasdemo.xml</filename>
|
||||
<folder>src</folder>
|
||||
<folder>services</folder>
|
||||
<folder>forms</folder>
|
||||
+6
-4
@@ -97,11 +97,13 @@ final class DemoReset extends CMSPlugin implements SubscriberInterface
|
||||
|
||||
require_once $serviceFile;
|
||||
|
||||
$tablesRaw = $sysParams->get('demo_snapshot_tables', '');
|
||||
$tables = array_filter(array_map('trim', explode("\n", $tablesRaw)));
|
||||
$media = (bool) $sysParams->get('demo_snapshot_include_media', 1);
|
||||
$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 = [];
|
||||
|
||||
$service = new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, $media);
|
||||
$service = new \Moko\Plugin\System\MokoWaaS\Service\DemoResetService($tables, (array) $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.21.02-dev</version>
|
||||
<version>02.26.00</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>
|
||||
|
||||
@@ -82,5 +82,23 @@ final class MokoWaaSApi extends CMSPlugin implements SubscriberInterface
|
||||
'snapshot',
|
||||
['component' => 'com_mokowaas']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/mokowaas/sync',
|
||||
'sync',
|
||||
['component' => 'com_mokowaas']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/mokowaas/sync-receive',
|
||||
'syncreceive',
|
||||
['component' => 'com_mokowaas']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/mokowaas/extensions',
|
||||
'extensions',
|
||||
['component' => 'com_mokowaas']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<license>GPL-3.0-or-later</license>
|
||||
<authorEmail>hello@mokoconsulting.tech</authorEmail>
|
||||
<authorUrl>https://mokoconsulting.tech</authorUrl>
|
||||
<version>02.21.02-dev</version>
|
||||
<version>02.26.00</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.21.02
|
||||
* VERSION: 02.26.00
|
||||
* 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.21.02
|
||||
* VERSION: 02.26.00
|
||||
* BRIEF: Web Services API plugin for Perfect Publisher (com_autotweet)
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="package" method="upgrade">
|
||||
<name>MokoWaaS</name>
|
||||
<name>Package - MokoWaaS</name>
|
||||
<packagename>mokowaas</packagename>
|
||||
<version>02.21.02-dev</version>
|
||||
<version>02.26.00</version>
|
||||
<creationDate>2026-05-23</creationDate>
|
||||
<author>Moko Consulting</author>
|
||||
<authorEmail>hello@mokoconsulting.tech</authorEmail>
|
||||
|
||||
+146
-3
@@ -34,6 +34,9 @@ class Pkg_MokowaasInstallerScript
|
||||
*/
|
||||
public function postflight($type, $parent)
|
||||
{
|
||||
// Remove legacy extensions from before the package rewrite
|
||||
$this->cleanupLegacyExtensions();
|
||||
|
||||
$this->enablePlugin('system', 'mokowaas');
|
||||
$this->enablePlugin('webservices', 'mokowaas');
|
||||
$this->enablePlugin('task', 'mokowaasdemo');
|
||||
@@ -45,6 +48,101 @@ class Pkg_MokowaasInstallerScript
|
||||
$this->sendHeartbeat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove legacy/stale extension entries and filesystem remnants.
|
||||
*
|
||||
* The old standalone plugin was named "mokowaasbrand" (plg_system_mokowaasbrand).
|
||||
* After the rewrite into the pkg_mokowaas package, the old entries and files
|
||||
* may linger — especially on sites restored from old backups.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function cleanupLegacyExtensions(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Legacy element names to remove from #__extensions
|
||||
$legacy = [
|
||||
$db->quote('mokowaasbrand'),
|
||||
$db->quote('plg_system_mokowaasbrand'),
|
||||
];
|
||||
|
||||
// Delete from #__extensions
|
||||
$query = $db->getQuery(true)
|
||||
->delete($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('element') . ' IN (' . implode(',', $legacy) . ')');
|
||||
$db->setQuery($query);
|
||||
$affected = $db->execute();
|
||||
$count = $db->getAffectedRows();
|
||||
|
||||
// Remove legacy plugin files from the filesystem
|
||||
$legacyDirs = [
|
||||
JPATH_PLUGINS . '/system/mokowaasbrand',
|
||||
];
|
||||
|
||||
foreach ($legacyDirs as $dir)
|
||||
{
|
||||
if (is_dir($dir))
|
||||
{
|
||||
$this->rmdirRecursive($dir);
|
||||
}
|
||||
}
|
||||
|
||||
if ($count > 0)
|
||||
{
|
||||
Factory::getApplication()->enqueueMessage(
|
||||
sprintf('Removed %d legacy MokoWaaS extension(s).', $count),
|
||||
'message'
|
||||
);
|
||||
|
||||
Log::add(
|
||||
sprintf('Cleaned up %d legacy MokoWaaS extension entries', $count),
|
||||
Log::INFO,
|
||||
'mokowaas'
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
Log::add('Legacy cleanup error: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively remove a directory.
|
||||
*
|
||||
* @param string $dir Directory path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function rmdirRecursive(string $dir): void
|
||||
{
|
||||
$items = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if ($item->isDir())
|
||||
{
|
||||
@rmdir($item->getPathname());
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($item->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
@rmdir($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a plugin by group and element.
|
||||
*
|
||||
@@ -90,18 +188,63 @@ class Pkg_MokowaasInstallerScript
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// All MokoWaaS elements: package, system plugin, component,
|
||||
// webservices plugins, task plugin
|
||||
$elements = [
|
||||
$db->quote('pkg_mokowaas'),
|
||||
$db->quote('mokowaas'),
|
||||
$db->quote('com_mokowaas'),
|
||||
$db->quote('mokowaasdemo'),
|
||||
$db->quote('perfectpublisher'),
|
||||
];
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__extensions'))
|
||||
->set($db->quoteName('protected') . ' = 1')
|
||||
->set($db->quoteName('locked') . ' = 0')
|
||||
->where('(' . $db->quoteName('element') . ' = ' . $db->quote('mokowaas')
|
||||
. ' OR ' . $db->quoteName('element') . ' = ' . $db->quote('pkg_mokowaas') . ')');
|
||||
->where($db->quoteName('element') . ' IN (' . implode(',', $elements) . ')');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
// Ensure update server stays enabled
|
||||
$this->enableUpdateServer();
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
Log::add('Error protecting MokoWaaS extensions: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the MokoWaaS update server entry stays enabled.
|
||||
*
|
||||
* Joomla stores update server records in #__update_sites. If a tenant
|
||||
* or automation disables it, the site stops receiving updates. This
|
||||
* re-enables it on every install/update.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 02.21.00
|
||||
*/
|
||||
private function enableUpdateServer(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Find update site by name or URL pattern
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__update_sites'))
|
||||
->set($db->quoteName('enabled') . ' = 1')
|
||||
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoWaaS%')
|
||||
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoWaaS%') . ')');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
Log::add('Error protecting MokoWaaS extensions: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
||||
Log::add('Error enabling update server: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
-44
@@ -1,23 +1,42 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
VERSION: 02.22.00
|
||||
VERSION: 02.26.00
|
||||
-->
|
||||
|
||||
<updates>
|
||||
<update>
|
||||
<name>MokoWaaS</name>
|
||||
<description>MokoWaaS dev build.</description>
|
||||
<name>Package - MokoWaaS</name>
|
||||
<description>Package - MokoWaaS stable build.</description>
|
||||
<element>pkg_mokowaas</element>
|
||||
<type>package</type>
|
||||
<client>site</client>
|
||||
<version>02.22.00-dev</version>
|
||||
<version>02.25.00</version>
|
||||
<creationDate>2026-05-30</creationDate>
|
||||
<infourl title="MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/development</infourl>
|
||||
<infourl title="Package - MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/stable</infourl>
|
||||
<downloads>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/development/pkg_mokowaas-02.22.00-dev.zip</downloadurl>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/stable/pkg_mokowaas-02.25.00.zip</downloadurl>
|
||||
</downloads>
|
||||
<sha256>d8dd0870f27b39d01e4c3057afd27c882aa277b601d9c134f69fe4cba1d2b57c</sha256>
|
||||
<sha256>67f7f86d822d8dc6f450c1d0b68fbaca886ccb42046bcb3c04da909789f95c28</sha256>
|
||||
<tags><tag>stable</tag></tags>
|
||||
<changelogurl>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/CHANGELOG.md</changelogurl>
|
||||
<maintainer>Moko Consulting</maintainer>
|
||||
<maintainerurl>https://mokoconsulting.tech</maintainerurl>
|
||||
<targetplatform name="joomla" version="(5|6)\..*"/>
|
||||
</update>
|
||||
<update>
|
||||
<name>Package - MokoWaaS</name>
|
||||
<description>Package - MokoWaaS dev build.</description>
|
||||
<element>pkg_mokowaas</element>
|
||||
<type>package</type>
|
||||
<client>site</client>
|
||||
<version>02.26.00-dev</version>
|
||||
<creationDate>2026-05-30</creationDate>
|
||||
<infourl title="Package - MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/development</infourl>
|
||||
<downloads>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/development/pkg_mokowaas-02.26.00-dev.zip</downloadurl>
|
||||
</downloads>
|
||||
<sha256>22f4def98469d371d673cde0c740a9b54a5e71d2eeb15c4506aed159541daae8</sha256>
|
||||
<tags><tag>dev</tag></tags>
|
||||
<changelogurl>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/CHANGELOG.md</changelogurl>
|
||||
<maintainer>Moko Consulting</maintainer>
|
||||
@@ -25,18 +44,18 @@
|
||||
<targetplatform name="joomla" version="(5|6)\..*"/>
|
||||
</update>
|
||||
<update>
|
||||
<name>MokoWaaS</name>
|
||||
<description>MokoWaaS alpha build.</description>
|
||||
<name>Package - MokoWaaS</name>
|
||||
<description>Package - MokoWaaS alpha build.</description>
|
||||
<element>pkg_mokowaas</element>
|
||||
<type>package</type>
|
||||
<client>site</client>
|
||||
<version>02.22.00-alpha</version>
|
||||
<version>02.26.00-alpha</version>
|
||||
<creationDate>2026-05-30</creationDate>
|
||||
<infourl title="MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/alpha</infourl>
|
||||
<infourl title="Package - MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/alpha</infourl>
|
||||
<downloads>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/alpha/pkg_mokowaas-02.22.00-alpha.zip</downloadurl>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/alpha/pkg_mokowaas-02.26.00-alpha.zip</downloadurl>
|
||||
</downloads>
|
||||
<sha256>d8dd0870f27b39d01e4c3057afd27c882aa277b601d9c134f69fe4cba1d2b57c</sha256>
|
||||
<sha256>22f4def98469d371d673cde0c740a9b54a5e71d2eeb15c4506aed159541daae8</sha256>
|
||||
<tags><tag>alpha</tag></tags>
|
||||
<changelogurl>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/CHANGELOG.md</changelogurl>
|
||||
<maintainer>Moko Consulting</maintainer>
|
||||
@@ -44,18 +63,18 @@
|
||||
<targetplatform name="joomla" version="(5|6)\..*"/>
|
||||
</update>
|
||||
<update>
|
||||
<name>MokoWaaS</name>
|
||||
<description>MokoWaaS beta build.</description>
|
||||
<name>Package - MokoWaaS</name>
|
||||
<description>Package - MokoWaaS beta build.</description>
|
||||
<element>pkg_mokowaas</element>
|
||||
<type>package</type>
|
||||
<client>site</client>
|
||||
<version>02.22.00-beta</version>
|
||||
<version>02.26.00-beta</version>
|
||||
<creationDate>2026-05-30</creationDate>
|
||||
<infourl title="MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/beta</infourl>
|
||||
<infourl title="Package - MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/beta</infourl>
|
||||
<downloads>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/beta/pkg_mokowaas-02.22.00-beta.zip</downloadurl>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/beta/pkg_mokowaas-02.26.00-beta.zip</downloadurl>
|
||||
</downloads>
|
||||
<sha256>d8dd0870f27b39d01e4c3057afd27c882aa277b601d9c134f69fe4cba1d2b57c</sha256>
|
||||
<sha256>22f4def98469d371d673cde0c740a9b54a5e71d2eeb15c4506aed159541daae8</sha256>
|
||||
<tags><tag>beta</tag></tags>
|
||||
<changelogurl>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/CHANGELOG.md</changelogurl>
|
||||
<maintainer>Moko Consulting</maintainer>
|
||||
@@ -63,41 +82,22 @@
|
||||
<targetplatform name="joomla" version="(5|6)\..*"/>
|
||||
</update>
|
||||
<update>
|
||||
<name>MokoWaaS</name>
|
||||
<description>MokoWaaS rc build.</description>
|
||||
<name>Package - MokoWaaS</name>
|
||||
<description>Package - MokoWaaS rc build.</description>
|
||||
<element>pkg_mokowaas</element>
|
||||
<type>package</type>
|
||||
<client>site</client>
|
||||
<version>02.22.00-rc</version>
|
||||
<version>02.26.00-rc</version>
|
||||
<creationDate>2026-05-30</creationDate>
|
||||
<infourl title="MokoWaaS">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/release-candidate</infourl>
|
||||
<infourl title='Package - MokoWaaS'>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/release-candidate</infourl>
|
||||
<downloads>
|
||||
<downloadurl type="full" format="zip">https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/release-candidate/pkg_mokowaas-02.22.00-rc.zip</downloadurl>
|
||||
<downloadurl type='full' format='zip'>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/release-candidate/pkg_mokowaas-02.26.00-rc.zip</downloadurl>
|
||||
</downloads>
|
||||
<sha256>d8dd0870f27b39d01e4c3057afd27c882aa277b601d9c134f69fe4cba1d2b57c</sha256>
|
||||
<sha256>22f4def98469d371d673cde0c740a9b54a5e71d2eeb15c4506aed159541daae8</sha256>
|
||||
<tags><tag>rc</tag></tags>
|
||||
<changelogurl>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/CHANGELOG.md</changelogurl>
|
||||
<maintainer>Moko Consulting</maintainer>
|
||||
<maintainerurl>https://mokoconsulting.tech</maintainerurl>
|
||||
<targetplatform name="joomla" version="(5|6)\..*"/>
|
||||
</update>
|
||||
<update>
|
||||
<name>MokoWaaS</name>
|
||||
<description>MokoWaaS stable build.</description>
|
||||
<element>pkg_mokowaas</element>
|
||||
<type>package</type>
|
||||
<client>site</client>
|
||||
<version>02.22.00</version>
|
||||
<creationDate>2026-05-30</creationDate>
|
||||
<infourl title='MokoWaaS'>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/tag/stable</infourl>
|
||||
<downloads>
|
||||
<downloadurl type='full' format='zip'>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/releases/download/stable/pkg_mokowaas-02.22.00.zip</downloadurl>
|
||||
</downloads>
|
||||
<sha256>d8dd0870f27b39d01e4c3057afd27c882aa277b601d9c134f69fe4cba1d2b57c</sha256>
|
||||
<tags><tag>stable</tag></tags>
|
||||
<changelogurl>https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/raw/branch/main/CHANGELOG.md</changelogurl>
|
||||
<maintainer>Moko Consulting</maintainer>
|
||||
<maintainerurl>https://mokoconsulting.tech</maintainerurl>
|
||||
<targetplatform name="joomla" version="(5|6)\..*" />
|
||||
</update>
|
||||
</updates>
|
||||
|
||||
@@ -180,6 +180,9 @@ In addition to the query-string endpoints above, MokoWaaS registers standard Joo
|
||||
| `POST /api/v1/mokowaas/install` | InstallController | Install extension from ZIP URL |
|
||||
| `POST /api/v1/mokowaas/reset` | ResetController | Restore site to baseline snapshot |
|
||||
| `GET/POST /api/v1/mokowaas/snapshot` | SnapshotController | List or create snapshots |
|
||||
| `POST /api/v1/mokowaas/sync` | SyncController | Push content to all sync targets |
|
||||
| `POST /api/v1/mokowaas/sync-receive` | SyncReceiveController | Receive content from source site |
|
||||
| `GET /api/v1/mokowaas/extensions` | ExtensionsController | List installed extensions |
|
||||
|
||||
These routes use Joomla's standard API authentication (API token in `X-Joomla-Token` header) and are useful for integrations that already use the Joomla API framework.
|
||||
|
||||
@@ -282,3 +285,53 @@ The `name` field is optional and defaults to the active baseline name.
|
||||
"has_media": true
|
||||
}
|
||||
```
|
||||
|
||||
### Extensions Endpoint (REST API)
|
||||
|
||||
```
|
||||
GET /api/index.php/v1/mokowaas/extensions
|
||||
X-Joomla-Token: <api-token>
|
||||
```
|
||||
|
||||
Lists all installed Joomla extensions with version, enabled/protected/locked status, and update server info.
|
||||
|
||||
**Query filters:**
|
||||
|
||||
| Parameter | Description | Example |
|
||||
|---|---|---|
|
||||
| `type` | Filter by extension type | `?type=plugin` |
|
||||
| `search` | Search name or element | `?search=moko` |
|
||||
| `enabled` | Filter by enabled status | `?enabled=1` |
|
||||
|
||||
**Query-string equivalent:** `GET /?mokowaas=extensions&search=moko&type=plugin`
|
||||
|
||||
Requires `core.manage` on `com_installer`.
|
||||
|
||||
**Success Response** (HTTP 200):
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"count": 3,
|
||||
"extensions": [
|
||||
{
|
||||
"extension_id": 456,
|
||||
"name": "System - MokoWaaS",
|
||||
"type": "plugin",
|
||||
"element": "mokowaas",
|
||||
"folder": "system",
|
||||
"client_id": 0,
|
||||
"enabled": true,
|
||||
"protected": true,
|
||||
"locked": false,
|
||||
"version": "02.21.00",
|
||||
"author": "Moko Consulting",
|
||||
"update_server": {
|
||||
"name": "MokoWaaS Update Server",
|
||||
"location": "https://git.mokoconsulting.tech/.../updates.xml",
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user