]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved code in function getStoredFiles() of bweb class
authorDavide Franco <bacula-dev@dflc.ch>
Sat, 9 Jul 2011 13:52:48 +0000 (15:52 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:49:21 +0000 (14:49 +0200)
gui/bacula-web/includes/bweb.inc.php

index 7b716de871e1c4d7c896c152bbb37109616a43c1..6779c68a57826f24d14d5391067684f54537817f 100644 (file)
@@ -379,32 +379,41 @@ class Bweb extends DB
                return array( $vols['pool_name'], $vols['vols'] );
        }
        
-       public function GetStoredFiles( $delay = LAST_DAY )
+       public function getStoredFiles( $start_timestamp, $end_timestamp, $job_name = 'ALL' )
        {
-               $totalfiles = 0;
-
-               $query = "SELECT SUM(JobFiles) AS stored_files FROM Job ";
+               $query = "";
+               $start_date = date( "Y-m-d H:i:s", $start_timestamp);   
+               $end_date   = date( "Y-m-d H:i:s", $end_timestamp);     
                
-               // Interval calculation
-               $end_date   = mktime();
-               $start_date = $end_date - $delay;
+               switch( $this->driver )
+               {
+                       case 'sqlite':
+                       case 'mysql':
+                                       $query = "SELECT SUM(JobFiles) AS stored_files FROM Job ";
+                                       $query .= "WHERE ( EndTime BETWEEN '$start_date' AND '$end_date' )";
+                       break;
+                       case 'pgsql':
+                                       $query = "SELECT SUM(JobFiles) AS stored_files FROM job ";
+                                       $query .= "WHERE ( endtime BETWEEN timestamp '$start_date' AND timestamp '$end_date' )";
+                       break;
+               }
                
-               $start_date = date( "Y-m-d H:i:s", $start_date );
-               $end_date   = date( "Y-m-d H:i:s", $end_date );                 
-
-               if( $delay != ALL )
-                       $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
-                       
+               if( $job_name != 'ALL' ) 
+                       $query .= " AND name = '$job_name'";
+               
+               // Execute query
                $result = $this->db_link->query( $query );
                
                if( !PEAR::isError($result) ) {
-                       $nbfiles        = $result->fetchRow(DB_FETCHMODE_ASSOC);
-                       $totalfiles = $totalfiles + $nbfiles['stored_files'];
+                       $result = $result->fetchRow();
+                       
+                       if( isset($result['stored_files']) and !empty($result['stored_files']) )
+                               return $result['stored_files'];
+                       else
+                               return 0;
                }else{
                        $this->TriggerDBError("Unable to get protected files from catalog", $result);
                }
-               
-               return $totalfiles;
        }
        
        // Function: getStoredBytes