feat: download key preservation in preflight + update site notice
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user