]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved and fixed bugs in code for volumes by pools graph
authorDavide Franco <bacula-dev@dflc.ch>
Sat, 9 Jul 2011 14:44:30 +0000 (16:44 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:49:22 +0000 (14:49 +0200)
gui/bacula-web/includes/bweb.inc.php
gui/bacula-web/index.php

index f18328dabee01e25ae08eeb2280b6e9df09fdcb9..c1b49de8d2c2c519361a86e6753982ad28fa1ab1 100644 (file)
@@ -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' )
index d081d66e6f592fddea0980df9a6fb6bbed4fdb05..9b3ab978ff522dcf41bec26017d939cbaba879f1 100644 (file)
@@ -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();