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.
78 lines
2.0 KiB
PHP
78 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;
|
|
|
|
/**
|
|
* Content sync receiver API controller (target side).
|
|
*
|
|
* POST /api/index.php/v1/mokosuite/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($task = 'syncReceive'): 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['mokosuite_sync']))
|
|
{
|
|
$this->sendJson(400, ['error' => 'Invalid payload — missing mokosuite_sync version']);
|
|
return;
|
|
}
|
|
|
|
$serviceFile = JPATH_PLUGINS . '/task/mokosuitesync/src/Service/ContentSyncReceiver.php';
|
|
require_once $serviceFile;
|
|
|
|
$receiver = new \Moko\Plugin\Task\MokoSuiteSync\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();
|
|
}
|
|
}
|