1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | use Exception; |
||
6 | use SimpleSAML\Assert\Assert; |
||
7 | use SimpleSAML\Configuration; |
||
8 | use SimpleSAML\Logger; |
||
9 | use SimpleSAML\Module\statistics\Aggregator; |
||
10 | |||
11 | /** |
||
12 | * Hook to run a cron job. |
||
13 | * |
||
14 | * @param array &$croninfo Output |
||
15 | */ |
||
16 | function statistics_hook_cron(array &$croninfo): void |
||
17 | { |
||
18 | Assert::keyExists($croninfo, 'summary'); |
||
19 | Assert::keyExists($croninfo, 'tag'); |
||
20 | |||
21 | $statconfig = Configuration::getConfig('module_statistics.php'); |
||
22 | |||
23 | if (is_null($statconfig->getOptionalValue('cron_tag', null))) { |
||
24 | return; |
||
25 | } |
||
26 | if ($statconfig->getOptionalValue('cron_tag', null) !== $croninfo['tag']) { |
||
27 | return; |
||
28 | } |
||
29 | |||
30 | $maxtime = $statconfig->getOptionalInteger('time_limit', null); |
||
31 | if ($maxtime) { |
||
0 ignored issues
–
show
|
|||
32 | set_time_limit($maxtime); |
||
33 | } |
||
34 | |||
35 | try { |
||
36 | $aggregator = new Aggregator(); |
||
37 | $results = $aggregator->aggregate(); |
||
38 | if (empty($results)) { |
||
39 | Logger::notice('Output from statistics aggregator was empty.'); |
||
40 | } else { |
||
41 | $aggregator->store($results); |
||
42 | } |
||
43 | } catch (Exception $e) { |
||
44 | $message = 'Loganalyzer threw exception: ' . $e->getMessage(); |
||
45 | Logger::warning($message); |
||
46 | $croninfo['summary'][] = $message; |
||
47 | } |
||
48 | } |
||
49 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: