From 5f48d2dabc94e5e13c345b555a79ed177a1465f5 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 12 Feb 2014 10:47:42 +0100 Subject: [PATCH 1/2] [ADDED] Notification cleanup script * [ADDED] Admin Panel Setting for max age for notifications * [ADDED] Cronjob to clean out old notifications * [ADDED] New cron to scripts and monitoring Fixes #1672 once merged. --- cronjobs/run-crons.sh | 2 +- cronjobs/run-maintenance.sh | 2 +- public/include/classes/notification.class.php | 21 +++++++++++++++++++ public/include/config/admin_settings.inc.php | 6 ++++++ public/include/config/monitor_crons.inc.php | 2 +- 5 files changed, 30 insertions(+), 3 deletions(-) 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': From ac3bea9f1a56dd245e41545b41e72bb94139bf4f Mon Sep 17 00:00:00 2001 From: Andy Mornes Date: Thu, 13 Feb 2014 13:26:48 -0600 Subject: [PATCH 2/2] [FIX] Correcting user ID for new block emails Also adding the currency to the notifications as well. --- cronjobs/findblock.php | 3 ++- public/templates/mail/notifications/new_block.tpl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 71cca570..1ac69535 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -153,7 +153,7 @@ if (empty($aAllBlocks)) { $aAccounts = $notification->getNotificationAccountIdByType('new_block'); if (is_array($aAccounts)) { - $finder = $user->getUserName($aBlock['account_id']); + $finder = $user->getUserName($iAccountId); foreach ($aAccounts as $aData) { $aMailData['height'] = $aBlock['height']; $aMailData['subject'] = 'New Block'; @@ -162,6 +162,7 @@ if (empty($aAllBlocks)) { $aMailData['amount'] = $aBlock['amount']; $aMailData['difficulty'] = $aBlock['difficulty']; $aMailData['finder'] = $finder; + $aMailData['currency'] = $config['currency']; if (!$notification->sendNotification($aData['account_id'], 'new_block', $aMailData)) $log->logError('Failed to notify user of new found block: ' . $user->getUserName($aData['account_id'])); } diff --git a/public/templates/mail/notifications/new_block.tpl b/public/templates/mail/notifications/new_block.tpl index 46b81fbf..20549f18 100644 --- a/public/templates/mail/notifications/new_block.tpl +++ b/public/templates/mail/notifications/new_block.tpl @@ -1,5 +1,5 @@ -

{nocache}Block Number {$DATA.height} has been discovered by {$DATA.finder} with a total value of {$DATA.amount}! The current difficulty is {$DATA.difficulty}.{/nocache}

+

{nocache}Block Number {$DATA.height} has been discovered by {$DATA.finder} with a total value of {$DATA.amount} {$DATA.currency}! The current difficulty is {$DATA.difficulty}.{/nocache}