]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Optimized php code in bweb classe
authorDavide Franco <bacula-dev@dflc.ch>
Sun, 26 Jun 2011 16:16:51 +0000 (18:16 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:49:16 +0000 (14:49 +0200)
 - Optimized Get_Pools_List() function in BWeb class
 - Added defautl fetch mode to DB class
 - Optimized code in CountVolumesByPool() function

gui/bacula-web/includes/bweb.inc.php
gui/bacula-web/index.php

index 08e221d2019152c6764b81b3157b4363e18e7cf1..04e1a6221edd3d04d281ab4616ab994905b6e813 100644 (file)
@@ -52,6 +52,7 @@ class Bweb extends DB
                }else {
                        $this->driver = $dsn['phptype'];                            
             register_shutdown_function(array(&$this,'close') );
+                       $this->db_link->setFetchMode(DB_FETCHMODE_ASSOC);
                }
                
                // Initialize smarty template classe
@@ -317,20 +318,14 @@ class Bweb extends DB
        // Return the list of Pools in a array
        public function Get_Pools_List()
        {
-               $pool_list = array();
-               $result    = "";
-               
-               $query = "SELECT Name, PoolId FROM Pool";
-               
-               $result = $this->db_link->query ( $query );
+               $result         = "";
+               $query          = "SELECT Name, PoolId FROM Pool";
+               $result         = $this->db_link->query ( $query );
 
                if( PEAR::isError( $result ) ) {
-                       die( "Unable to get the pool list from catalog" );                              
+                       $this->TriggerDBError( "Unable to get the pool list from catalog", $result );                           
                }else {
-                       while( $pool = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
-                               array_push( $pool_list, array( $pool['name'] => $pool['poolid'] ) );
-                       }
-                       return $pool_list;
+                       return $result;
                }
        }
        
@@ -424,18 +419,18 @@ class Bweb extends DB
        
        public function CountVolumesByPool( $pool_id )
        {
-               foreach( $pool_id as $pool_name => $pool ) {
-                       $query = "SELECT COUNT(*) AS nb_vol FROM Media WHERE PoolId = '$pool_id'";
-                       $result = $this->db_link->query( $query );
-                       
-                       if( PEAR::isError( $result ) ) {
-                               $this->TriggerDBError( 'Unable to get volume number from catalog', $result );
-                               //die("Unable to get volume number from catalog");
-                       }else{
-                               $nb_vol = $result->fetchRow(DB_FETCHMODE_ASSOC);
-                               return array( $pool_name, $nb_vol['nb_vol'] );
-                       }
-               }
+               var_dump( $pool_id );
+               $res    = null;
+               $nb_vol = null;
+               $query  = "SELECT COUNT(*) as nb_vol FROM media WHERE poolid = $pool_id";
+               
+               $res = $this->db_link->query( $query );
+               if( PEAR::isError( $res ) )
+                       $this->triggerDBError( 'Unable to get volume number from pool', $res );
+               else
+                       $nb_vol = $res->fetchRow( );
+               
+               return array( $pool_name, $nb_vol['nb_vol'] );
        }
        
        public function GetStoredFiles( $delay = LAST_DAY )
index 2672381fb118b1b70054772374571397f13246c9..e665c449c03e8b2baa338f91d7a1640a29c2d3f3 100644 (file)
@@ -87,10 +87,8 @@ $data = array();
 $graph = new BGraph( "graph1.png" );
 
 $pools = $dbSql->Get_Pools_List();
-
-foreach( $pools as $pool ) {
-       array_push( $data, $dbSql->CountVolumesByPool( $pool ) );
-}
+while( $pool = $pools->fetchRow( ) )
+       array_push( $data, $pool );
 
 $graph->SetData( $data, 'pie', 'text-data-single' );
 $graph->SetGraphSize( 400, 230 );