From b1bc264314416cbd8ec7460f1eba0d456b50ce19 Mon Sep 17 00:00:00 2001 From: Jonathan Miller <230051081+jmiller-moko@users.noreply.github.com> Date: Tue, 7 Apr 2026 16:28:08 -0500 Subject: [PATCH] feat: resolve mokocassiopeia download URL from updates.xml Instead of hardcoding the zip URL, fetches MokoCassiopeia's updates.xml from the repo main branch and parses the downloadurl. This way the download location is controlled by the MokoCassiopeia repo. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/script.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/src/script.php b/src/script.php index 91cec48d..8666e90b 100644 --- a/src/script.php +++ b/src/script.php @@ -251,9 +251,22 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface return; } - // Template not installed — try to install from GitHub - $zipUrl = 'https://github.com/mokoconsulting-tech/MokoCassiopeia' - . '/releases/latest/download/MokoCassiopeia.zip'; + // Template not installed — get download URL from updates.xml + $updatesUrl = 'https://raw.githubusercontent.com' + . '/mokoconsulting-tech/MokoCassiopeia/main/updates.xml'; + + $zipUrl = $this->getDownloadUrlFromUpdates($updatesUrl); + + if (empty($zipUrl)) + { + Factory::getApplication()->enqueueMessage( + 'MokoCassiopeia: could not resolve download URL.', + 'warning' + ); + + return; + } + $tmpFile = JPATH_ROOT . '/tmp/mokocassiopeia.zip'; $tmpDir = JPATH_ROOT . '/tmp/mokocassiopeia'; @@ -366,6 +379,41 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface $db->execute(); } + /** + * Parse an updates.xml and return the download URL. + * + * @param string $updatesUrl URL to the updates.xml file + * + * @return string|null Download URL or null on failure + * + * @since 02.01.01 + */ + private function getDownloadUrlFromUpdates($updatesUrl) + { + try + { + $xml = @file_get_contents($updatesUrl); + + if ($xml === false) + { + return null; + } + + $updates = new \SimpleXMLElement($xml); + + if (isset($updates->update->downloads->downloadurl)) + { + return (string) $updates->update->downloads->downloadurl; + } + } + catch (\Exception $e) + { + return null; + } + + return null; + } + private const BLOCK_START = '; ===== BEGIN MokoWaaS Overrides (do not edit this block) ====='; /** Sentinel comment that marks the end of MokoWaaS overrides inside a Joomla override file. */