refactor: remove all file sync — API-based DB content only

Removed images/, files/, media/ sync and related infrastructure
(syncDirectory, getHealthToken). Sync is now purely Joomla REST API:
articles, categories, menus, modules.

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-05-31 14:13:11 -05:00
parent dc1508520f
commit b89ea25b20
2 changed files with 0 additions and 146 deletions
@@ -43,13 +43,6 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="sync_images" type="radio" default="1"
label="Sync Images (/images/)"
description="Sync the /images/ directory to the target site."
class="btn-group btn-group-yesno">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>
</fields>
</form>
@@ -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 '';
}
}
}