4b9a675d0f
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Generic: Project CI / Lint & Validate (push) Successful in 36s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 40s
Generic: Project CI / Tests (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
All Joomla element names, PHP classes, language files, folder structure, and manifest references renamed from mokosuite to mokosuiteclient. This repo is now the client-facing tracker for the MokoSuite platform.
152 lines
3.5 KiB
PHP
152 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* @package MokoSuiteClient
|
|
* @subpackage com_mokosuiteclient
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
|
* @license GNU General Public License version 3 or later; see LICENSE
|
|
*/
|
|
|
|
namespace Moko\Component\MokoSuiteClient\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;
|
|
|
|
/**
|
|
* Snapshot management API controller.
|
|
*
|
|
* GET /api/index.php/v1/mokosuiteclient/snapshot — list snapshots
|
|
* POST /api/index.php/v1/mokosuiteclient/snapshot — create snapshot
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
class SnapshotController extends BaseController
|
|
{
|
|
/**
|
|
* List all available snapshots.
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
public function displayList(): void
|
|
{
|
|
$app = Factory::getApplication();
|
|
$user = $app->getIdentity();
|
|
|
|
if (!$user->authorise('core.manage', 'com_plugins'))
|
|
{
|
|
$this->sendJson(403, ['error' => 'Not authorized']);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
$service = $this->createService();
|
|
|
|
$this->sendJson(200, [
|
|
'status' => 'ok',
|
|
'snapshots' => $service->listSnapshots(),
|
|
]);
|
|
}
|
|
catch (\Throwable $e)
|
|
{
|
|
$this->sendJson(500, [
|
|
'error' => 'Failed to list snapshots',
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create a new snapshot.
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
public function execute($task = 'snapshot'): 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
|
|
{
|
|
$plugin = PluginHelper::getPlugin('system', 'mokosuiteclient');
|
|
$params = $plugin ? new Registry($plugin->params) : new Registry;
|
|
|
|
$body = json_decode($app->input->json->getRaw(), true);
|
|
$name = $body['name']
|
|
?? $params->get('demo_active_baseline', 'default');
|
|
|
|
$service = $this->createService();
|
|
$result = $service->createSnapshot($name);
|
|
|
|
$this->sendJson(200, $result);
|
|
}
|
|
catch (\Throwable $e)
|
|
{
|
|
$this->sendJson(500, [
|
|
'error' => 'Snapshot failed',
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create DemoResetService from plugin params.
|
|
*
|
|
* @return \Moko\Plugin\System\MokoSuiteClient\Service\DemoResetService
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
private function createService()
|
|
{
|
|
$serviceFile = JPATH_PLUGINS . '/task/mokosuiteclientdemo/src/Service/DemoResetService.php';
|
|
|
|
if (!file_exists($serviceFile))
|
|
{
|
|
throw new \RuntimeException('DemoResetService not found — is the demo reset plugin installed?');
|
|
}
|
|
|
|
require_once $serviceFile;
|
|
|
|
$plugin = PluginHelper::getPlugin('system', 'mokosuiteclient');
|
|
$params = $plugin ? new Registry($plugin->params) : new Registry;
|
|
|
|
$media = (bool) $params->get('demo_snapshot_include_media', 1);
|
|
|
|
return new \Moko\Plugin\Task\MokoSuiteClientDemo\Service\DemoResetService($media);
|
|
}
|
|
|
|
/**
|
|
* @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();
|
|
}
|
|
}
|