Passed
Branch master (90f5ca)
by Tim
08:42
created

aggregator2_hook_cron()   A

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
use Exception;
4
use SimpleSAML\Configuration;
5
use SimpleSAML\Module\aggregator2\Aggregator;
6
7
/**
8
 * cron hook to update aggregator2 metadata.
9
 *
10
 * @param array &$croninfo  Output
11
 */
12
function aggregator2_hook_cron(array &$croninfo): void
13
{
14
    assert('array_key_exists("summary", $croninfo)');
15
    assert('array_key_exists("tag", $croninfo)');
16
17
    $cronTag = $croninfo['tag'];
18
19
    $config = Configuration::getConfig('module_aggregator2.php');
20
    $config = $config->toArray();
21
22
    foreach ($config as $id => $c) {
23
        if (!isset($c['cron.tag'])) {
24
            continue;
25
        }
26
        if ($c['cron.tag'] !== $cronTag) {
27
            continue;
28
        }
29
30
        try {
31
            $a = Aggregator::getAggregator($id);
32
            $a->updateCache();
33
        } catch (Exception $e) {
34
            $croninfo['summary'][] = 'Error during aggregator2 cacheupdate: ' . $e->getMessage();
35
        }
36
    }
37
}
38