From: Davide Franco Date: Thu, 17 Feb 2011 17:21:10 +0000 (+0100) Subject: bacula-web: Improved PHP code for GetDbSize() function in bweb.inc.php X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a46b787c93f46990b8dc54c37c00060843464374;p=bacula%2Fbacula bacula-web: Improved PHP code for GetDbSize() function in bweb.inc.php --- diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php index 39deeaab53..79d7cfc8de 100644 --- a/gui/bacula-web/bweb.inc.php +++ b/gui/bacula-web/bweb.inc.php @@ -211,7 +211,38 @@ class Bweb extends DB { function GetDbSize() { - $database_size = 0; + $database_size = 0; + $query = ""; + + switch( $this->driver ) + { + case 'mysql': + $query = "SELECT table_schema AS 'database', sum( data_length + index_length) AS 'dbsize' "; + $query .= "FROM information_schema.TABLES "; + $query .= "WHERE table_schema = 'bacula' "; + $query .= "GROUP BY table_schema"; + break; + case 'pgsql': + $query = "SELECT pg_database_size('bacula') AS dbsize"; + break; + case 'sqlite': + // Not yet implemented + return "0 MB"; + break; + } + + $result = $this->db_link->query( $query ); + + if(! PEAR::isError( $result ) ) + { + $db = $result->fetchRow( DB_FETCHMODE_ASSOC ); + $database_size =+ $db['dbsize']; + }else + die( "Unable to get database size
" . $jobs->getMessage() ); + + return $this->human_file_size( $database_size ); + + /* if ( $this->driver == "mysql") { $dbsize = $this->db_link->query("show table status") or die ("classes.inc: Error query: 3"); @@ -237,8 +268,7 @@ class Bweb extends DB { } // end if $dbsize->free(); - - return $this->human_file_size( $database_size ); + */ } // end function GetDbSize() public function Get_Nb_Clients()