Skip to content

Commit 7fc30f8

Browse files
author
Florian Schaal
committed
db-quota-notify
1 parent c626c96 commit 7fc30f8

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

server/lib/classes/cron.d/300-quota_notify.inc.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,17 @@ public function onRunJob() {
442442
else $used_ratio = 0;
443443

444444
//* send notifications only if 90% or more of the quota are used
445-
if($used_ratio > 0.9) {
445+
if($used_ratio > 0.9 && $user_ratio != 0) {
446446

447-
//* reset notification date
448-
if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => null), 'database_id', $rec['database_id']);
447+
//* could a notification be sent?
448+
$send_notification = false;
449+
if(!$rec['last_quota_notification']) $send_notification = true; //* not yet notified
450+
elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
449451

450-
$app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
451452

452-
// send notification - everything ok again
453-
if($rec['last_quota_notification'] && $web_config['overquota_notify_onok'] == 'y' && ($web_config['overquota_db_notify_admin'] == 'y' || $web_config['overquota_db_notify_client'] == 'y')) {
453+
//* Send quota notifications
454+
if(($web_config['overquota_db_notify_admin'] == 'y' || $web_config['overquota_db_notify_client'] == 'y') && $send_notification == true) {
455+
$app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
454456
$placeholders = array(
455457
'{database_name}' => $rec['database_name'],
456458
'{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
@@ -462,27 +464,25 @@ public function onRunJob() {
462464
$recipients = array();
463465

464466
//* send email to admin
465-
if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y')
467+
if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y')
466468
$recipients[] = $global_config['admin_mail'];
467469

468470
//* Send email to client
469-
if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
471+
if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
470472
$recipients[] = $client['email'];
471473

472474
$this->_tools->send_notification_email('db_quota_notification', $placeholders, $recipients);
473475

474476
}
475477

476478
} else {
479+
//* reset notification date
480+
if($rec['last_quota_notification']) $app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => null), 'database_id', $rec['database_id']);
477481

478-
//* could a notification be sent?
479-
$send_notification = false;
480-
if(!$rec['last_quota_notification']) $send_notification = true; //* not yet notified
481-
elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
482+
$app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
482483

483-
//* Send quota notifications
484-
if(($web_config['overquota_db_notify_admin'] == 'y' || $web_config['overquota_db_notify_client'] == 'y') && $send_notification == true) {
485-
$app->dbmaster->datalogUpdate('web_database', array("last_quota_notification" => array("SQL" => "CURDATE()")), 'database_id', $rec['database_id']);
484+
// send notification - everything ok again
485+
if($rec['last_quota_notification'] && $web_config['overquota_notify_onok'] == 'y' && ($web_config['overquota_db_notify_admin'] == 'y' || $web_config['overquota_db_notify_client'] == 'y')) {
486486
$placeholders = array(
487487
'{database_name}' => $rec['database_name'],
488488
'{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
@@ -494,16 +494,17 @@ public function onRunJob() {
494494
$recipients = array();
495495

496496
//* send email to admin
497-
if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y')
497+
if($global_config['admin_mail'] != '' && $web_config['overquota_db_notify_admin'] == 'y')
498498
$recipients[] = $global_config['admin_mail'];
499499

500500
//* Send email to client
501-
if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
501+
if($web_config['overquota_db_notify_client'] == 'y' && $client['email'] != '')
502502
$recipients[] = $client['email'];
503503

504504
$this->_tools->send_notification_email('db_quota_ok_notification', $placeholders, $recipients);
505505

506506
}
507+
507508
}
508509

509510
}

0 commit comments

Comments
 (0)