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(); } }