]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Improved countJobs() function in bweb class
authorDavide Franco <bacula-dev@dflc.ch>
Fri, 8 Jul 2011 17:38:30 +0000 (19:38 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:49:21 +0000 (14:49 +0200)
gui/bacula-web/includes/bweb.inc.php
gui/bacula-web/index.php
gui/bacula-web/jobs.php

index a847878117364676217f0c726a769a7e50232020..c1a57c5f1a027db492d5b5611a3a6c8601fc6d8b 100644 (file)
@@ -273,54 +273,55 @@ class Bweb extends DB
                
        }
        
-       public function CountJobs( $delay = LAST_DAY, $status = 'any' )
+       public function countJobs( $start_timestamp, $end_timestamp, $status = 'ALL', $level = 'ALL', $jobname = 'ALL', $client = 'ALL' )
        {
                $query                  = "SELECT COUNT(JobId) AS job_nb FROM Job ";
                $where_delay    = "";
-               $where_status   = "";
                
-               // Interval condition for SQL query
-               if( $delay != ALL ) {
-                       $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 );
-               
-                       $where_delay = "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+               // Calculate sql query interval
+               $start_date             = date( "Y-m-d H:i:s", $start_timestamp);       
+               $end_date               = date( "Y-m-d H:i:s", $end_timestamp);
+
+               switch( $this->driver )
+               {
+                       case 'sqlite':
+                       case 'mysql':
+                               $query .= "WHERE (EndTime BETWEEN '$start_date' AND '$end_date') ";
+                       break;
+                       case 'pgsql':
+                               $query .= "WHERE (EndTime BETWEEN timestamp '$start_date' AND timestamp '$end_date') ";
+                       break;
                }
                
-               if( $status != 'any' ) {
+               if( $status != 'ALL' ) {
                        switch( $status )
                        {
                                case 'completed':
-                                       $where_status = "JobStatus = 'T' ";
+                                       $query .= " AND JobStatus = 'T' ";
                                break;
                                case 'failed':
-                                       $where_status = "JobStatus IN ('f','E') ";
+                                       $query .= " AND  JobStatus IN ('f','E') ";
                                break;
                                case 'canceled':
-                                       $where_status = "JobStatus = 'A' ";
+                                       $query .= " AND JobStatus = 'A' ";
                                break;
                                case 'waiting':
-                                       $where_status = "JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
+                                       $query .= " AND JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
                                break;
                        } // end switch
                }
                
-               if( !empty($where_delay) )
-                       $query = $query . $where_delay . 'AND ' . $where_status;
-               else {
-                       if( !empty($where_status) )
-                               $query = $query . 'WHERE ' . $where_status;
+               if( $level != 'ALL' ) {
+                       $query .= " AND Level = '$level'";
                }
-                       
+
+               // Execute the query
                $jobs = $this->db_link->query( $query );
        
                if (PEAR::isError( $jobs ) ) {
                        $this->TriggerDBError("Unable to get last $status jobs number from catalog", $jobs);
                }else {
-                       $jobs = $jobs->fetchRow( DB_FETCHMODE_ASSOC ); 
+                       $jobs = $jobs->fetchRow(); 
                        return $jobs['job_nb'];
                }
        }
index 762cb52e136b77cfd8c491a54d88e339331bdd83..61fa605ee24d6c755b40deeaab3a3d24aa368b8d 100644 (file)
@@ -47,19 +47,15 @@ $dbSql->tpl->assign('clientes_totales',$nb_clients["nb_client"] );
 // Backup Job list for report.tpl and last_run_report.tpl
 $dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
 
-// Last 24 hours completed jobs number
-$dbSql->tpl->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) );
-
-// Last 24 hours failed jobs number
-$dbSql->tpl->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) );
-
-// Last 24 hours waiting jobs number
-$dbSql->tpl->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) );
-
-// Last 24 hours Job Levels
-$dbSql->tpl->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') );
-$dbSql->tpl->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') );
-$dbSql->tpl->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') );
+// Last 24 hours status (completed, failed and waiting jobs)
+$dbSql->tpl->assign( 'completed_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'completed' ) );
+$dbSql->tpl->assign( 'failed_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'failed' ) );
+$dbSql->tpl->assign( 'waiting_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'waiting' ) );
+
+// Last 24 hours jobs Level
+$dbSql->tpl->assign( 'incr_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_INCR) );
+$dbSql->tpl->assign( 'diff_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_DIFF) );
+$dbSql->tpl->assign( 'full_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_FULL) );
 
 // Last 24 hours Job status graph
 $data   = array();  
index c54dc2c9efe37c37aef90bcf1a3db69aed27de2e..5dbb2acf5d729949bbeb2862e4e0d6f78911eff1 100644 (file)
   
   // Count jobs
   if( isset( $_POST['status'] ) )
-       $total_jobs = $dbSql->CountJobs( ALL, $_POST['status'] );
+       $total_jobs = $dbSql->countJobs( FIRST_DAY, NOW, $_POST['status'] );
   else
-       $total_jobs = $dbSql->CountJobs( ALL );
+       $total_jobs = $dbSql->countJobs( FIRST_DAY, NOW );
   
   $dbSql->tpl->assign( 'total_jobs', $total_jobs );