00d44256b4
Rebrand all 17 sub-extensions from mokowaas to mokosuite naming, including component, plugins, modules, task plugins, and webservices. Updates package manifest, workflows, docs, wiki, and issue templates. Adds new plg_system_mokosuite_license extension.
83 lines
2.0 KiB
PHP
83 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* @package MokoSuite
|
|
* @subpackage com_mokosuite
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
|
* @license GNU General Public License version 3 or later; see LICENSE
|
|
*/
|
|
|
|
namespace Moko\Component\MokoSuite\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/mokosuite/sync
|
|
*
|
|
* Pushes content to all configured sync targets.
|
|
*
|
|
* @since 02.21.00
|
|
*/
|
|
class SyncController extends BaseController
|
|
{
|
|
public function execute($task = 'sync'): 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', 'mokosuite');
|
|
|
|
if (!$plugin)
|
|
{
|
|
$this->sendJson(503, ['error' => 'MokoSuite system plugin not enabled']);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
$params = new Registry($plugin->params);
|
|
$targets = json_decode($params->get('sync_targets', '[]'), true) ?: [];
|
|
|
|
$serviceFile = JPATH_PLUGINS . '/task/mokosuitesync/src/Service/ContentSyncService.php';
|
|
require_once $serviceFile;
|
|
|
|
$service = new \Moko\Plugin\Task\MokoSuiteSync\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();
|
|
}
|
|
}
|