fix: use single-key pattern instead of universal backup
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Report Issues (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 2s
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Report Issues (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 2s
This commit is contained in:
+34
-44
@@ -18,8 +18,8 @@ class Pkg_MokoOGInstallerScript
|
||||
protected $minimumJoomla = '4.0.0';
|
||||
protected $minimumPhp = '8.1.0';
|
||||
|
||||
/** @var array Download keys saved before Joomla wipes update sites */
|
||||
private array $savedDownloadKeys = [];
|
||||
|
||||
|
||||
|
||||
public function preflight(string $type, InstallerAdapter $parent): bool
|
||||
{
|
||||
@@ -33,14 +33,14 @@ class Pkg_MokoOGInstallerScript
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->savedDownloadKeys = $this->backupDownloadKeys();
|
||||
$this->saveDownloadKey();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function postflight(string $type, InstallerAdapter $parent): void
|
||||
{
|
||||
$this->restoreDownloadKeys($this->savedDownloadKeys);
|
||||
$this->restoreDownloadKey();
|
||||
$this->warnMissingLicenseKey();
|
||||
|
||||
if ($type === 'install')
|
||||
@@ -61,66 +61,56 @@ class Pkg_MokoOGInstallerScript
|
||||
}
|
||||
}
|
||||
|
||||
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_mokoog'))
|
||||
->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_mokoog'))
|
||||
->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) {}
|
||||
}
|
||||
@@ -129,7 +119,7 @@ class Pkg_MokoOGInstallerScript
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$db = \Joomla\CMS\Factory::getDbo();
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select([$db->quoteName('update_site_id'), $db->quoteName('extra_query')])
|
||||
@@ -150,7 +140,7 @@ class Pkg_MokoOGInstallerScript
|
||||
$editUrl = 'index.php?option=com_installer&view=updatesites';
|
||||
}
|
||||
|
||||
Factory::getApplication()->enqueueMessage(
|
||||
\Joomla\CMS\Factory::getApplication()->enqueueMessage(
|
||||
'<strong>Moko Consulting License Key Required</strong> — '
|
||||
. 'No download key is configured. Updates will not be available until a valid license key is entered. '
|
||||
. '<a href="' . $editUrl . '" class="btn btn-sm btn-warning ms-2">Enter License Key</a>',
|
||||
|
||||
Reference in New Issue
Block a user