Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
- Client Controller and Model refactored.
- Storage Controller and Model refactored.
- Pool Controller and Model refactored.
- Fileset Controller and Model refactored.
- Director Controller and Model refactored.
- Media Controller and Model refactored.
- Dashboard Controller and Model refactored.
- Job Controller and Model refactored.
- Restore Controller and Model refactored.

Signed-off-by: Frank Bergkemper <frank.bergkemper@dass-it.de>
  • Loading branch information
fbergkemper committed Nov 18, 2015
1 parent 9dc12d5 commit a3be545
Show file tree
Hide file tree
Showing 36 changed files with 1,162 additions and 826 deletions.
14 changes: 13 additions & 1 deletion module/Client/Module.php
Expand Up @@ -3,7 +3,7 @@
namespace Client;

use Client\Model\Client;
use Client\Model\ClientTable;
use Client\Model\ClientModel;

class Module
{
Expand All @@ -27,5 +27,17 @@ public function getConfig()
return include __DIR__ . '/config/module.config.php';
}

public function getServiceConfig()
{
return array(
'factories' => array(
'Client\Model\ClientModel' => function() {
$model = new ClientModel();
return $model;
}
)
);
}

}

74 changes: 26 additions & 48 deletions module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -33,79 +33,57 @@
class ClientController extends AbstractActionController
{

protected $clientTable;
protected $jobTable;
protected $director;
protected $clientModel;

public function indexAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {

$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$clients = $this->getClients();
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$clients = $this->getClientModel()->getClients();

$paginator = new Paginator(new ArrayAdapter($clients));
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage($limit);
$paginator = new Paginator(new ArrayAdapter($clients));
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'limit' => $limit,
)
);
return new ViewModel(
array(
'paginator' => $paginator,
'limit' => $limit,
)
);
}
else {
return $this->redirect()->toRoute('auth', array('action' => 'login'));
return $this->redirect()->toRoute('auth', array('action' => 'login'));
}
}

public function detailsAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {

$name = $this->params()->fromRoute('id');
$name = $this->params()->fromRoute('id');

return new ViewModel(
array(
'client' => $this->getClient($name),
'backups' => $this->getClientBackups($name, 10, "desc"),
)
);
return new ViewModel(
array(
'client' => $this->getClientModel()->getClient($name),
'backups' => $this->getClientModel()->getClientBackups($name, 10, "desc"),
)
);

}
else {
return $this->redirect()->toRoute('auth', array('action' => 'login'));
return $this->redirect()->toRoute('auth', array('action' => 'login'));
}
}

private function getClients()
public function getClientModel()
{
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command("llist clients", 2, null);
$clients = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $clients['result']['clients'];
}

private function getClient($client=null)
{
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command('llist client="'.$client.'"', 2, null);
$clients = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $clients['result']['clients'][0];
}

private function getClientBackups($client=null, $limit=10, $order="desc")
{
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command('llist backups client="'.$client.'" limit='.$limit.' order='.$order.'', 2, null);
if( preg_match("/Select/", $result) ) {
return null;
}
else {
$backups = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $backups['result']['backups'];
if(!$this->clientModel) {
$sm = $this->getServiceLocator();
$this->clientModel = $sm->get('Client\Model\ClientModel');
}
return $this->clientModel;
}

}
Expand Down
92 changes: 92 additions & 0 deletions module/Client/src/Client/Model/ClientModel.php
@@ -0,0 +1,92 @@
<?php

/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace Client\Model;

use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ClientModel implements ServiceLocatorAwareInterface
{
protected $serviceLocator;
protected $director;

public function __construct()
{
}

public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}

public function getServiceLocator()
{
return $this->serviceLocator;
}

public function getClients()
{
$cmd = 'llist clients';
$this->director = $this->getServiceLocator()->get('director');
$result = $this->director->send_command($cmd, 2, null);
$clients = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $clients['result']['clients'];
}

public function getClient($client=null)
{
if(isset($client)) {
$cmd = 'llist client="'.$client.'"';
$this->director = $this->getServiceLocator()->get('director');
$result = $this->director->send_command($cmd, 2, null);
$client = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $client['result']['clients'][0];
}
else {
return false;
}
}

public function getClientBackups($client=null, $limit=null, $order=null)
{
if(isset($client, $limit, $order)) {
$cmd = 'llist backups client="'.$client.'" limit='.$limit.' order='.$order.'';
$this->director = $this->getServiceLocator()->get('director');
$result = $this->director->send_command($cmd, 2, null);
if(preg_match("/Select/", $result)) {
return null;
}
else {
$backups = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $backups['result']['backups'];
}
}
else {
return false;
}
}

}
7 changes: 0 additions & 7 deletions module/Client/src/Client/Model/ClientTable.php

This file was deleted.

17 changes: 4 additions & 13 deletions module/Dashboard/Module.php
Expand Up @@ -3,9 +3,7 @@
namespace Dashboard;

use Dashboard\Model\Dashboard;
use Dashboard\Model\DashboardTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Dashboard\Model\DashboardModel;

class Module
{
Expand Down Expand Up @@ -33,16 +31,9 @@ public function getServiceConfig()
{
return array(
'factories' => array(
'Dashboard\Model\DashboardTable' => function($sm) {
$tableGateway = $sm->get('DashboardTableGateway');
$table = new DashboardTable($tableGateway);
return $table;
},
'DashboardTableGateway' => function($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Dashboard());
return new TableGateway('dashboard', $dbAdapter, null, $resultSetPrototype);
'Dashboard\Model\DashboardModel' => function() {
$model = new DashboardModel();
return $model;
},
),
);
Expand Down
83 changes: 35 additions & 48 deletions module/Dashboard/src/Dashboard/Controller/DashboardController.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -30,17 +30,18 @@

class DashboardController extends AbstractActionController
{
protected $dashboardModel;

public function indexAction()
{
if($_SESSION['bareos']['authenticated'] && $this->SessionTimeoutPlugin()->timeout()) {

return new ViewModel(
array(
'runningJobs' => $this->getJobCount("running", 1, null),
'waitingJobs' => $this->getJobCount("waiting", 1, null),
'successfulJobs' => $this->getJobCount("successful", 1, null),
'unsuccessfulJobs' => $this->getJobCount("unsuccessful", 1, null),
'runningJobs' => $this->getJobs("running", 1, null),
'waitingJobs' => $this->getJobs("waiting", 1, null),
'successfulJobs' => $this->getJobs("successful", 1, null),
'unsuccessfulJobs' => $this->getJobs("unsuccessful", 1, null),
)
);
}
Expand All @@ -49,29 +50,28 @@ public function indexAction()
}
}

private function getJobCount($status=null, $days=null, $hours=null)
private function getJobs($status=null, $days=1, $hours=null)
{
if($status != null) {
$director = $this->getServiceLocator()->get('director');
if($status == "running") {
$jobs_R = $this->getJobsByStatus('R', 1, null);
$jobs_l = $this->getJobsByStatus('l', 1, null);
$jobs_R = $this->getDashboardModel()->getJobs('R', $days, $hours);
$jobs_l = $this->getDashboardModel()->getJobs('l', $days, $hours);
$num = count($jobs_R) + count($jobs_l);
return $num;
}
elseif($status == "waiting") {
$jobs_F = $this->getJobsByStatus('F', 1, null);
$jobs_S = $this->getJobsByStatus('S', 1, null);
$jobs_s = $this->getJobsByStatus('s', 1, null);
$jobs_m = $this->getJobsByStatus('m', 1, null);
$jobs_M = $this->getJobsByStatus('M', 1, null);
$jobs_j = $this->getJobsByStatus('j', 1, null);
$jobs_c = $this->getJobsByStatus('c', 1, null);
$jobs_C = $this->getJobsByStatus('C', 1, null);
$jobs_d = $this->getJobsByStatus('d', 1, null);
$jobs_t = $this->getJobsByStatus('t', 1, null);
$jobs_p = $this->getJobsByStatus('p', 1, null);
$jobs_q = $this->getJobsByStatus('q', 1, null);
$jobs_F = $this->getDashboardModel()->getJobs('F', $days, $hours);
$jobs_S = $this->getDashboardModel()->getJobs('S', $days, $hours);
$jobs_s = $this->getDashboardModel()->getJobs('s', $days, $hours);
$jobs_m = $this->getDashboardModel()->getJobs('m', $days, $hours);
$jobs_M = $this->getDashboardModel()->getJobs('M', $days, $hours);
$jobs_j = $this->getDashboardModel()->getJobs('j', $days, $hours);
$jobs_c = $this->getDashboardModel()->getJobs('c', $days, $hours);
$jobs_C = $this->getDashboardModel()->getJobs('C', $days, $hours);
$jobs_d = $this->getDashboardModel()->getJobs('d', $days, $hours);
$jobs_t = $this->getDashboardModel()->getJobs('t', $days, $hours);
$jobs_p = $this->getDashboardModel()->getJobs('p', $days, $hours);
$jobs_q = $this->getDashboardModel()->getJobs('q', $days, $hours);
$num = count($jobs_F) + count($jobs_S) +
count($jobs_s) + count($jobs_m) +
count($jobs_M) + count($jobs_j) +
Expand All @@ -81,16 +81,16 @@ private function getJobCount($status=null, $days=null, $hours=null)
return $num;
}
elseif($status == "successful") {
$jobs_T = $this->getJobsByStatus('T', 1, null);
$jobs_W = $this->getJobsByStatus('W', 1, null);
$jobs_T = $this->getDashboardModel()->getJobs('T', $days, $hours);
$jobs_W = $this->getDashboardModel()->getJobs('W', $days, $hours);
$num = count($jobs_T) + count($jobs_W);
return $num;
}
elseif($status == "unsuccessful") {
$jobs_A = $this->getJobsByStatus('A', 1, null);
$jobs_E = $this->getJobsByStatus('E', 1, null);
$jobs_e = $this->getJobsByStatus('e', 1, null);
$jobs_f = $this->getJobsByStatus('f', 1, null);
$jobs_A = $this->getDashboardModel()->getJobs('A', $days, $hours);
$jobs_E = $this->getDashboardModel()->getJobs('E', $days, $hours);
$jobs_e = $this->getDashboardModel()->getJobs('e', $days, $hours);
$jobs_f = $this->getDashboardModel()->getJobs('f', $days, $hours);
$num = count($jobs_A) + count($jobs_E) + count($jobs_e) + count($jobs_f);
return $num;
}
Expand All @@ -103,26 +103,13 @@ private function getJobCount($status=null, $days=null, $hours=null)
}
}

private function getJobsByStatus($status=null, $days=null, $hours=null)
{
if($status != null) {
$director = $this->getServiceLocator()->get('director');
if($days != null) {
$result = $director->send_command('llist jobs jobstatus="'.$status.'" days="'.$days.'"', 2, null);
}
elseif($hours != null) {
$result = $director->send_command('llist jobs jobstatus="'.$status.'" hours="'.$hours.'"', 2, null);
}
else {
$result = $director->send_command('llist jobs jobstatus="'.$status.'"', 2, null);
}
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $jobs['result']['jobs'];
}
else {
return null;
}
}
public function getDashboardModel()
{
if(!$this->dashboardModel) {
$sm = $this->getServiceLocator();
$this->dashboardModel = $sm->get('Dashboard\Model\DashboardModel');
}
return $this->dashboardModel;
}

}

0 comments on commit a3be545

Please sign in to comment.