diff --git a/cronjobs/run-crons.sh b/cronjobs/run-crons.sh index 29b294bf..46b2ab61 100755 --- a/cronjobs/run-crons.sh +++ b/cronjobs/run-crons.sh @@ -10,7 +10,7 @@ PHP_BIN=$( which php ) # List of cruns to execute -CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php token_cleanup.php archive_cleanup.php liquid_payout.php" +CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blockupdate.php payouts.php tickerupdate.php notifications.php statistics.php token_cleanup.php archive_cleanup.php notification_cleanup.php liquid_payout.php" # Output additional runtime information VERBOSE="0" diff --git a/cronjobs/run-maintenance.sh b/cronjobs/run-maintenance.sh index 05bd93a6..cd3ae296 100755 --- a/cronjobs/run-maintenance.sh +++ b/cronjobs/run-maintenance.sh @@ -10,7 +10,7 @@ PHP_BIN=$( which php ) # List of cruns to execute -CRONS="tickerupdate.php notifications.php token_cleanup.php archive_cleanup.php" +CRONS="tickerupdate.php notifications.php token_cleanup.php archive_cleanup.php notification_cleanup.php" # Output additional runtime information VERBOSE="0" diff --git a/public/include/classes/notification.class.php b/public/include/classes/notification.class.php index ec09bad9..d4376005 100644 --- a/public/include/classes/notification.class.php +++ b/public/include/classes/notification.class.php @@ -151,6 +151,27 @@ class Notification extends Mail { $this->setErrorMessage('Error sending mail notification'); return false; } + + /** + * Cleanup old notifications + * @param none + * @return bool true or false + **/ + public function cleanupNotifications($days=7) { + $failed = 0; + $this->deleted = 0; + $stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE time < (NOW() - ? * 24 * 60 * 60)"); + if (! ($this->checkStmt($stmt) && $stmt->bind_param('i', $days) && $stmt->execute())) { + $failed++; + } else { + $this->deleted += $stmt->affected_rows; + } + if ($failed > 0) { + $this->setCronMessage('Failed to delete ' . $failed . ' notifications from ' . $this->table . ' table'); + return false; + } + return true; + } } $notification = new Notification(); diff --git a/public/include/config/admin_settings.inc.php b/public/include/config/admin_settings.inc.php index dd0c4eed..4bddfc68 100644 --- a/public/include/config/admin_settings.inc.php +++ b/public/include/config/admin_settings.inc.php @@ -390,6 +390,12 @@ $aSettings['monitoring'][] = array( 'name' => 'monitoring_uptimerobot_api_keys', 'value' => $setting->getValue('monitoring_uptimerobot_api_keys'), 'tooltip' => 'Create per-monitor API keys and save them here to propagate your uptime statistics.' ); +$aSettings['notifications'][] = array( + 'display' => 'Notification Cleanup Time', 'type' => 'text', + 'default' => 7, + 'name' => 'notifications_cleanup_time', 'value' => $setting->getValue('notifications_cleanup_time'), + 'tooltip' => 'Maximum age in days of notifications before cleaned from database.' +); $aSettings['notifications'][] = array( 'display' => 'Disable notifications', 'type' => 'select', 'options' => array( 0 => 'No', 1 => 'Yes' ), diff --git a/public/include/config/monitor_crons.inc.php b/public/include/config/monitor_crons.inc.php index 821041bc..4fc61542 100644 --- a/public/include/config/monitor_crons.inc.php +++ b/public/include/config/monitor_crons.inc.php @@ -2,7 +2,7 @@ // Small helper array that may be used on some page controllers to // fetch the crons we wish to monitor -$aMonitorCrons = array('statistics','payouts','token_cleanup','archive_cleanup','blockupdate','findblock','notifications','tickerupdate','liquid_payout'); +$aMonitorCrons = array('statistics','payouts','token_cleanup','archive_cleanup','notification_cleanup','blockupdate','findblock','notifications','tickerupdate','liquid_payout'); switch ($config['payout_system']) { case 'pplns':