aggregator2_hook_cron()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 15
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 23
rs 9.4555
1
<?php
2
3
declare(strict_types=1);
4
5
use Exception;
6
use SimpleSAML\Assert\Assert;
7
use SimpleSAML\Configuration;
8
use SimpleSAML\Module\aggregator2\Aggregator;
9
10
/**
11
 * cron hook to update aggregator2 metadata.
12
 *
13
 * @param array &$croninfo  Output
14
 */
15
function aggregator2_hook_cron(array &$croninfo): void
16
{
17
    Assert::keyExists($croninfo, 'summary');
18
    Assert::keyExists($croninfo, 'tag');
19
20
    $cronTag = $croninfo['tag'];
21
22
    $config = Configuration::getConfig('module_aggregator2.php');
23
    $config = $config->toArray();
24
25
    foreach ($config as $id => $c) {
26
        if (!isset($c['cron.tag'])) {
27
            continue;
28
        }
29
        if ($c['cron.tag'] !== $cronTag) {
30
            continue;
31
        }
32
33
        try {
34
            $a = Aggregator::getAggregator($id);
35
            $a->updateCache();
36
        } catch (Exception $e) {
37
            $croninfo['summary'][] = 'Error during aggregator2 cacheupdate: ' . $e->getMessage();
38
        }
39
    }
40
}
41