From 01c0bb8a32b76ce8c7d96f9a570f4d3c54e3d9c1 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 6 Jun 2026 15:47:38 -0500 Subject: [PATCH] fix: restore download keys by element name, not just URL/ID The URL migration in postflight changes update site URLs BEFORE restoreDownloadKeys runs, so URL-based matching fails. Element names are stable across updates. Now backs up keys as elem_ELEMENT and restores by matching the extension element name first, falling back to URL and ID. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- source/script.php | 49 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/source/script.php b/source/script.php index b0b8d88a..6d581090 100644 --- a/source/script.php +++ b/source/script.php @@ -680,16 +680,27 @@ class Pkg_MokowaasInstallerScript try { $db = Factory::getDbo(); + + // Get ALL download keys with their element names (stable identifier) $db->setQuery( $db->getQuery(true) - ->select([$db->quoteName('update_site_id'), $db->quoteName('extra_query'), $db->quoteName('location')]) - ->from($db->quoteName('#__update_sites')) - ->where($db->quoteName('extra_query') . ' != ' . $db->quote('')) + ->select([ + 'us.' . $db->quoteName('update_site_id'), + 'us.' . $db->quoteName('extra_query'), + 'us.' . $db->quoteName('location'), + 'e.' . $db->quoteName('element'), + ]) + ->from($db->quoteName('#__update_sites', 'us')) + ->join('INNER', $db->quoteName('#__update_sites_extensions', 'use') . ' ON us.update_site_id = use.update_site_id') + ->join('INNER', $db->quoteName('#__extensions', 'e') . ' ON e.extension_id = use.extension_id') + ->where($db->quoteName('us.extra_query') . ' != ' . $db->quote('')) ); $rows = $db->loadObjectList() ?: []; foreach ($rows as $row) { + // Key by element name (stable), URL, and ID (fallbacks) + $keys['elem_' . $row->element] = $row->extra_query; $keys[$row->location] = $row->extra_query; $keys['id_' . $row->update_site_id] = $row->extra_query; } @@ -868,11 +879,21 @@ class Pkg_MokowaasInstallerScript try { $db = Factory::getDbo(); + + // Get update sites with empty extra_query AND their element names $db->setQuery( $db->getQuery(true) - ->select([$db->quoteName('update_site_id'), $db->quoteName('extra_query'), $db->quoteName('location')]) - ->from($db->quoteName('#__update_sites')) - ->where($db->quoteName('extra_query') . ' = ' . $db->quote('')) + ->select([ + 'us.' . $db->quoteName('update_site_id'), + 'us.' . $db->quoteName('extra_query'), + 'us.' . $db->quoteName('location'), + 'e.' . $db->quoteName('element'), + ]) + ->from($db->quoteName('#__update_sites', 'us')) + ->join('LEFT', $db->quoteName('#__update_sites_extensions', 'use') . ' ON us.update_site_id = use.update_site_id') + ->join('LEFT', $db->quoteName('#__extensions', 'e') . ' ON e.extension_id = use.extension_id') + ->where('(' . $db->quoteName('us.extra_query') . ' = ' . $db->quote('') + . ' OR ' . $db->quoteName('us.extra_query') . ' NOT LIKE ' . $db->quote('%dlid=%') . ')') ); $sites = $db->loadObjectList() ?: []; @@ -880,8 +901,20 @@ class Pkg_MokowaasInstallerScript foreach ($sites as $site) { - // Try to match by location URL first, then by old ID - $key = $savedKeys[$site->location] ?? $savedKeys['id_' . $site->update_site_id] ?? ''; + $element = (string) ($site->element ?? ''); + + // Match by element name first (stable), then URL, then old ID + $key = ''; + + if ($element !== '') + { + $key = $savedKeys['elem_' . $element] ?? ''; + } + + if (empty($key)) + { + $key = $savedKeys[$site->location] ?? $savedKeys['id_' . $site->update_site_id] ?? ''; + } if (!empty($key)) {