From 9b693abe7d5e99414169447bae1fa75e2e0823a7 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 6 Jun 2026 16:46:36 -0500 Subject: [PATCH] feat: download key preservation in preflight + update site notice --- source/script.php | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/source/script.php b/source/script.php index cb7d5e98..fd9547b4 100644 --- a/source/script.php +++ b/source/script.php @@ -42,6 +42,10 @@ class Pkg_MokoJoomCrossInstallerScript return false; } + if ($type === 'update') { + $this->saveDownloadKey(); + } + return true; } @@ -55,6 +59,11 @@ class Pkg_MokoJoomCrossInstallerScript */ public function postflight(string $type, InstallerAdapter $parent): void { + if ($this->savedDownloadKey !== null) { + $this->restoreDownloadKey(); + } + $this->showUpdateSiteNotice(); + $db = Factory::getDbo(); if ($type === 'install') { @@ -100,6 +109,65 @@ class Pkg_MokoJoomCrossInstallerScript * * @return void */ + private ?string $savedDownloadKey = null; + + private function saveDownloadKey(): void + { + try { + $db = Factory::getDbo(); + $db->setQuery( + $db->getQuery(true) + ->select($db->quoteName('us.extra_query')) + ->from($db->quoteName('#__update_sites', 'us')) + ->join('INNER', $db->quoteName('#__update_sites_extensions', 'use') . ' ON use.update_site_id = us.update_site_id') + ->join('INNER', $db->quoteName('#__extensions', 'e') . ' ON e.extension_id = use.extension_id') + ->where($db->quoteName('e.element') . ' = ' . $db->quote('pkg_mokojoomcross')) + ->setLimit(1) + ); + $key = $db->loadResult(); + if (!empty($key)) { $this->savedDownloadKey = $key; } + } catch (\Throwable $e) {} + } + + private function restoreDownloadKey(): void + { + try { + $db = Factory::getDbo(); + $db->setQuery( + $db->getQuery(true) + ->select($db->quoteName('us.update_site_id')) + ->from($db->quoteName('#__update_sites', 'us')) + ->join('INNER', $db->quoteName('#__update_sites_extensions', 'use') . ' ON use.update_site_id = us.update_site_id') + ->join('INNER', $db->quoteName('#__extensions', 'e') . ' ON e.extension_id = use.extension_id') + ->where($db->quoteName('e.element') . ' = ' . $db->quote('pkg_mokojoomcross')) + ->setLimit(1) + ); + $siteId = (int) $db->loadResult(); + if ($siteId > 0) { + $db->setQuery($db->getQuery(true)->update($db->quoteName('#__update_sites'))->set($db->quoteName('extra_query') . ' = ' . $db->quote($this->savedDownloadKey))->where($db->quoteName('update_site_id') . ' = ' . $siteId))->execute(); + } + } catch (\Throwable $e) {} + } + + private function showUpdateSiteNotice(): void + { + try { + $db = Factory::getDbo(); + $db->setQuery( + $db->getQuery(true) + ->select($db->quoteName('us.update_site_id')) + ->from($db->quoteName('#__update_sites', 'us')) + ->join('INNER', $db->quoteName('#__update_sites_extensions', 'use') . ' ON use.update_site_id = us.update_site_id') + ->join('INNER', $db->quoteName('#__extensions', 'e') . ' ON e.extension_id = use.extension_id') + ->where($db->quoteName('e.element') . ' = ' . $db->quote('pkg_mokojoomcross')) + ->setLimit(1) + ); + if ((int) $db->loadResult() > 0) { + Factory::getApplication()->enqueueMessage('To receive automatic updates, configure your download key in System > Update Sites.', 'info'); + } + } catch (\Throwable $e) {} + } + private function detectPerfectPublisherPro($db): void { $query = $db->getQuery(true)