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

Commit c42c3fa

Browse files
committed
fix: make database required for challenges, skip challenge cleanup without database
prevents errors in cron fix #182
1 parent 34c0e9b commit c42c3fa

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

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)