From: Davide Franco Date: Fri, 11 Mar 2011 12:52:45 +0000 (+0100) Subject: bacula-web: Improved GetStoredFiles() function adding interval delay X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f10e03c3ca8cf4c61d5028670496a466c2485209;p=bacula%2Fbacula bacula-web: Improved GetStoredFiles() function adding interval delay - Improved GetStoredFiles() function with a new parameter that allow to specify interval. --- 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 );