fix: create download_keys table on update + element-based key matching
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Universal: Auto Version Bump / Version Bump (push) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (push) Has been cancelled

Root cause: the #__mokowaas_download_keys table was only in
install.mysql.sql (fresh installs). Existing sites never got it,
so syncKeysToTable/applyKeysFromTable silently failed.

- Add sql/updates/mysql/02.35.00.sql migration for existing installs
- Register <update><schemas> in component manifest
- Add ensureDownloadKeysTable() as belt-and-suspenders in postflight
- backupDownloadKeys() now saves by element name (stable identifier)
- restoreDownloadKeys() matches by element first, URL second, ID third

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:53:42 -05:00
parent 99398fde6b
commit 104251f800
3 changed files with 47 additions and 0 deletions
+30
View File
@@ -109,6 +109,9 @@ class Pkg_MokowaasInstallerScript
// Clean up stale/duplicate update sites
$this->cleanupStaleUpdateSites();
// Ensure download keys table exists (belt-and-suspenders with schema update)
$this->ensureDownloadKeysTable();
// Restore download keys: first from preflight backup, then from DB table
$this->restoreDownloadKeys($this->savedDownloadKeys);
$this->reapplyKeysFromDatabase();
@@ -673,6 +676,33 @@ class Pkg_MokowaasInstallerScript
*
* @return array Map of update_site_id => extra_query
*/
/**
* Ensure the download keys table exists.
*/
private function ensureDownloadKeysTable(): void
{
try
{
$db = Factory::getDbo();
$db->setQuery("CREATE TABLE IF NOT EXISTS `#__mokowaas_download_keys` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`element` VARCHAR(100) NOT NULL DEFAULT '',
`location` VARCHAR(512) NOT NULL DEFAULT '',
`dlid` VARCHAR(255) NOT NULL DEFAULT '',
`created` DATETIME NOT NULL,
`modified` DATETIME NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_dlkey_element` (`element`),
KEY `idx_dlkey_location` (`location`(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
$db->execute();
}
catch (\Throwable $e)
{
// Non-critical
}
}
private function backupDownloadKeys(): array
{
$keys = [];