Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit b756406

Browse files
author
Dominik František Bučík
authored
Merge pull request #199 from CESNET/fix-cron-bug
Fix cron when database is not configured
2 parents 34c0e9b + 1826f2d commit b756406

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

composer.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@
2525
"name": "Dominik Frantisek Bucik",
2626
"email": "bucik@ics.muni.cz"
2727
},
28-
{
29-
"name": "Dominik Baranek",
30-
"email": "baranek@ics.muni.cz"
31-
},
3228
{
3329
"name": "Dominik Baranek",
3430
"email": "baranek@ics.muni.cz"
3531
}
3632
],
3733
"require": {
38-
"simplesamlphp/simplesamlphp": "~1.17",
3934
"simplesamlphp/composer-module-installer": "~1.0",
4035
"symfony/var-exporter": "^5.0",
4136
"phpseclib/phpseclib": "~3.0",

hooks/hook_cron.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Hook to run a cron job.
1010
*
1111
* @param array $croninfo Output
12-
* @author Dominik Baranek <baranek@ics.muni.cz>
1312
*/
1413
function perun_hook_cron(&$croninfo)
1514
{
@@ -19,9 +18,15 @@ function perun_hook_cron(&$croninfo)
1918
}
2019
Logger::info('cron [perun]: Running cron in cron tag [' . $croninfo['tag'] . '] ');
2120

22-
$challengesDbCmd = new ChallengesDbCmd();
21+
try {
22+
$challengesDbCmd = new ChallengesDbCmd();
2323

24-
if (! $challengesDbCmd->deleteOldChallenges()) {
25-
Logger::error('cron [perun]: Error while deleting old challenges from the database.');
24+
if (! $challengesDbCmd->deleteOldChallenges()) {
25+
Logger::error('cron [perun]: Error while deleting old challenges from the database.');
26+
}
27+
} catch (\Exception $e) {
28+
Logger::info(
29+
'cron [perun]: Not deleting old challenges from the database because no database is configured or an error occured: ' . $e->getMessage()
30+
);
2631
}
2732
}

lib/databaseCommand/DatabaseConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private function __construct()
3232
{
3333
$configuration = Configuration::getConfig(self::CONFIG_FILE_NAME);
3434

35-
$this->config = $configuration->getConfigItem(self::DATABASE, null);
35+
$this->config = $configuration->getConfigItem(self::DATABASE);
3636
$this->store = $this->config->getConfigItem(self::STORE, null);
3737

3838
$this->whitelistTableName = $this->config->getString(self::WHITELIST_TABLE_NAME, null);

0 commit comments

Comments
 (0)