Skip to content

Commit 1c365f0

Browse files
author
Till Brehm
committed
Merge branch 'stable-3.1' into 'stable-3.1'
fix getDatabaseSize() See merge request ispconfig/ispconfig3!829
2 parents 6d28d42 + 8c4359b commit 1c365f0

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,18 +654,29 @@ public function diffrec($record_old, $record_new) {
654654
* @return int - database-size in bytes
655655
*/
656656
public function getDatabaseSize($database_name) {
657-
global $app;
658-
659-
require_once 'lib/mysql_clientdb.conf';
660-
661-
$result = $this->_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".$this->escape($database_name)."'");
657+
global $app, $conf;
658+
static $db=null;
659+
660+
if ( ! $db ) {
661+
$clientdb_host = ($conf['db_host']) ? $conf['db_host'] : NULL;
662+
$clientdb_user = ($conf['db_user']) ? $conf['db_user'] : NULL;
663+
$clientdb_password = ($conf['db_password']) ? $conf['db_password'] : NULL;
664+
$clientdb_port = ((int)$conf['db_port']) ? (int)$conf['db_port'] : NULL;
665+
$clientdb_flags = ($conf['db_flags'] !== NULL) ? $conf['db_flags'] : NULL;
666+
667+
require_once 'lib/mysql_clientdb.conf';
668+
669+
$db = new db($clientdb_host, $clientdb_user, $clientdb_password, NULL, $clientdb_port, $clientdb_flags);
670+
}
671+
672+
$result = $db->_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".$db->escape($database_name)."'");
662673
if(!$result) {
663-
$this->_sqlerror('Unable to determine the size of database ' . $database_name);
674+
$db->_sqlerror('Unable to determine the size of database ' . $database_name);
664675
return;
665676
}
666677
$database_size = $result->getAsRow();
667678
$result->free();
668-
return $database_size[0] ? $database_size[0] : 0;
679+
return $database_size[0] ? $database_size[0] : 0;
669680
}
670681

671682
//** Function to fill the datalog with a full differential record.

server/lib/classes/db_mysql.inc.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,18 +654,29 @@ public function diffrec($record_old, $record_new) {
654654
* @return int - database-size in bytes
655655
*/
656656
public function getDatabaseSize($database_name) {
657-
global $app;
658-
659-
require_once 'lib/mysql_clientdb.conf';
660-
661-
$result = $this->_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".$this->escape($database_name)."'");
657+
global $app, $conf;
658+
static $db=null;
659+
660+
if ( ! $db ) {
661+
$clientdb_host = ($conf['db_host']) ? $conf['db_host'] : NULL;
662+
$clientdb_user = ($conf['db_user']) ? $conf['db_user'] : NULL;
663+
$clientdb_password = ($conf['db_password']) ? $conf['db_password'] : NULL;
664+
$clientdb_port = ((int)$conf['db_port']) ? (int)$conf['db_port'] : NULL;
665+
$clientdb_flags = ($conf['db_flags'] !== NULL) ? $conf['db_flags'] : NULL;
666+
667+
require_once 'lib/mysql_clientdb.conf';
668+
669+
$db = new db($clientdb_host, $clientdb_user, $clientdb_password, NULL, $clientdb_port, $clientdb_flags);
670+
}
671+
672+
$result = $db->_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".$db->escape($database_name)."'");
662673
if(!$result) {
663-
$this->_sqlerror('Unable to determine the size of database ' . $database_name);
674+
$db->_sqlerror('Unable to determine the size of database ' . $database_name);
664675
return;
665676
}
666677
$database_size = $result->getAsRow();
667678
$result->free();
668-
return $database_size[0] ? $database_size[0] : 0;
679+
return $database_size[0] ? $database_size[0] : 0;
669680
}
670681

671682
//** Function to fill the datalog with a full differential record.

0 commit comments

Comments
 (0)