diff --git a/src/script.php b/src/script.php
index 2d8a903..06a66e8 100644
--- a/src/script.php
+++ b/src/script.php
@@ -17,8 +17,8 @@ class Pkg_MokojoomstorelocatorInstallerScript
protected $minimumPhp = '8.1';
protected $minimumJoomla = '4.4.0';
- /** @var array Download keys saved before Joomla wipes update sites */
- private array $savedDownloadKeys = [];
+
+
public function preflight($type, $parent)
{
@@ -36,14 +36,14 @@ class Pkg_MokojoomstorelocatorInstallerScript
return false;
}
- $this->savedDownloadKeys = $this->backupDownloadKeys();
+ $this->saveDownloadKey();
return true;
}
public function postflight($type, $parent)
{
- $this->restoreDownloadKeys($this->savedDownloadKeys);
+ $this->restoreDownloadKey();
$this->warnMissingLicenseKey();
return true;
@@ -53,66 +53,56 @@ class Pkg_MokojoomstorelocatorInstallerScript
{
}
- private function backupDownloadKeys(): array
- {
- $keys = [];
+
+ private ?string $savedDownloadKey = null;
+
+ private function saveDownloadKey(): void
+ {
try
{
- $db = Factory::getDbo();
+ $db = \Joomla\CMS\Factory::getDbo();
$db->setQuery(
$db->getQuery(true)
- ->select(['us.' . $db->quoteName('update_site_id'), 'us.' . $db->quoteName('extra_query'), 'us.' . $db->quoteName('location'), 'e.' . $db->quoteName('element')])
+ ->select($db->quoteName('us.extra_query'))
->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('#__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('us.extra_query') . ' != ' . $db->quote(''))
+ ->where($db->quoteName('e.element') . ' = ' . $db->quote('pkg_mokojoomstorelocator'))
+ ->setLimit(1)
);
-
- foreach ($db->loadObjectList() ?: [] as $row)
- {
- $keys['elem_' . $row->element] = $row->extra_query;
- $keys[$row->location] = $row->extra_query;
- $keys['id_' . $row->update_site_id] = $row->extra_query;
- }
+ $key = $db->loadResult();
+ if (!empty($key)) { $this->savedDownloadKey = $key; }
}
catch (\Throwable $e) {}
-
- return $keys;
}
- private function restoreDownloadKeys(array $savedKeys): void
+ private function restoreDownloadKey(): void
{
- if (empty($savedKeys)) { return; }
+ if ($this->savedDownloadKey === null) { return; }
try
{
- $db = Factory::getDbo();
+ $db = \Joomla\CMS\Factory::getDbo();
$db->setQuery(
$db->getQuery(true)
- ->select(['us.' . $db->quoteName('update_site_id'), 'us.' . $db->quoteName('extra_query'), 'us.' . $db->quoteName('location'), 'e.' . $db->quoteName('element')])
+ ->select($db->quoteName('us.update_site_id'))
->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=%') . ')')
+ ->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_mokojoomstorelocator'))
+ ->setLimit(1)
);
-
- $restored = 0;
-
- foreach ($db->loadObjectList() ?: [] as $site)
+ $siteId = (int) $db->loadResult();
+ if ($siteId > 0)
{
- $element = (string) ($site->element ?? '');
- $key = ($element !== '') ? ($savedKeys['elem_' . $element] ?? '') : '';
- if (empty($key)) { $key = $savedKeys[$site->location] ?? $savedKeys['id_' . $site->update_site_id] ?? ''; }
-
- if (!empty($key))
- {
- $db->setQuery($db->getQuery(true)->update($db->quoteName('#__update_sites'))->set($db->quoteName('extra_query') . ' = ' . $db->quote($key))->where($db->quoteName('update_site_id') . ' = ' . (int) $site->update_site_id))->execute();
- $restored++;
- }
+ $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();
}
-
- if ($restored > 0) { Factory::getApplication()->enqueueMessage(sprintf('Restored %d download key(s).', $restored), 'message'); }
}
catch (\Throwable $e) {}
}
@@ -121,7 +111,7 @@ class Pkg_MokojoomstorelocatorInstallerScript
{
try
{
- $db = Factory::getDbo();
+ $db = \Joomla\CMS\Factory::getDbo();
$db->setQuery(
$db->getQuery(true)
->select([$db->quoteName('update_site_id'), $db->quoteName('extra_query')])
@@ -142,7 +132,7 @@ class Pkg_MokojoomstorelocatorInstallerScript
$editUrl = 'index.php?option=com_installer&view=updatesites';
}
- Factory::getApplication()->enqueueMessage(
+ \Joomla\CMS\Factory::getApplication()->enqueueMessage(
'Moko Consulting License Key Required — '
. 'No download key is configured. Updates will not be available until a valid license key is entered. '
. 'Enter License Key',