From 5ab496b399d42ade5168755913db406f08827a0e Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 6 Jun 2026 15:13:43 -0500 Subject: [PATCH] fix: backup download keys in preflight, not postflight Joomla's package installer deletes and recreates update site rows from the manifest BETWEEN preflight and postflight. By the time postflight ran backupDownloadKeys(), the extra_query values were already empty. Moved the backup to preflight() via a class property. The restore in postflight() now uses keys saved before Joomla touched them. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- source/script.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/source/script.php b/source/script.php index 241c05d3..b56a8491 100644 --- a/source/script.php +++ b/source/script.php @@ -39,8 +39,16 @@ class Pkg_MokowaasInstallerScript * with no default, causing INSERT failures when Joomla's package installer * creates placeholder rows before processing sub-extension manifests. */ + /** @var array Download keys saved before Joomla wipes update sites */ + private array $savedDownloadKeys = []; + public function preflight($type, $parent) { + // CRITICAL: backup download keys BEFORE Joomla's installer wipes update sites. + // Joomla deletes and recreates #__update_sites rows from the manifest + // between preflight and postflight, clearing extra_query (dlid). + $this->savedDownloadKeys = $this->backupDownloadKeys(); + try { $db = Factory::getDbo(); @@ -95,17 +103,14 @@ class Pkg_MokowaasInstallerScript // Mark MokoWaaS extensions as protected (prevents disable/uninstall at framework level) $this->protectExtensions(); - // Save download keys before any update site manipulation - $savedKeys = $this->backupDownloadKeys(); - // Migrate all Moko update server URLs to new format $this->migrateUpdateServerUrls(); // Clean up stale/duplicate update sites $this->cleanupStaleUpdateSites(); - // Restore download keys that were wiped by cleanup/migration - $this->restoreDownloadKeys($savedKeys); + // Restore download keys saved in preflight (before Joomla wiped them) + $this->restoreDownloadKeys($this->savedDownloadKeys); // Fix orphaned update records (extension_id=0) $this->fixUpdateRecords();