feat: license key warning + heartbeat validation + stale update site cleanup
- Persistent admin warning when no download key is set on the MokoWaaS update site, with link to System → Update Sites - Daily heartbeat validates the key against MokoGitea's dynamic endpoint; shows error if key is invalid or expired - Package postflight removes stale/duplicate update site entries and orphaned #__updates rows Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,9 @@ class Pkg_MokowaasInstallerScript
|
||||
// Mark MokoWaaS extensions as protected (prevents disable/uninstall at framework level)
|
||||
$this->protectExtensions();
|
||||
|
||||
// Clean up stale/duplicate update sites
|
||||
$this->cleanupStaleUpdateSites();
|
||||
|
||||
// Trigger heartbeat registration
|
||||
$this->sendHeartbeat();
|
||||
}
|
||||
@@ -218,6 +221,92 @@ class Pkg_MokowaasInstallerScript
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove stale and duplicate MokoWaaS update site entries.
|
||||
*
|
||||
* Keeps only the package-level update site pointing to the dynamic
|
||||
* MokoGitea endpoint. Removes plugin-level entries, old static URLs,
|
||||
* and orphaned #__updates rows tied to deleted update sites.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 02.30.00
|
||||
*/
|
||||
private function cleanupStaleUpdateSites(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$dynamicUrl = 'https://git.mokoconsulting.tech/MokoConsulting/MokoWaaS/updates.xml';
|
||||
|
||||
// Find all MokoWaaS update sites
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName(['update_site_id', 'location']))
|
||||
->from($db->quoteName('#__update_sites'))
|
||||
->where('(' . $db->quoteName('name') . ' LIKE ' . $db->quote('%MokoWaaS%')
|
||||
. ' OR ' . $db->quoteName('location') . ' LIKE ' . $db->quote('%MokoWaaS%') . ')');
|
||||
$db->setQuery($query);
|
||||
$sites = $db->loadObjectList();
|
||||
|
||||
$keepId = null;
|
||||
$removeIds = [];
|
||||
|
||||
foreach ($sites as $site)
|
||||
{
|
||||
if ($site->location === $dynamicUrl && $keepId === null)
|
||||
{
|
||||
$keepId = (int) $site->update_site_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$removeIds[] = (int) $site->update_site_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($removeIds))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$idList = implode(',', $removeIds);
|
||||
|
||||
// Remove orphaned #__updates rows
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->delete($db->quoteName('#__updates'))
|
||||
->where($db->quoteName('update_site_id') . ' IN (' . $idList . ')')
|
||||
)->execute();
|
||||
|
||||
// Remove link rows
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->delete($db->quoteName('#__update_sites_extensions'))
|
||||
->where($db->quoteName('update_site_id') . ' IN (' . $idList . ')')
|
||||
)->execute();
|
||||
|
||||
// Remove stale update sites
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->delete($db->quoteName('#__update_sites'))
|
||||
->where($db->quoteName('update_site_id') . ' IN (' . $idList . ')')
|
||||
)->execute();
|
||||
|
||||
$count = count($removeIds);
|
||||
|
||||
if ($count > 0)
|
||||
{
|
||||
Factory::getApplication()->enqueueMessage(
|
||||
sprintf('Cleaned up %d stale MokoWaaS update site(s).', $count),
|
||||
'message'
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (\Throwable $e)
|
||||
{
|
||||
Log::add('Error cleaning up stale update sites: ' . $e->getMessage(), Log::WARNING, 'jerror');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the MokoWaaS update server entry stays enabled and points
|
||||
* to the correct dynamic endpoint with the license key attached.
|
||||
|
||||
Reference in New Issue
Block a user