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) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-06-06 15:47:38 -05:00
parent 2656db9579
commit 01c0bb8a32
+41 -8
View File
@@ -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))
{