d94909eb91
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
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Universal: Auto Version Bump / Version Bump (push) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (push) Has been cancelled
DemoResetService, ContentSyncService, and ContentSyncReceiver were deleted from the core plugin but still referenced by the demo task plugin and API controllers. Moved service classes into their owning packages with updated namespaces: - DemoResetService → plg_task_mokowaasdemo/src/Service/ - ContentSyncService → plg_task_mokowaassync/src/Service/ - ContentSyncReceiver → plg_task_mokowaassync/src/Service/ Updated all require_once paths and FQCN references in API controllers and DemoReset task plugin. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
121 lines
2.8 KiB
PHP
121 lines
2.8 KiB
PHP
<?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;
|
|
|
|
/**
|
|
* Demo site reset API controller.
|
|
*
|
|
* POST /api/index.php/v1/mokowaas/reset
|
|
* Body: {"baseline": "default"}
|
|
*
|
|
* Restores the site to a named baseline snapshot.
|
|
* Requires a Joomla API token with core.manage on com_plugins.
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
class ResetController extends BaseController
|
|
{
|
|
/**
|
|
* Restore site to a baseline snapshot.
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
public function execute($task = 'reset'): 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;
|
|
}
|
|
|
|
$params = new Registry($plugin->params);
|
|
|
|
try
|
|
{
|
|
$service = $this->createService($params);
|
|
$result = $service->restoreSnapshot('default');
|
|
|
|
$this->sendJson(200, $result);
|
|
}
|
|
catch (\Throwable $e)
|
|
{
|
|
$this->sendJson(500, [
|
|
'error' => 'Reset failed',
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create DemoResetService from plugin params.
|
|
*
|
|
* @param Registry $params Plugin parameters
|
|
*
|
|
* @return \Moko\Plugin\System\MokoWaaS\Service\DemoResetService
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
private function createService(Registry $params)
|
|
{
|
|
$serviceFile = JPATH_PLUGINS . '/task/mokowaasdemo/src/Service/DemoResetService.php';
|
|
|
|
if (!file_exists($serviceFile))
|
|
{
|
|
throw new \RuntimeException('DemoResetService not found — is the demo reset plugin installed?');
|
|
}
|
|
|
|
require_once $serviceFile;
|
|
|
|
$media = (bool) $params->get('demo_snapshot_include_media', 1);
|
|
|
|
return new \Moko\Plugin\Task\MokoWaaSDemo\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();
|
|
}
|
|
}
|