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