]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved GetStoredFiles() function adding interval delay
authorDavide Franco <bacula-dev@dflc.ch>
Fri, 11 Mar 2011 12:52:45 +0000 (13:52 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:49:07 +0000 (14:49 +0200)
 - Improved GetStoredFiles() function with a new parameter that allow to specify interval.

gui/bacula-web/bweb.inc.php

index 3d756a246fdc475af7d3d9e4a2a037591a9cb507..95f6a77f0d56e0795d4d93cad9f4936a9a2cee63 100644 (file)
@@ -612,19 +612,32 @@ class Bweb extends DB {
                        }
                }
                
-               public function GetStoredFiles()
+               public function GetStoredFiles( $delay = LAST_DAY )
                {
-                       $nbfiles = 0;
-                       $query = "SELECT COUNT(FilenameId) AS nbfiles FROM Filename";
+                       $totalfiles = 0;
+
+                       $query = "SELECT SUM(JobFiles) AS stored_files FROM Job ";
+                       
+                       // Interval calculation
+                       $end_date   = mktime();
+                       $start_date = $end_date - $delay;
+                       
+                       $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'";
+                               
                        $result = $this->db_link->query( $query );
                        
                        if( !PEAR::isError($result) ) {
-                               $nbfiles = $result->fetchRow(DB_FETCHMODE_ASSOC);
-                               $nbfiles = $nbfiles['nbfiles'];
+                               $nbfiles        = $result->fetchRow(DB_FETCHMODE_ASSOC);
+                               $totalfiles = $totalfiles + $nbfiles['stored_files'];
                        }else{
-                               die("Unable to get protected files from catalog");
+                               die("Unable to get protected files from catalog <br />" . $result->getMessage() );
                        }
-                       return $nbfiles;
+                       
+                       return $totalfiles;
                }
                
                public function GetStoredBytes( $delay = LAST_DAY )
@@ -638,9 +651,8 @@ class Bweb extends DB {
                        $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 ) {
+                       if( $delay != ALL )
                                $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date'";
-                       }
                        
                        $result = $this->db_link->query( $query );