From b52b9fe3e745647a6faf198da06e2577afd4720b Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Sat, 9 Jul 2011 16:44:30 +0200 Subject: [PATCH] bacula-web: Improved and fixed bugs in code for volumes by pools graph --- gui/bacula-web/includes/bweb.inc.php | 40 ++++++++++++++-------------- gui/bacula-web/index.php | 14 +++++----- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/gui/bacula-web/includes/bweb.inc.php b/gui/bacula-web/includes/bweb.inc.php index f18328dabe..c1b49de8d2 100644 --- a/gui/bacula-web/includes/bweb.inc.php +++ b/gui/bacula-web/includes/bweb.inc.php @@ -304,17 +304,18 @@ class Bweb extends DB } // Return the list of Pools in a array - public function Get_Pools_List() + public function get_Pools() { - $result = ""; - $query = "SELECT Name, PoolId FROM Pool"; + $pools = array(); + $query = "SELECT name, poolid FROM pool"; $result = $this->db_link->query ( $query ); - if( PEAR::isError( $result ) ) { - $this->TriggerDBError( "Unable to get the pool list from catalog", $result ); - }else { - return $result; + if( !PEAR::isError( $result ) ) { + while( $pool = $result->fetchRow() ) + $pools[] = $pool; + return $pools; } + $this->TriggerDBError( "Unable to get the pool list from catalog", $result ); } public function Get_BackupJob_Names() @@ -346,7 +347,7 @@ class Bweb extends DB } } - public function CountVolumesByPool( $pool_id ) + public function countVolumes( $pool_id = 'ALL' ) { $res = null; $nb_vol = null; @@ -356,27 +357,26 @@ class Bweb extends DB { case 'sqlite': case 'mysql': - $query = 'SELECT COUNT(*) as vols,Pool.name as pool_name '; + $query = 'SELECT COUNT(*) as vols_count '; $query .= 'FROM Media '; - $query .= 'RIGHT JOIN Pool ON (Media.PoolId = Pool.PoolId) '; - $query .= 'WHERE Media.poolid = ' . $pool_id; break; case 'pgsql': - $query = 'SELECT COUNT(*) as vols,Pool.name as pool_name '; + $query = 'SELECT COUNT(*) as vols_count '; $query .= 'FROM Media '; - $query .= 'RIGHT JOIN Pool ON (Media.PoolId = Pool.PoolId) '; - $query .= 'WHERE Media.poolid = ' . $pool_id; - $query .= 'GROUP BY pool.name'; break; } - $res = $this->db_link->query( $query ); - if( PEAR::isError( $res ) ) - $this->triggerDBError( 'Unable to get volume number from pool', $res ); + if( $pool_id != 'ALL' ) + $query .= 'WHERE media.poolid = ' . $pool_id; - $vols = $res->fetchRow( ); + $res = $this->db_link->query( $query ); - return array( $vols['pool_name'], $vols['vols'] ); + if( !PEAR::isError( $res ) ) { + $vols = $res->fetchRow( ); + return $vols['vols_count']; + } + + $this->triggerDBError( 'Unable to get volume number from pool', $res ); } public function getStoredFiles( $start_timestamp, $end_timestamp, $job_name = 'ALL' ) diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index d081d66e6f..9b3ab978ff 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -67,16 +67,14 @@ $graph->Render(); $dbSql->tpl->assign('graph_jobs', $graph->Get_Image_file() ); unset($graph); -// Pool and volumes graph -$data = array(); -$graph = new CGraph( "graph1.png" ); +// Volumes by pools graph +$vols_by_pool = array(); +$graph = new CGraph( "graph1.png" ); -$pools = $dbSql->Get_Pools_List(); -while( $pool = $pools->fetchRow( ) ) { - array_push( $data, $dbSql->CountVolumesByPool( $pool['poolid']) ); -} +foreach( $dbSql->get_Pools() as $pool ) + $vols_by_pool[] = array( $pool['name'], $dbSql->countVolumes( $pool['poolid'] ) ); -$graph->SetData( $data, 'pie', 'text-data-single' ); +$graph->SetData( $vols_by_pool, 'pie', 'text-data-single' ); $graph->SetGraphSize( 400, 230 ); $graph->Render(); -- 2.39.5