diff --git a/src/packages/plg_task_mokowaassync/forms/sync_params.xml b/src/packages/plg_task_mokowaassync/forms/sync_params.xml index f0af5f54..77de59f8 100644 --- a/src/packages/plg_task_mokowaassync/forms/sync_params.xml +++ b/src/packages/plg_task_mokowaassync/forms/sync_params.xml @@ -43,13 +43,6 @@ - - - - diff --git a/src/packages/plg_task_mokowaassync/src/Extension/ContentSync.php b/src/packages/plg_task_mokowaassync/src/Extension/ContentSync.php index f7e06a19..4e411466 100644 --- a/src/packages/plg_task_mokowaassync/src/Extension/ContentSync.php +++ b/src/packages/plg_task_mokowaassync/src/Extension/ContentSync.php @@ -108,19 +108,6 @@ final class ContentSync extends CMSPlugin implements SubscriberInterface if (!$result) $errors++; } - // File sync via MokoWaaS endpoint - $healthToken = $this->getHealthToken(); - - if ((int) ($params->sync_images ?? 0) === 1) - { - $result = $this->syncDirectory('images', $targetUrl, $healthToken); - $synced[] = 'images:' . ($result ? 'ok' : 'fail'); - if (!$result) $errors++; - } - - // Files sync removed — /files/ not standard in Joomla - - // Media sync removed — /media/ is too large and contains extension assets $summary = implode(', ', $synced); @@ -400,99 +387,6 @@ final class ContentSync extends CMSPlugin implements SubscriberInterface } } - // ------------------------------------------------------------------ - // File sync via MokoWaaS endpoint - // ------------------------------------------------------------------ - - /** - * Sync a directory to the target site via the MokoWaaS sync-receive endpoint. - * - * @param string $dir Directory name (images, files, media) - * @param string $targetUrl Target site base URL - * @param string $token MokoWaaS health token for auth - * - * @return bool - * - * @since 02.31.00 - */ - private function syncDirectory(string $dir, string $targetUrl, string $token): bool - { - try - { - $sourcePath = JPATH_ROOT . '/' . $dir; - - if (!is_dir($sourcePath)) - { - $this->logTask("Directory /{$dir}/ does not exist — skipping"); - - return true; - } - - // Collect files - $files = []; - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($sourcePath, \RecursiveDirectoryIterator::SKIP_DOTS), - \RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($iterator as $file) - { - if ($file->isFile()) - { - $relativePath = str_replace('\\', '/', substr($file->getPathname(), strlen($sourcePath) + 1)); - $files[] = [ - 'path' => $dir . '/' . $relativePath, - 'content' => base64_encode(file_get_contents($file->getPathname())), - ]; - } - } - - if (empty($files)) - { - return true; - } - - // Send in batches of 50 files - $batches = array_chunk($files, 50); - - foreach ($batches as $batch) - { - $payload = json_encode([ - 'token' => $token, - 'files' => $batch, - ]); - - $ch = curl_init($targetUrl . '/?mokowaas=syncreceive'); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); - curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 120); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - $response = curl_exec($ch); - $httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - - if ($httpCode < 200 || $httpCode >= 300) - { - $this->logTask("File sync batch failed for /{$dir}/: HTTP {$httpCode}"); - - return false; - } - } - - $this->logTask(sprintf('Synced %d files from /%s/', count($files), $dir)); - - return true; - } - catch (\Throwable $e) - { - $this->logTask("File sync failed for /{$dir}/: " . $e->getMessage()); - - return false; - } - } - // ------------------------------------------------------------------ // HTTP helpers // ------------------------------------------------------------------ @@ -593,37 +487,4 @@ final class ContentSync extends CMSPlugin implements SubscriberInterface return $httpCode >= 200 && $httpCode < 300; } - // ------------------------------------------------------------------ - // Helpers - // ------------------------------------------------------------------ - - /** - * Read the MokoWaaS health API token from the system plugin params. - * - * @return string - * - * @since 02.31.00 - */ - private function getHealthToken(): string - { - try - { - $db = Factory::getDbo(); - $query = $db->getQuery(true) - ->select($db->quoteName('params')) - ->from($db->quoteName('#__extensions')) - ->where($db->quoteName('type') . ' = ' . $db->quote('plugin')) - ->where($db->quoteName('folder') . ' = ' . $db->quote('system')) - ->where($db->quoteName('element') . ' = ' . $db->quote('mokowaas')); - $db->setQuery($query); - $raw = $db->loadResult(); - $params = json_decode($raw ?: '{}', true); - - return $params['health_api_token'] ?? ''; - } - catch (\Throwable $e) - { - return ''; - } - } }