]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/baculum/protected/Class/JobManager.php
baculum: Assign Baculum copyright to Kern Sibbald
[bacula/bacula] / gui / baculum / protected / Class / JobManager.php
index 701122e7aa350f9513394b3ea1099a83edfa1eae..729b80615747abcd93ddd2a283ecd38c67a3c123 100644 (file)
@@ -1,25 +1,28 @@
 <?php
-/**
- * Bacula® - The Network Backup Solution
- * Baculum - Bacula web interface
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2014 Marcin Haba
+ * Copyright (C) 2013-2016 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
- * The main author of Bacula is Kern Sibbald, with contributions from many
- * others, a complete list can be found in the file AUTHORS.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
  *
  * You may use this file and others of this release according to the
  * license defined in the LICENSE file, which includes the Affero General
  * Public License, v3.0 ("AGPLv3") and some additional permissions and
  * terms pursuant to its AGPLv3 Section 7.
  *
- * Bacula® is a registered trademark of Kern Sibbald.
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
  */
  
 class JobManager extends TModule {
 
-       public function getJobs($limit) {
+       public function getJobs($limit, $allowedJobs = array()) {
                $criteria = new TActiveRecordCriteria;
                $order = 'JobId';
                $cfg = $this->Application->getModule('configuration');
@@ -31,6 +34,19 @@ class JobManager extends TModule {
                if(is_int($limit) && $limit > 0) {
                        $criteria->Limit = $limit;
                }
+
+               if (count($allowedJobs) > 0) {
+                       $where = array();
+                       $names = array();
+                       for ($i = 0; $i < count($allowedJobs); $i++) {
+                               $where[] = "name = :name$i";
+                               $names[":name$i"] = $allowedJobs[$i];
+                       }
+                       $criteria->Condition = implode(' OR ', $where);
+                       foreach($names as $name => $jobname) {
+                               $criteria->Parameters[$name] = $jobname;
+                       }
+               }
                return JobRecord::finder()->findAll($criteria);
        }
 
@@ -47,9 +63,18 @@ class JobManager extends TModule {
        }
 
        public function getRecentJobids($jobname, $clientid) {
-               $sql = "name='$jobname' AND clientid='$clientid' AND jobstatus IN ('T', 'W') AND level IN ('F', 'I', 'D') ORDER BY endtime DESC";
+               $sql = "name='$jobname' AND clientid='$clientid' AND jobstatus IN ('T', 'W') AND level IN ('F', 'I', 'D')";
                $finder = JobRecord::finder();
-               $jobs = $finder->findAll($sql);
+               $criteria = new TActiveRecordCriteria;
+               $order = 'EndTime';
+               $cfg = $this->Application->getModule('configuration');
+               $appCfg = $cfg->getApplicationConfig();
+               if($cfg->isPostgreSQLType($appCfg['db']['type'])) {
+                   $order = strtolower($order);
+               }
+               $criteria->OrdersBy[$order] = 'desc';
+               $criteria->Condition = $sql;
+               $jobs = $finder->findAll($criteria);
 
                $jobids = array();
                $waitForFull = false;
@@ -68,5 +93,25 @@ class JobManager extends TModule {
                }
                return $jobids;
        }
+
+       public function getJobTotals($allowedJobs = array()) {
+               $jobtotals = array('bytes' => 0, 'files' => 0);
+               $connection = JobRecord::finder()->getDbConnection();
+               $connection->setActive(true);
+
+               $where = '';
+               if (count($allowedJobs) > 0) {
+                       $where = " WHERE name='" . implode("' OR name='", $allowedJobs) . "'";
+               }
+
+               $sql = "SELECT sum(JobFiles) AS files, sum(JobBytes) AS bytes FROM Job $where";
+               $pdo = $connection->getPdoInstance();
+               $result = $pdo->query($sql);
+               $ret = $result->fetch();
+               $jobtotals['bytes'] = $ret['bytes'];
+               $jobtotals['files'] = $ret['files'];
+               $pdo = null;
+               return $jobtotals;
+       }
 }
 ?>