From bdbbf6d2a8053c5d7ceaa2835ed0d6f41a33926d Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Tue, 9 Jun 2026 12:31:57 -0500 Subject: [PATCH] feat(monitor): send heartbeat on install/update and version change - onExtensionAfterInstall: immediate heartbeat after package install - onAfterInitialise: detect version change on first admin page load, send heartbeat if version differs from last sent, store version in plugin params to avoid re-sending every session --- .../src/Extension/Monitor.php | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/source/packages/plg_system_mokosuite_monitor/src/Extension/Monitor.php b/source/packages/plg_system_mokosuite_monitor/src/Extension/Monitor.php index d90685fa..e3834c8b 100644 --- a/source/packages/plg_system_mokosuite_monitor/src/Extension/Monitor.php +++ b/source/packages/plg_system_mokosuite_monitor/src/Extension/Monitor.php @@ -34,10 +34,63 @@ class Monitor extends CMSPlugin implements SubscriberInterface public static function getSubscribedEvents(): array { return [ - 'onExtensionAfterSave' => 'onExtensionAfterSave', + 'onExtensionAfterSave' => 'onExtensionAfterSave', + 'onAfterInitialise' => 'onAfterInitialise', + 'onExtensionAfterInstall' => 'onExtensionAfterInstall', ]; } + /** + * Send heartbeat on first admin page load after install/update. + */ + public function onAfterInitialise(): void + { + $app = $this->getApplication(); + if (!$app->isClient('administrator')) return; + if (!$this->params->get('heartbeat_enabled', 1)) return; + + $session = \Joomla\CMS\Factory::getSession(); + if ($session->get('mokosuite.heartbeat_sent', false)) return; + + // Check if version changed since last heartbeat + $lastVersion = $this->params->get('_last_heartbeat_version', ''); + $currentVersion = $this->getMokoSuiteVersion(); + + if ($lastVersion !== $currentVersion) + { + $session->set('mokosuite.heartbeat_sent', true); + $this->sendHeartbeat(); + + // Store version so we don't re-send every session + try + { + $db = \Joomla\CMS\Factory::getDbo(); + $params = json_decode($this->params->toString(), true) ?: []; + $params['_last_heartbeat_version'] = $currentVersion; + $db->setQuery( + $db->getQuery(true) + ->update('#__extensions') + ->set('params = ' . $db->quote(json_encode($params))) + ->where('element = ' . $db->quote('mokosuite_monitor')) + ->where('folder = ' . $db->quote('system')) + ->where('type = ' . $db->quote('plugin')) + )->execute(); + } + catch (\Throwable $e) {} + } + } + + /** + * Send heartbeat immediately after package install/update. + */ + public function onExtensionAfterInstall($installer, $eid): void + { + if (!$this->params->get('heartbeat_enabled', 1)) return; + + try { $this->sendHeartbeat(); } + catch (\Throwable $e) {} + } + /** * After saving this plugin or the core plugin, send heartbeat. */