From 5ca959fa688255a8de61f89fe2751eb4d24a6912 Mon Sep 17 00:00:00 2001 From: Florian Schaal <florian@schaal-24.de> Date: Tue, 22 Mar 2016 09:22:07 -0400 Subject: [PATCH] fixed typo --- server/lib/classes/cron.d/100-monitor_database_size.inc.php | 68 +++++++++++++++++++-------------- 1 files changed, 39 insertions(+), 29 deletions(-) diff --git a/server/lib/classes/cron.d/100-monitor_database_size.inc.php b/server/lib/classes/cron.d/100-monitor_database_size.inc.php index 6ec22d8..d2981dd 100644 --- a/server/lib/classes/cron.d/100-monitor_database_size.inc.php +++ b/server/lib/classes/cron.d/100-monitor_database_size.inc.php @@ -77,38 +77,48 @@ /** The state of the database-usage */ $state = 'ok'; - /** Fetch the data of all active databases into an array */ - $records = $app->db->queryAllRecords("SELECT database_name, sys_groupid FROM web_database WHERE server_id = $server_id AND active='y' GROUP BY sys_groupid, database_name ASC"); - if(is_array($records) && !empty($records)) { + /** Fetch the data of all databases into an array */ + $databases = $app->db->queryAllRecords("SELECT database_id, database_name, sys_groupid, database_quota, quota_exceeded FROM web_database WHERE server_id = ? GROUP BY sys_groupid, database_name ASC", $server_id); + + if(is_array($databases) && !empty($databases)) { + $data = array(); - for ($i = 0; $i < sizeof($records); $i++) { - $data[$i]['name'] = $records[$i]['database_name']; - $data[$i]['size'] = $app->db->getDatabaseSize($data[$i]['name']); - $data[$i]['client_id'] = $records[$i]['sys_groupid']; + + for ($i = 0; $i < sizeof($databases); $i++) { + $rec = $databases[$i]; + + $data[$i]['database_name']= $rec['database_name']; + $data[$i]['size'] = $app->db->getDatabaseSize($rec['database_name']); + $data[$i]['sys_groupid'] = $rec['sys_groupid']; + + $quota = $rec['database_quota'] * 1024 * 1024; + if(!is_numeric($quota)) continue; + + if($quota < 1 || $quota > $data[$i]['size']) { + print $rec['database_name'] . ' does not exceed quota qize: ' . $quota . ' > ' . $data[$i]['size'] . "\n"; + if($rec['quota_exceeded'] == 'y') { + $app->dbmaster->datalogUpdate('web_database', array('quota_exceeded' => 'n'), 'database_id', $rec['database_id']); + } + } elseif($rec['quota_exceeded'] == 'n') { + print $rec['database_name'] . ' exceeds quota qize: ' . $quota . ' < ' . $data[$i]['size'] . "\n"; + $app->dbmaster->datalogUpdate('web_database', array('quota_exceeded' => 'y'), 'database_id', $rec['database_id']); + } } + + $res = array(); + $res['server_id'] = $server_id; + $res['type'] = $type; + $res['data'] = $data; + $res['state'] = $state; + + //* Insert the data into the database + $sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . + 'VALUES (?, ?, UNIX_TIMESTAMP(), ?, ?)'; + $app->dbmaster->query($sql, $res['server_id'], $res['type'], serialize($res['data']), $res['state']); + + //* The new data is written, now we can delete the old one + $this->_tools->delOldRecords($res['type'], $res['server_id']); } - - $res = array(); - $res['server_id'] = $server_id; - $res['type'] = $type; - $res['data'] = $data; - $res['state'] = $state; - - /* - * Insert the data into the database - */ - $sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . - 'VALUES (' . - $res['server_id'] . ', ' . - "'" . $app->dbmaster->quote($res['type']) . "', " . - 'UNIX_TIMESTAMP(), ' . - "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . - "'" . $res['state'] . "'" . - ')'; - $app->dbmaster->query($sql); - - /* The new data is written, now we can delete the old one */ - $this->_tools->delOldRecords($res['type'], $res['server_id']); parent::onRunJob(); } -- Gitblit v1.9.1