refactor: remove database-backed download key table
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
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
The #__mokowaas_download_keys table approach was over-engineered. Download key preservation is handled by the install script's preflight/postflight with element-name matching. Removed: - #__mokowaas_download_keys table from install SQL - syncKeysToTable/applyKeysFromTable from core plugin - saveDownloadKey/applyDownloadKey/reapplyAllDownloadKeys from model - ensureDownloadKeysTable/syncKeysToDatabase/reapplyKeysFromDatabase from install script Added: - Migration SQL (02.35.00) to DROP the table from existing installs - Uninstall SQL for all component tables - Install/uninstall SQL blocks in component manifest Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+1
-182
@@ -109,12 +109,8 @@ 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
|
||||
// Restore download keys saved in preflight (before Joomla wiped them)
|
||||
$this->restoreDownloadKeys($this->savedDownloadKeys);
|
||||
$this->reapplyKeysFromDatabase();
|
||||
|
||||
// Fix orphaned update records (extension_id=0)
|
||||
$this->fixUpdateRecords();
|
||||
@@ -676,33 +672,6 @@ 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 = [];
|
||||
@@ -735,8 +704,6 @@ class Pkg_MokowaasInstallerScript
|
||||
$keys['id_' . $row->update_site_id] = $row->extra_query;
|
||||
}
|
||||
|
||||
// Also save to our persistent database table
|
||||
$this->syncKeysToDatabase($db, $rows);
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
@@ -746,154 +713,6 @@ class Pkg_MokowaasInstallerScript
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync current download keys to the persistent #__mokowaas_download_keys table.
|
||||
*/
|
||||
private function syncKeysToDatabase($db, array $rows): void
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check if table exists
|
||||
$tables = $db->getTableList();
|
||||
$prefix = $db->getPrefix();
|
||||
|
||||
if (!\in_array($prefix . 'mokowaas_download_keys', $tables, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$now = gmdate('Y-m-d H:i:s');
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
parse_str($row->extra_query, $parsed);
|
||||
$dlid = $parsed['dlid'] ?? '';
|
||||
|
||||
if (empty($dlid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find the element for this update site
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select('e.' . $db->quoteName('element'))
|
||||
->from($db->quoteName('#__update_sites_extensions', 'use'))
|
||||
->join('INNER', $db->quoteName('#__extensions', 'e') . ' ON e.extension_id = use.extension_id')
|
||||
->where($db->quoteName('use.update_site_id') . ' = ' . (int) $row->update_site_id),
|
||||
0, 1
|
||||
);
|
||||
$element = (string) $db->loadResult();
|
||||
|
||||
if (empty($element))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Upsert
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select('COUNT(*)')
|
||||
->from($db->quoteName('#__mokowaas_download_keys'))
|
||||
->where($db->quoteName('element') . ' = ' . $db->quote($element))
|
||||
);
|
||||
|
||||
if ((int) $db->loadResult() > 0)
|
||||
{
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->update($db->quoteName('#__mokowaas_download_keys'))
|
||||
->set($db->quoteName('dlid') . ' = ' . $db->quote($dlid))
|
||||
->set($db->quoteName('location') . ' = ' . $db->quote($row->location))
|
||||
->set($db->quoteName('modified') . ' = ' . $db->quote($now))
|
||||
->where($db->quoteName('element') . ' = ' . $db->quote($element))
|
||||
)->execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->insert($db->quoteName('#__mokowaas_download_keys'))
|
||||
->columns([$db->quoteName('element'), $db->quoteName('location'), $db->quoteName('dlid'), $db->quoteName('created'), $db->quoteName('modified')])
|
||||
->values(implode(',', [
|
||||
$db->quote($element), $db->quote($row->location), $db->quote($dlid), $db->quote($now), $db->quote($now),
|
||||
]))
|
||||
)->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
// Non-critical — table may not exist yet
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-apply all download keys from our persistent database table.
|
||||
*/
|
||||
private function reapplyKeysFromDatabase(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$tables = $db->getTableList();
|
||||
$prefix = $db->getPrefix();
|
||||
|
||||
if (!\in_array($prefix . 'mokowaas_download_keys', $tables, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select('*')
|
||||
->from($db->quoteName('#__mokowaas_download_keys'))
|
||||
->where($db->quoteName('dlid') . ' != ' . $db->quote(''))
|
||||
);
|
||||
$keys = $db->loadObjectList() ?: [];
|
||||
|
||||
$restored = 0;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select('us.' . $db->quoteName('update_site_id'))
|
||||
->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('e.element') . ' = ' . $db->quote($key->element))
|
||||
->where('(' . $db->quoteName('us.extra_query') . ' = ' . $db->quote('')
|
||||
. ' OR ' . $db->quoteName('us.extra_query') . ' NOT LIKE ' . $db->quote('%dlid=%') . ')')
|
||||
);
|
||||
$siteIds = $db->loadColumn() ?: [];
|
||||
|
||||
foreach ($siteIds as $siteId)
|
||||
{
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->update($db->quoteName('#__update_sites'))
|
||||
->set($db->quoteName('extra_query') . ' = ' . $db->quote('dlid=' . $key->dlid))
|
||||
->where($db->quoteName('update_site_id') . ' = ' . (int) $siteId)
|
||||
)->execute();
|
||||
$restored++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($restored > 0)
|
||||
{
|
||||
Factory::getApplication()->enqueueMessage(
|
||||
sprintf('Re-applied %d download key(s) from persistent storage.', $restored),
|
||||
'message'
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
// Non-critical
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore download keys that were cleared by update site cleanup.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user