feat(monitor): send heartbeat on install/update and version change
Universal: Auto Version Bump / Version Bump (push) Successful in 8s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 10s
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Generic: Repo Health / Access control (pull_request) Successful in 1s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Successful in 7s
Universal: PR Check / Validate PR (pull_request) Failing after 11s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 30s
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Failing after 31s
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: moko-platform CI / CI Summary (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
Universal: Auto Version Bump / Version Bump (push) Successful in 8s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 10s
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Generic: Repo Health / Access control (pull_request) Successful in 1s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Successful in 7s
Universal: PR Check / Validate PR (pull_request) Failing after 11s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 30s
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Failing after 31s
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: moko-platform CI / CI Summary (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Report Issues (push) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report Issues (pull_request) Has been cancelled
- 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
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user