From f10e03c3ca8cf4c61d5028670496a466c2485209 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Fri, 11 Mar 2011 13:52:45 +0100 Subject: [PATCH] bacula-web: Improved GetStoredFiles() function adding interval delay - Improved GetStoredFiles() function with a new parameter that allow to specify interval. --- gui/bacula-web/bweb.inc.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php index 3d756a246f..95f6a77f0d 100644 --- a/gui/bacula-web/bweb.inc.php +++ b/gui/bacula-web/bweb.inc.php @@ -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
" . $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 ); -- 2.39.5