diff --git a/config-templates/module_proxystatistics.php b/config-templates/module_proxystatistics.php index c0dfbe25ccf4f5049138545d790f26781d054d69..ad4b0de6f16fca9f1176c7d39d58bf94eda8119b 100644 --- a/config-templates/module_proxystatistics.php +++ b/config-templates/module_proxystatistics.php @@ -104,9 +104,17 @@ $config = [ */ //'apiWritePasswordHash' => password_hash('ap1Wr1T3rP@S$'), - 'ignoredIds' => [ - 'IDP' => ['spentityid1', 'spentityid2', 'spentityid3',], - 'SP' => ['idpentityid1', 'idpentityid2', 'idpentityid3',], - ], + /* + * List of IDP and/or SP EntityIDs for which the login statistic will be ignored even + * when requested to be instered into the storage. By default lists are empty + */ + //'ignoredIds' => [ + // 'IDP' => ['spentityid1', 'spentityid2', 'spentityid3',], + // 'SP' => ['idpentityid1', 'idpentityid2', 'idpentityid3',], + //], + /* + * Enabled or disables CRON hook (aggregating the stats). By default is enabled. + */ + //'cronEnabled' => false, ]; diff --git a/hooks/hook_cron.php b/hooks/hook_cron.php index 5dcb39b1c3002a5cdaf3deda4617591918820791..3e634778925663a7c312dc03b7b64f1b2a04c373 100644 --- a/hooks/hook_cron.php +++ b/hooks/hook_cron.php @@ -3,6 +3,7 @@ declare(strict_types=1); use SimpleSAML\Logger; +use SimpleSAML\Module\proxystatistics\Config; use SimpleSAML\Module\proxystatistics\DatabaseCommand; /** @@ -18,8 +19,13 @@ function proxystatistics_hook_cron(&$croninfo) return; } - Logger::info('cron [proxystatistics]: Running cron in cron tag [' . $croninfo['tag'] . '] '); + $config = Config::getInstance(); + if (!$config->isCronEnabled()) { + Logger::debug('cron [proxystatistics]: Skipping cron - disabled by confiuration'); + return; + } + Logger::info('cron [proxystatistics]: Running cron in cron tag [' . $croninfo['tag'] . '] '); try { $dbCmd = new DatabaseCommand(); $dbCmd->aggregate(); diff --git a/lib/Config.php b/lib/Config.php index fd443dde17b572f087abd0e2f86ec8d3ca5ed1b3..6f8b9a3bda5258cece63dca2e1c81f17f08e723d 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -43,6 +43,8 @@ class Config private const IGNORED_IDS = 'ignoredIds'; + private const CRON_ENABLED = 'cronEnabled'; + private $config; private $store; @@ -67,6 +69,8 @@ class Config private $ignoredIds; + private $cronEnabled; + private static $instance; private function __construct() @@ -79,6 +83,7 @@ class Config $this->keepPerUser = $this->config->getIntegerRange(self::KEEP_PER_USER, 31, 1827, 31); $this->requiredAuthSource = $this->config->getString(self::REQUIRE_AUTH_SOURCE, ''); $this->idAttribute = $this->config->getString(self::USER_ID_ATTRIBUTE, 'uid'); + $this->cronEnabled = $this->config->getBoolean(self::CRON_ENABLED, true); $this->apiWriteEnabled = $this->config->getBoolean(self::API_WRITE_ENABLED, false); $this->ignoredIds = $this->config->getArray(self::IGNORED_IDS, []); if ($this->apiWriteEnabled) { @@ -172,4 +177,9 @@ class Config { return $this->ignoredIds; } + + public function isCronEnabled() + { + return $this->cronEnabled; + } }