diff --git a/module/Client/Module.php b/module/Client/Module.php index ffc9876c..eab858c9 100644 --- a/module/Client/Module.php +++ b/module/Client/Module.php @@ -3,7 +3,7 @@ namespace Client; use Client\Model\Client; -use Client\Model\ClientTable; +use Client\Model\ClientModel; class Module { @@ -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; + } + ) + ); + } + } diff --git a/module/Client/src/Client/Controller/ClientController.php b/module/Client/src/Client/Controller/ClientController.php index eee7eabc..219e6d74 100644 --- a/module/Client/src/Client/Controller/ClientController.php +++ b/module/Client/src/Client/Controller/ClientController.php @@ -33,30 +33,28 @@ 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')); } } @@ -64,48 +62,28 @@ 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; } } diff --git a/module/Client/src/Client/Model/ClientModel.php b/module/Client/src/Client/Model/ClientModel.php new file mode 100644 index 00000000..b56c3fa8 --- /dev/null +++ b/module/Client/src/Client/Model/ClientModel.php @@ -0,0 +1,92 @@ +. + * + */ + +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; + } + } + +} diff --git a/module/Client/src/Client/Model/ClientTable.php b/module/Client/src/Client/Model/ClientTable.php deleted file mode 100644 index 760d522a..00000000 --- a/module/Client/src/Client/Model/ClientTable.php +++ /dev/null @@ -1,7 +0,0 @@ - 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; }, ), ); diff --git a/module/Dashboard/src/Dashboard/Controller/DashboardController.php b/module/Dashboard/src/Dashboard/Controller/DashboardController.php index ddc113a5..8d789d4e 100644 --- a/module/Dashboard/src/Dashboard/Controller/DashboardController.php +++ b/module/Dashboard/src/Dashboard/Controller/DashboardController.php @@ -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 @@ -30,6 +30,7 @@ class DashboardController extends AbstractActionController { + protected $dashboardModel; public function indexAction() { @@ -37,10 +38,10 @@ public function indexAction() 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), ) ); } @@ -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) + @@ -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; } @@ -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; + } } - diff --git a/module/Dashboard/src/Dashboard/Model/DashboardModel.php b/module/Dashboard/src/Dashboard/Model/DashboardModel.php new file mode 100644 index 00000000..1aadb448 --- /dev/null +++ b/module/Dashboard/src/Dashboard/Model/DashboardModel.php @@ -0,0 +1,72 @@ +. + * + */ + +namespace Dashboard\Model; + +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class DashboardModel 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 getJobs($status=null, $days=null, $hours=null) + { + if(isset($status)) { + $this->director = $this->getServiceLocator()->get('director'); + if(isset($days)) { + $cmd = 'llist jobs jobstatus='.$status.' days='.$days.''; + } + elseif(isset($hours)) { + $cmd = 'llist jobs jobstatus='.$status.' hours='.$hours.''; + } + else { + $cmd = 'llist jobs jobstatus='.$status.''; + } + $result = $this->director->send_command($cmd, 2, null); + $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $jobs['result']['jobs']; + } + else { + return false; + } + } + +} diff --git a/module/Dashboard/src/Dashboard/Model/DashboardTable.php b/module/Dashboard/src/Dashboard/Model/DashboardTable.php deleted file mode 100644 index 0ed1dddc..00000000 --- a/module/Dashboard/src/Dashboard/Model/DashboardTable.php +++ /dev/null @@ -1,31 +0,0 @@ -. - * - */ - -namespace Dashboard\Model; - -class DashboardTable -{ -} - diff --git a/module/Director/Module.php b/module/Director/Module.php index 4fac226c..76c421cc 100644 --- a/module/Director/Module.php +++ b/module/Director/Module.php @@ -3,9 +3,7 @@ namespace Director; use Director\Model\Director; -use Director\Model\DirectorTable; -use Zend\Db\ResultSet\ResultSet; -use Zend\Db\TableGateway\TableGateway; +use Director\Model\DirectorModel; class Module { @@ -33,20 +31,11 @@ public function getServiceConfig() { return array( 'factories' => array( - 'Director\Model\DirectorTable' => function($sm) - { - $tableGateway = $sm->get('DirectorTableGateway'); - $table = new DirectorTable($tableGateway); - return $table; - }, - 'DirectorTableGateway' => function($sm) - { - $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); - $resultSetPrototype = new ResultSet(); - $resultSetPrototype->setArrayObjectPrototype(new Director()); - return new TableGateway('director', $dbAdapter, null, $resultSetPrototype); - }, - ), + 'Director\Model\DirectorModel' => function() { + $model = new DirectorModel(); + return $model; + } + ) ); } diff --git a/module/Director/src/Director/Controller/DirectorController.php b/module/Director/src/Director/Controller/DirectorController.php index 01912831..2d036038 100644 --- a/module/Director/src/Director/Controller/DirectorController.php +++ b/module/Director/src/Director/Controller/DirectorController.php @@ -31,79 +31,79 @@ class DirectorController extends AbstractActionController { - - protected $director = null; - protected $directorOutput = array(); + protected $directorModel; public function indexAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $cmd = "status director"; - $this->director = $this->getServiceLocator()->get('director'); - return new ViewModel(array( - 'directorOutput' => $this->director->send_command($cmd), - )); + return new ViewModel(array( + 'directorOutput' => $this->getDirectorModel()->getDirectorStatus() + ) + ); } else { - return $this->redirect()->toRoute('auth', array('action' => 'login')); + return $this->redirect()->toRoute('auth', array('action' => 'login')); } } public function messagesAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $cmd = "messages"; - $this->director = $this->getServiceLocator()->get('director'); - return new ViewModel(array( - 'directorOutput' => $this->director->send_command($cmd), - )); - } + return new ViewModel(array( + 'directorOutput' => $this->getDirectorModel()->getDirectorMessages() + ) + ); + } else { - return $this->redirect()->toRoute('auth', array('action' => 'login')); + return $this->redirect()->toRoute('auth', array('action' => 'login')); } } public function scheduleAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $cmd = "show schedule"; - $this->director = $this->getServiceLocator()->get('director'); - return new ViewModel(array( - 'directorOutput' => $this->director->send_command($cmd), - )); + return new ViewModel(array( + 'directorOutput' => $this->getDirectorModel()->getDirectorSchedules() + ) + ); } else { - return $this->redirect()->toRoute('auth', array('action' => 'login')); + return $this->redirect()->toRoute('auth', array('action' => 'login')); } } public function schedulerstatusAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $cmd = "status scheduler"; - $this->director = $this->getServiceLocator()->get('director'); - return new ViewModel(array( - 'directorOutput' => $this->director->send_command($cmd), - )); + return new ViewModel(array( + 'directorOutput' => $this->getDirectorModel()->getDirectorSchedulerStatus() + ) + ); } else { - return $this->redirect()->toRoute('auth', array('action' => 'login')); + return $this->redirect()->toRoute('auth', array('action' => 'login')); } } public function versionAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $cmd = "version"; - $this->director = $this->getServiceLocator()->get('director'); - return new ViewModel(array( - 'directorOutput' => $this->director->send_command($cmd), - )); + return new ViewModel(array( + 'directorOutput' => $this->getDirectorModel()->getDirectorVersion() + ) + ); } else { - return $this->redirect()->toRoute('auth', array('action' => 'login')); + return $this->redirect()->toRoute('auth', array('action' => 'login')); } } + public function getDirectorModel() + { + if(!$this->directorModel) { + $sm = $this->getServiceLocator(); + $this->directorModel = $sm->get('Director\Model\DirectorModel'); + } + return $this->directorModel; + } } - diff --git a/module/Director/src/Director/Model/DirectorModel.php b/module/Director/src/Director/Model/DirectorModel.php new file mode 100644 index 00000000..095475ec --- /dev/null +++ b/module/Director/src/Director/Model/DirectorModel.php @@ -0,0 +1,89 @@ +. + * + */ + +namespace Director\Model; + +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class DirectorModel 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 getDirectorStatus() + { + $cmd = 'status director'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } + + public function getDirectorMessages() + { + $cmd = 'messages'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } + + public function getDirectorSchedules() + { + $cmd = 'show schedule'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } + + public function getDirectorSchedulerStatus() + { + $cmd = 'status scheduler'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } + + public function getDirectorVersion() + { + $cmd = 'version'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } +} diff --git a/module/Director/src/Director/Model/DirectorTable.php b/module/Director/src/Director/Model/DirectorTable.php deleted file mode 100644 index 9dffbd95..00000000 --- a/module/Director/src/Director/Model/DirectorTable.php +++ /dev/null @@ -1,38 +0,0 @@ -. - * - */ - -namespace Director\Model; - -//use Zend\Db\TableGateway\TableGateway; - -class DirectorTable -{ - - public function __construct() - { - } - -} - diff --git a/module/Fileset/Module.php b/module/Fileset/Module.php index 1521b014..402e0244 100644 --- a/module/Fileset/Module.php +++ b/module/Fileset/Module.php @@ -3,7 +3,7 @@ namespace Fileset; use Fileset\Model\Fileset; -use Fileset\Model\FilesetTable; +use Fileset\Model\FilesetModel; class Module { @@ -27,5 +27,16 @@ public function getConfig() return include __DIR__ . '/config/module.config.php'; } -} + public function getServiceConfig() + { + return array( + 'factories' => array( + 'Fileset\Model\FilesetModel' => function() { + $model = new FilesetModel(); + return $model; + } + ) + ); + } +} diff --git a/module/Fileset/src/Fileset/Controller/FilesetController.php b/module/Fileset/src/Fileset/Controller/FilesetController.php index 19353a80..59239935 100644 --- a/module/Fileset/src/Fileset/Controller/FilesetController.php +++ b/module/Fileset/src/Fileset/Controller/FilesetController.php @@ -33,13 +33,13 @@ class FilesetController extends AbstractActionController { - protected $director; + protected $filesetModel; public function indexAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $filesets = $this->getFilesets(); + $filesets = $this->getFilesetModel()->getFilesets(); $page = (int) $this->params()->fromQuery('page', 1); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; @@ -64,7 +64,7 @@ public function detailsAction() if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { $id = $this->params()->fromRoute('id', 0); - $fileset = $this->getFileset($id); + $fileset = $this->getFilesetModel()->getFileset($id); return new ViewModel( array( @@ -77,19 +77,13 @@ public function detailsAction() } } - private function getFilesets() + public function getFilesetModel() { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command("list filesets", 2, null); - $filesets = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $filesets['result']['filesets']; - } - - private function getFileset($id) { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command("llist fileset filesetid=".$id, 2, null); - $fileset = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $fileset['result']['filesets'][0]; + if(!$this->filesetModel) { + $sm = $this->getServiceLocator(); + $this->filesetModel = $sm->get('Fileset\Model\FilesetModel'); + } + return $this->filesetModel; } } diff --git a/module/Fileset/src/Fileset/Model/FilesetModel.php b/module/Fileset/src/Fileset/Model/FilesetModel.php new file mode 100644 index 00000000..e168cb75 --- /dev/null +++ b/module/Fileset/src/Fileset/Model/FilesetModel.php @@ -0,0 +1,72 @@ +. + * + */ + +namespace Fileset\Model; + +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class FilesetModel 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 getFilesets() + { + $cmd = 'list filesets'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $filesets = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $filesets['result']['filesets']; + } + + public function getFileset($id) + { + if(isset($id)) { + $cmd = 'llist fileset filesetid='.$id.''; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $fileset = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $fileset['result']['filesets'][0]; + } + else { + return false; + } + } +} diff --git a/module/Fileset/src/Fileset/Model/FilesetTable.php b/module/Fileset/src/Fileset/Model/FilesetTable.php deleted file mode 100644 index e973575d..00000000 --- a/module/Fileset/src/Fileset/Model/FilesetTable.php +++ /dev/null @@ -1,31 +0,0 @@ -. - * - */ - -namespace Fileset\Model; - -class FilesetTable -{ -} - diff --git a/module/Job/Module.php b/module/Job/Module.php index af164203..aa79f097 100644 --- a/module/Job/Module.php +++ b/module/Job/Module.php @@ -3,7 +3,7 @@ namespace Job; use Job\Model\Job; -use Job\Model\JobTable; +use Job\Model\JobModel; class Module { @@ -27,4 +27,16 @@ public function getConfig() return include __DIR__ . '/config/module.config.php'; } + public function getServiceConfig() + { + return array( + 'factories' => array( + 'Job\Model\JobModel' => function() { + $model = new JobModel(); + return $model; + } + ) + ); + } + } diff --git a/module/Job/src/Job/Controller/JobController.php b/module/Job/src/Job/Controller/JobController.php index b7fac729..ac49cd1c 100644 --- a/module/Job/src/Job/Controller/JobController.php +++ b/module/Job/src/Job/Controller/JobController.php @@ -34,15 +34,13 @@ class JobController extends AbstractActionController { - protected $jobTable; - protected $bconsoleOutput = array(); - protected $director = null; + protected $jobModel; public function indexAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $jobs = $this->getJobs(); + $jobs = $this->getJobModel()->getJobs(); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; $page = (int) $this->params()->fromQuery('page'); @@ -67,8 +65,8 @@ public function detailsAction() if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { $jobid = (int) $this->params()->fromRoute('id', 0); - $job = $this->getJob($jobid); - $joblog = $this->getJobLog($jobid); + $job = $this->getJobModel()->getJob($jobid); + $joblog = $this->getJobModel()->getJobLog($jobid); return new ViewModel(array( 'job' => $job, @@ -84,8 +82,8 @@ public function runningAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $jobs_R = $this->getJobsByStatus('R', null, null); - $jobs_l = $this->getJobsByStatus('l', null, null); + $jobs_R = $this->getJobModel()->getJobsByStatus('R', null, null); + $jobs_l = $this->getJobModel()->getJobsByStatus('l', null, null); $jobs = array_merge($jobs_R, $jobs_l); @@ -113,18 +111,18 @@ public function waitingAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $jobs_F = $this->getJobsByStatus('F', null, null); - $jobs_S = $this->getJobsByStatus('S', null, null); - $jobs_m = $this->getJobsByStatus('m', null, null); - $jobs_M = $this->getJobsByStatus('M', null, null); - $jobs_s = $this->getJobsByStatus('s', null, null); - $jobs_j = $this->getJobsByStatus('j', null, null); - $jobs_c = $this->getJobsByStatus('c', null, null); - $jobs_d = $this->getJobsByStatus('d', null, null); - $jobs_t = $this->getJobsByStatus('t', null, null); - $jobs_p = $this->getJobsByStatus('p', null, null); - $jobs_q = $this->getJobsByStatus('q', null, null); - $jobs_C = $this->getJobsByStatus('C', null, null); + $jobs_F = $this->getJobModel()->getJobsByStatus('F', null, null); + $jobs_S = $this->getJobModel()->getJobsByStatus('S', null, null); + $jobs_m = $this->getJobModel()->getJobsByStatus('m', null, null); + $jobs_M = $this->getJobModel()->getJobsByStatus('M', null, null); + $jobs_s = $this->getJobModel()->getJobsByStatus('s', null, null); + $jobs_j = $this->getJobModel()->getJobsByStatus('j', null, null); + $jobs_c = $this->getJobModel()->getJobsByStatus('c', null, null); + $jobs_d = $this->getJobModel()->getJobsByStatus('d', null, null); + $jobs_t = $this->getJobModel()->getJobsByStatus('t', null, null); + $jobs_p = $this->getJobModel()->getJobsByStatus('p', null, null); + $jobs_q = $this->getJobModel()->getJobsByStatus('q', null, null); + $jobs_C = $this->getJobModel()->getJobsByStatus('C', null, null); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; $page = (int) $this->params()->fromQuery('page', 1); @@ -157,10 +155,10 @@ public function unsuccessfulAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $jobs_A = $this->getJobsByStatus('A', 1, null); // Canceled jobs last 24h - $jobs_E = $this->getJobsByStatus('E', 1, null); // - $jobs_e = $this->getJobsByStatus('e', 1, null); // - $jobs_f = $this->getJobsByStatus('f', 1, null); // + $jobs_A = $this->getJobModel()->getJobsByStatus('A', 1, null); // Canceled jobs last 24h + $jobs_E = $this->getJobModel()->getJobsByStatus('E', 1, null); // + $jobs_e = $this->getJobModel()->getJobsByStatus('e', 1, null); // + $jobs_f = $this->getJobModel()->getJobsByStatus('f', 1, null); // $jobs = array_merge($jobs_A, $jobs_E, $jobs_e, $jobs_f); $page = (int) $this->params()->fromQuery('page', 1); @@ -187,8 +185,8 @@ public function successfulAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $jobs_T = $this->getJobsByStatus('T', 1, null); // Terminated - $jobs_W = $this->getJobsByStatus('W', 1, null); // Terminated with warnings + $jobs_T = $this->getJobModel()->getJobsByStatus('T', 1, null); // Terminated + $jobs_W = $this->getJobModel()->getJobsByStatus('W', 1, null); // Terminated with warnings $jobs = array_merge($jobs_T, $jobs_W); $page = (int) $this->params()->fromQuery('page', 1); @@ -215,11 +213,10 @@ public function rerunAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { $jobid = (int) $this->params()->fromRoute('id', 0); - $cmd = "rerun jobid=" . $jobid . " yes"; - $this->director = $this->getServiceLocator()->get('director'); + $result = $this->getJobModel()->rerunJob($jobid); return new ViewModel( array( - 'bconsoleOutput' => $this->director->send_command($cmd), + 'bconsoleOutput' => $result, 'jobid' => $jobid, ) ); @@ -233,11 +230,10 @@ public function cancelAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { $jobid = (int) $this->params()->fromRoute('id', 0); - $cmd = "cancel jobid=" . $jobid . " yes"; - $this->director = $this->getServiceLocator()->get('director'); + $result = $this->getJobModel()->cancelJob($jobid); return new ViewModel( array( - 'bconsoleOutput' => $this->director->send_command($cmd) + 'bconsoleOutput' => $result ) ); } @@ -250,7 +246,7 @@ public function runAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $jobs = $this->getDefinedBackupJobs(); + $jobs = $this->getJobModel()->getBackupJobs(); $page = (int) $this->params()->fromQuery('page', 1); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; @@ -274,16 +270,11 @@ public function runAction() public function queueAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - if($this->params()->fromQuery('job')) { - $jobname = $this->params()->fromQuery('job'); - } - else { - $jobname = null; - } - + $jobname = $this->params()->fromQuery('job'); + $result = $this->getJobModel()->runJob($jobname); return new ViewModel( array( - 'result' => $this->queueJob($jobname) + 'result' => $result ) ); } @@ -292,68 +283,12 @@ public function queueAction() } } - private function getJobs() - { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command('llist jobs', 2, null); - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return array_reverse($jobs['result']['jobs']); - } - - private function getJobsByStatus($status=null, $days=null, $hours=null) + public function getJobModel() { - if($status != null) { - $director = $this->getServiceLocator()->get('director'); - if($days != null && $hours == null) { - $result = $director->send_command('llist jobs jobstatus='.$status.' days='.$days, 2, null); - } - elseif($hours != null && $days == 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 array_reverse($jobs['result']['jobs']); - } - else { - return null; + if(!$this->jobModel) { + $sm = $this->getServiceLocator(); + $this->jobModel = $sm->get('Job\Model\JobModel'); } + return $this->jobModel; } - - private function getDefinedBackupJobs() - { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command(".jobs type=B", 2, null); - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $jobs['result']['jobs']; - } - - private function getJob($jobid) - { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command('llist jobid="'.$jobid.'"', 2, null); - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $jobs['result']['jobs'][0]; - } - - private function getJobLog($jobid) - { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command('list joblog jobid="'.$jobid.'"', 2, null); - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $jobs['result']['joblog']; - } - - private function queueJob($jobname=null) - { - $result = ""; - if($jobname != null) { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command('run job="'.$jobname.'" yes'); - } - return $result; - } - } - diff --git a/module/Job/src/Job/Model/JobModel.php b/module/Job/src/Job/Model/JobModel.php new file mode 100644 index 00000000..0ab8da56 --- /dev/null +++ b/module/Job/src/Job/Model/JobModel.php @@ -0,0 +1,156 @@ +. + * + */ + +namespace Job\Model; + +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class JobModel implements ServiceLocatorAwareInterface +{ + protected $serviceLocator; + protected $director; + + public function __constructor() + { + } + + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + } + + public function getServiceLocator() + { + return $this->serviceLocator; + } + + public function getJobs() + { + $cmd = 'llist jobs'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return array_reverse($jobs['result']['jobs']); + } + + public function getJobsByStatus($status=null, $days=null, $hours=null) + { + if(isset($status)) { + if(isset($days)) { + $cmd = 'llist jobs jobstatus='.$status.' days='.$days.''; + } + elseif(isset($hours)) { + $cmd = 'llist jobs jobstatus='.$status.' hours='.$hours.''; + } + else { + $cmd = 'llist jobs jobstatus='.$status.''; + } + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return array_reverse($jobs['result']['jobs']); + } + else { + return false; + } + } + + public function getJob($id=null) + { + if(isset($id)) { + $cmd = 'llist jobid='.$id.''; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $job = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $job['result']['jobs'][0]; + } + else { + return false; + } + } + + public function getJobLog($id=null) + { + if(isset($id)) { + $cmd = 'list joblog jobid='.$id.''; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $log = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $log['result']['joblog']; + } + else { + return false; + } + } + + public function getBackupJobs() + { + $cmd = '.jobs type=B'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $jobs['result']['jobs']; + } + + public function runJob($name=null) + { + if(isset($name)) { + $cmd = 'run job="'.$name.'" yes'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } + else { + return false; + } + } + + public function rerunJob($id=null) + { + if(isset($id)) { + $cmd = 'rerun jobid='.$id.' yes'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } + else { + return false; + } + } + + public function cancelJob($id=null) + { + if(isset($id)) { + $cmd = 'cancel jobid='.$id.' yes'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 0, null); + return $result; + } + else { + return false; + } + } +} diff --git a/module/Job/src/Job/Model/JobTable.php b/module/Job/src/Job/Model/JobTable.php deleted file mode 100644 index 1ebacec0..00000000 --- a/module/Job/src/Job/Model/JobTable.php +++ /dev/null @@ -1,30 +0,0 @@ -. - * - */ - -namespace Job\Model; - -class JobTable -{ -} diff --git a/module/Media/Module.php b/module/Media/Module.php index 7aaf8b1e..78a8b3b2 100644 --- a/module/Media/Module.php +++ b/module/Media/Module.php @@ -3,7 +3,7 @@ namespace Media; use Media\Model\Media; -use Media\Model\MediaTable; +use Media\Model\MediaModel; class Module { @@ -27,5 +27,17 @@ public function getConfig() return include __DIR__ . '/config/module.config.php'; } + public function getServiceConfig() + { + return array( + 'factories' => array( + 'Media\Model\MediaModel' => function() { + $model = new MediaModel(); + return $model; + } + ) + ); + } + } diff --git a/module/Media/src/Media/Controller/MediaController.php b/module/Media/src/Media/Controller/MediaController.php index b7b12dd5..d6e662b2 100644 --- a/module/Media/src/Media/Controller/MediaController.php +++ b/module/Media/src/Media/Controller/MediaController.php @@ -32,12 +32,13 @@ class MediaController extends AbstractActionController { + protected $mediaModel; public function indexAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $volumes = $this->getVolumes(); + $volumes = $this->getMediaModel()->getVolumes(); $page = (int) $this->params()->fromQuery('page'); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; @@ -63,7 +64,7 @@ public function detailsAction() if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { $volumename = $this->params()->fromRoute('id'); - $volume = $this->getVolume($volumename); + $volume = $this->getMediaModel()->getVolume($volumename); return new ViewModel(array( 'media' => $volume, @@ -75,21 +76,13 @@ public function detailsAction() } } - private function getVolumes() + public function getMediaModel() { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command("llist volumes all", 2, null); - $pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $pools['result']['volumes']; - } - - private function getVolume($volume) - { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command('llist volume="'.$volume.'"', 2, null); - $pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $pools['result']['volume']; + if(!$this->mediaModel) { + $sm = $this->getServiceLocator(); + $this->mediaModel = $sm->get('Media\Model\MediaModel'); + } + return $this->mediaModel; } } - diff --git a/module/Media/src/Media/Model/MediaModel.php b/module/Media/src/Media/Model/MediaModel.php new file mode 100644 index 00000000..c2c83a0e --- /dev/null +++ b/module/Media/src/Media/Model/MediaModel.php @@ -0,0 +1,72 @@ +. + * + */ + +namespace Media\Model; + +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class MediaModel 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 getVolumes() + { + $cmd = 'llist volumes all'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $volumes = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $volumes['result']['volumes']; + } + + public function getVolume($volume=null) + { + if(isset($volume)) { + $cmd = 'llist volume="'.$volume.'"'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $volume = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $volume['result']['volume']; + } + else { + return false; + } + } +} diff --git a/module/Media/src/Media/Model/MediaTable.php b/module/Media/src/Media/Model/MediaTable.php deleted file mode 100644 index 9c83950c..00000000 --- a/module/Media/src/Media/Model/MediaTable.php +++ /dev/null @@ -1,31 +0,0 @@ -. - * - */ - -namespace Media\Model; - -class MediaTable -{ -} - diff --git a/module/Pool/Module.php b/module/Pool/Module.php index adff902c..0c094830 100644 --- a/module/Pool/Module.php +++ b/module/Pool/Module.php @@ -3,7 +3,7 @@ namespace Pool; use Pool\Model\Pool; -use Pool\Model\PoolTable; +use Pool\Model\PoolModel; class Module { @@ -27,5 +27,17 @@ public function getConfig() return include __DIR__ . '/config/module.config.php'; } + public function getServiceConfig() + { + return array( + 'factories' => array( + 'Pool\Model\PoolModel' => function() { + $model = new PoolModel(); + return $model; + } + ) + ); + } + } diff --git a/module/Pool/src/Pool/Controller/PoolController.php b/module/Pool/src/Pool/Controller/PoolController.php index 0651adc5..dec91ff8 100644 --- a/module/Pool/src/Pool/Controller/PoolController.php +++ b/module/Pool/src/Pool/Controller/PoolController.php @@ -32,12 +32,13 @@ class PoolController extends AbstractActionController { + protected $poolModel; public function indexAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $pools = $this->getPools(); + $pools = $this->getPoolModel()->getPools(); $page = (int) $this->params()->fromQuery('page'); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; @@ -48,7 +49,6 @@ public function indexAction() return new ViewModel( array( 'limit' => $limit, - //'pools' => $pools, 'paginator' => $paginator, ) ); @@ -68,8 +68,8 @@ public function detailsAction() $page = $this->params()->fromQuery('page'); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - $pool = $this->getPool($poolname); - $media = $this->getPoolMedia($poolname); + $pool = $this->getPoolModel()->getPool($poolname); + $media = $this->getPoolModel()->getPoolMedia($poolname); $paginator = new Paginator(new ArrayAdapter($media)); $paginator->setCurrentPageNumber($page); @@ -80,7 +80,6 @@ public function detailsAction() 'poolname' => $poolname, 'limit' => $limit, 'pool' => $pool, - //'media' => $media, 'paginator' => $paginator, ) ); @@ -90,29 +89,12 @@ public function detailsAction() } } - private function getPool($pool) + public function getPoolModel() { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command("llist pool=".$pool, 2, null); - $pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $pools['result']['pools'][0]; - } - - private function getPools() - { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command("llist pools", 2, null); - $pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $pools['result']['pools']; - } - - private function getPoolMedia($pool) - { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command("llist media pool=".$pool, 2, null); - $media = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $media['result']['volumes']; + if(!$this->poolModel) { + $sm = $this->getServiceLocator(); + $this->poolModel = $sm->get('Pool\Model\PoolModel'); + } + return $this->poolModel; } - } - diff --git a/module/Pool/src/Pool/Model/PoolModel.php b/module/Pool/src/Pool/Model/PoolModel.php new file mode 100644 index 00000000..2ff87dba --- /dev/null +++ b/module/Pool/src/Pool/Model/PoolModel.php @@ -0,0 +1,86 @@ +. + * + */ + +namespace Pool\Model; + +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class PoolModel 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 getPools() + { + $cmd = 'llist pools'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $pools = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $pools['result']['pools']; + } + + public function getPool($pool=null) + { + if(isset($pool)) { + $cmd = 'llist pool="'.$pool.'"'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $pool = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $pool['result']['pools'][0]; + } + else { + return false; + } + } + + public function getPoolMedia($pool=null) + { + if(isset($pool)) { + $cmd = 'llist media pool="'.$pool.'"'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $media = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $media['result']['volumes']; + } + else { + return false; + } + } +} diff --git a/module/Pool/src/Pool/Model/PoolTable.php b/module/Pool/src/Pool/Model/PoolTable.php deleted file mode 100644 index 15c9fd6e..00000000 --- a/module/Pool/src/Pool/Model/PoolTable.php +++ /dev/null @@ -1,30 +0,0 @@ -. - * - */ - -namespace Pool\Model; - -class PoolTable -{ -} diff --git a/module/Restore/Module.php b/module/Restore/Module.php index c43c6a1e..7cd53d30 100644 --- a/module/Restore/Module.php +++ b/module/Restore/Module.php @@ -3,14 +3,12 @@ namespace Restore; use Restore\Model\Restore; -use Restore\Model\RestoreTable; -use Zend\Db\ResultSet\ResultSet; -use Zend\Db\TableGateway\TableGateway; +use Restore\Model\RestoreModel; class Module { - public function getAutoloaderConfig() + public function getAutoloaderConfig() { return array( 'Zend\Loader\ClassMapAutoloader' => array( @@ -24,27 +22,19 @@ public function getAutoloaderConfig() ); } - public function getConfig() + public function getConfig() { return include __DIR__ . '/config/module.config.php'; } - public function getServiceConfig() + public function getServiceConfig() { return array( 'factories' => array( - 'Restore\Model\RestoreTable' => function($sm) + 'Restore\Model\RestoreModel' => function() { - $tableGateway = $sm->get('RestoreTableGateway'); - $table = new RestoreTable($tableGateway); - return $table; - }, - 'RestoreTableGateway' => function($sm) - { - $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); - $resultSetPrototype = new ResultSet(); - $resultSetPrototype->setArrayObjectPrototype(new Restore()); - return new TableGateway('restore', $dbAdapter, null, $resultSetPrototype); + $model = new RestoreModel(); + return $model; }, ), ); diff --git a/module/Restore/src/Restore/Controller/RestoreController.php b/module/Restore/src/Restore/Controller/RestoreController.php index 95fd1a13..6e8ab366 100644 --- a/module/Restore/src/Restore/Controller/RestoreController.php +++ b/module/Restore/src/Restore/Controller/RestoreController.php @@ -34,7 +34,8 @@ class RestoreController extends AbstractActionController { - protected $restore_params = array(); + protected $restoreModel; + protected $restore_params; /** * @@ -46,30 +47,37 @@ public function indexAction() $this->getRestoreParams(); if($this->restore_params['client'] == null) { - $client = array_pop($this->getClients(2)); + $clients = $this->getRestoreModel()->getClients(); + $client = array_pop($clients); $this->restore_params['client'] = $client['name']; } if($this->restore_params['type'] == "client" && $this->restore_params['jobid'] == null) { - $latestbackup = $this->getClientBackups($this->restore_params['client'], "any", "desc", 1); - $this->restore_params['jobid'] = $latestbackup[0]['jobid']; + $latestbackup = $this->getRestoreModel()->getClientBackups($this->restore_params['client'], "any", "desc", 1); + if(empty($latestbackup)) { + $this->restore_params['jobid'] = null; + } + else { + $this->restore_params['jobid'] = $latestbackup[0]['jobid']; + } } if(isset($this->restore_params['mergejobs']) && $this->restore_params['mergejobs'] == 1) { $jobids = $this->restore_params['jobid']; } else { - $jobids = $this->getJobIds($this->restore_params['jobid'], $this->restore_params['mergefilesets']); + $jobids = $this->getRestoreModel()->getJobIds($this->restore_params['jobid'], $this->restore_params['mergefilesets']); + $this->restore_params['jobids'] = $jobids; } if($this->restore_params['type'] == "client") { - $backups = $this->getClientBackups($this->restore_params['client'], "any", "desc"); + $backups = $this->getRestoreModel()->getClientBackups($this->restore_params['client'], "any", "desc"); } - $jobs = $this->getJobs(2); - $clients = $this->getClients(2); - $filesets = $this->getFilesets(0); - $restorejobs = $this->getRestoreJobs(0); + $jobs = $this->getRestoreModel()->getJobs(); + $clients = $this->getRestoreModel()->getClients(); + $filesets = $this->getRestoreModel()->getFilesets(); + $restorejobs = $this->getRestoreModel()->getRestoreJobs(); // Create the form $form = new RestoreForm( @@ -109,7 +117,7 @@ public function indexAction() $jobids = $form->getInputFilter()->getValue('jobids_hidden'); $replace = $form->getInputFilter()->getValue('replace'); - $result = $this->restore($type, $jobid, $client, $restoreclient, $restorejob, $where, $fileid, $dirid, $jobids, $replace); + $result = $this->getRestoreModel()->restore($type, $jobid, $client, $restoreclient, $restorejob, $where, $fileid, $dirid, $jobids, $replace); } @@ -166,34 +174,22 @@ private function buildSubtree() // Get directories if($this->restore_params['type'] == "client") { - $directories = $this->getDirectories( - $this->getJobIds($this->restore_params['jobid'], - $this->restore_params['mergefilesets'], - $this->restore_params['mergejobs']), - $this->restore_params['id'] - ); + $jobids = $this->getRestoreModel()->getJobIds($this->restore_params['jobid'],$this->restore_params['mergefilesets'],$this->restore_params['mergejobs']); + $this->restore_params['jobids'] = $jobids; + $directories = $this->getRestoreModel()->getDirectories($this->restore_params['jobids'],$this->restore_params['id']); } else { - $directories = $this->getDirectories( - $this->restore_params['jobid'], - $this->restore_params['id'] - ); + $directories = $this->getRestoreModel()->getDirectories($this->restore_params['jobid'],$this->restore_params['id']); } // Get files if($this->restore_params['type'] == "client") { - $files = $this->getFiles( - $this->getJobIds($this->restore_params['jobid'], - $this->restore_params['mergefilesets'], - $this->restore_params['mergejobs']), - $this->restore_params['id'] - ); + $jobids = $this->getRestoreModel()->getJobIds($this->restore_params['jobid'],$this->restore_params['mergefilesets'],$this->restore_params['mergejobs']); + $this->restore_params['jobids'] = $jobids; + $files = $this->getRestoreModel()->getFiles($this->restore_params['jobids'],$this->restore_params['id']); } else { - $files = $this->getFiles( - $this->restore_params['jobid'], - $this->restore_params['id'] - ); + $files = $this->getRestoreModel()->getFiles($this->restore_params['jobid'],$this->restore_params['id']); } $dnum = count($directories); @@ -385,218 +381,12 @@ private function getRestoreParams() } - /** - * - */ - private function restore($type=null, $jobid=null, $client=null, $restoreclient=null, $restorejob=null, $where=null, $fileid=null, $dirid=null, $jobids=null, $replace=null) - { - $result = null; - $director = $this->getServiceLocator()->get('director'); - - if($type == "client") { - $result = $director->restore($type, $jobid, $client, $restoreclient, $restorejob, $where, $fileid, $dirid, $jobids, $replace); - } - elseif($type == "job") { - // TODO - //$result = $director->restore(); - } - - return $result; - } - - /** - * - * @param $jobid - * @param $pathid - * @return array - */ - private function getDirectories($jobid=null, $pathid=null) - { - $director = $this->getServiceLocator()->get('director'); - if($pathid == null || $pathid == "#") { - $result = $director->send_command(".bvfs_lsdirs jobid=$jobid path=", 2, $jobid); - } - else { - $result = $director->send_command(".bvfs_lsdirs jobid=$jobid pathid=" . abs($pathid), 2, $jobid); - } - $directories = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $directories['result']['directories']; - } - - /** - * - * @param $jobid - * @param $pathid - * @return array - */ - private function getFiles($jobid=null, $pathid=null) - { - $director = $this->getServiceLocator()->get('director'); - if($pathid == null || $pathid == "#") { - $result = $director->send_command(".bvfs_lsfiles jobid=$jobid path=", 2); - } - else { - $result = $director->send_command(".bvfs_lsfiles jobid=$jobid pathid=" . abs($pathid), 2); - } - $files = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $files['result']['files']; - } - - /** - * TODO - */ - private function getRevisions($jobid=null, $filenameid=null) - { - $director = $this->getServiceLocator()->get('director'); - - // TODO - - } - - /** - * Get all JobIds needed to restore a particular job. - * With the all option set to true the director will - * use all definded filesets for a client. - * - * @param $jobid - * @return mixed - */ - private function getJobIds($jobid=null, $mergefilesets=0, $mergejobs=0) - { - $result = null; - $director = $this->getServiceLocator()->get('director'); - - if($mergefilesets == 0 && $mergejobs == 0) { - $cmd = ".bvfs_get_jobids jobid=$jobid all"; - $result = $director->send_command($cmd, 2); - } - elseif($mergefilesets == 1 && $mergejobs == 0) { - $cmd = ".bvfs_get_jobids jobid=$jobid"; - $result = $director->send_command($cmd, 2); - } - - if($mergejobs == 1) { - return $jobid; - } - - $jobids = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - $result = ""; - - if(!empty($jobids['result'])) { - $jnum = count($jobids['result']['jobids']); - - foreach($jobids['result']['jobids'] as $jobid) { - $result .= $jobid['id']; - --$jnum; - if($jnum > 0) { - $result .= ","; - } - } - } - - $this->restore_params['jobids'] = $result; - - return $result; - } - - /** - * Get job list from director in long or short format - * - * @param $format - * @return array - */ - private function getJobs($format=2) + public function getRestoreModel() { - $director = $this->getServiceLocator()->get('director'); - if($format == 2) { - $result = $director->send_command("llist jobs", 2); - } - elseif($format == 1) { - $result = $director->send_command("list jobs", 2); - } - elseif($format == 0) { + if(!$this->restoreModel) { + $sm = $this->getServiceLocator(); + $this->restoreModel = $sm->get('Restore\Model\RestoreModel'); } - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $jobs['result']['jobs']; + return $this->restoreModel; } - - /** - * Get client list from director in long or short format - * - * @param $format - * @return array - */ - private function getClients($format=2) - { - $director = $this->getServiceLocator()->get('director'); - if($format == 2) { - $result = $director->send_command("llist clients", 2); - } - elseif($format == 1) { - $result = $director->send_command("list clients", 2); - } - elseif($format == 0) { - $result = $director->send_command(".clients", 2); - return $result; - } - $clients = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $clients['result']['clients']; - } - - /** - * Get fileset list from director in long or short format - * - * @param $format - * @return array - */ - private function getFilesets($format=2) - { - $director = $this->getServiceLocator()->get('director'); - if($format == 2) { - $result = $director->send_command("llist filesets", 2); - } - elseif($format == 1) { - $result = $director->send_command("list filesets", 2); - } - elseif($format == 0) { - $result = $director->send_command(".filesets", 2); - } - $filesets = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $filesets['result']['filesets']; - } - - /** - * Get restore job list from director - */ - private function getRestoreJobs($format=0) - { - $director = $this->getServiceLocator()->get('director'); - if($format == 0) { - $result = $director->send_command(".jobs type=R", 2); - } - $restorejobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $restorejobs['result']['jobs']; - } - - /** - * Get client backup list from director - */ - private function getClientBackups($client=null, $fileset=null, $order=null, $limit=null) - { - $director = $this->getServiceLocator()->get('director'); - if($limit != null) { - $result = $director->send_command("list backups client=$client fileset=$fileset order=$order limit=$limit", 2); - } - else { - $result = $director->send_command("list backups client=$client fileset=$fileset order=$order", 2); - } - $backups = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - if(empty($backups['result'])) { - return null; - } - else { - return $backups['result']['backups']; - } - } - } diff --git a/module/Restore/src/Restore/Form/RestoreForm.php b/module/Restore/src/Restore/Form/RestoreForm.php index e7462207..b9d5d8d0 100644 --- a/module/Restore/src/Restore/Form/RestoreForm.php +++ b/module/Restore/src/Restore/Form/RestoreForm.php @@ -493,7 +493,7 @@ private function getBackupList() $level = "Full"; break; } - $selectData[$backup['jobid']] = "(" . $backup['jobid'] . ") " . $backup['starttime'] . " - " . $backup['fileset'] . " - " . $level; + $selectData[$backup['jobid']] = "(" . $backup['jobid'] . ") " . $backup['starttime'] . " - " . $backup['name'] . " - " . $level; } } return $selectData; diff --git a/module/Restore/src/Restore/Model/RestoreModel.php b/module/Restore/src/Restore/Model/RestoreModel.php new file mode 100644 index 00000000..80af0eec --- /dev/null +++ b/module/Restore/src/Restore/Model/RestoreModel.php @@ -0,0 +1,195 @@ +. + * + */ + +namespace Restore\Model; + +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class RestoreModel 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 getDirectories($jobid=null, $pathid=null) { + if(isset($jobid)) { + if($pathid == null || $pathid== "#") { + $cmd = '.bvfs_lsdirs jobid='.$jobid.' path='; + } + else { + $cmd = '.bvfs_lsdirs jobid='.$jobid.' pathid='.abs($pathid).''; + } + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, $jobid); + $directories = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $directories['result']['directories']; + } + else { + return false; + } + } + + public function getFiles($jobid=null, $pathid=null) { + if(isset($jobid)) { + if($pathid == null || $pathid == "#") { + $cmd = '.bvfs_lsfiles jobid='.$jobid.' path='; + } + else { + $cmd = '.bvfs_lsfiles jobid='.$jobid.' pathid='.abs($pathid).''; + } + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, $jobid); + $files = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $files['result']['files']; + } + else { + return false; + } + } + + public function getJobs() + { + $cmd = 'llist jobs'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $jobs['result']['jobs']; + } + + 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 getFilesets() + { + $cmd = '.filesets'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $filesets = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $filesets['result']['filesets']; + } + + public function getClientBackups($client=null, $fileset=null, $order=null, $limit=null) + { + if(isset($client, $fileset, $order)) { + if($limit != null) { + $cmd = 'list backups client='.$client.' fileset='.$fileset.' order='.$order.' limit='.$limit.''; + } + else { + $cmd = 'list backups client='.$client.' fileset='.$fileset.' order='.$order.''; + } + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $backups = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + if(empty($backups['result'])) { + return null; + } + else { + return $backups['result']['backups']; + } + } + else { + return false; + } + } + + public function getRestoreJobs() + { + $cmd = '.jobs type=R'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $restorejobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $restorejobs['result']['jobs']; + } + + public function getJobIds($jobid=null, $mergefilesets=0, $mergejobs=0) + { + if(isset($jobid)) { + if($mergefilesets == 0 && $mergejobs == 0) { + $cmd = '.bvfs_get_jobids jobid='.$jobid.' all'; + } + elseif($mergefilesets == 1 && $mergejobs == 0) { + $cmd = '.bvfs_get_jobids jobid='.$jobid.''; + } + elseif($mergefilesets == 1 && $mergejobs == 1) { + return $jobid; + } + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $jobids = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + if(!empty($jobids['result'])) { + $result = ""; + $i = count($jobids['result']['jobids']); + foreach($jobids['result']['jobids'] as $jobid) { + $result .= $jobid['id']; + --$i; + if($i > 0) { + $result .= ","; + } + } + } + return $result; + } + else { + return false; + } + } + + public function restore($type=null, $jobid=null, $client=null, $restoreclient=null, $restorejob=null, $where=null, $fileid=null, $dirid=null, $jobids=null, $replace=null) + { + if(isset($type)) { + $this->director = $this->getServiceLocator()->get('director'); + if($type == "client") { + $result = $this->director->restore($type, $jobid, $client, $restoreclient, $restorejob, $where, $fileid, $dirid, $jobids, $replace); + } + elseif($type == "job") { + // TODO + } + return $result; + } + else { + return false; + } + } +} diff --git a/module/Restore/src/Restore/Model/RestoreTable.php b/module/Restore/src/Restore/Model/RestoreTable.php deleted file mode 100644 index 5981d2fa..00000000 --- a/module/Restore/src/Restore/Model/RestoreTable.php +++ /dev/null @@ -1,32 +0,0 @@ -. - * - */ - -namespace Restore\Model; - -class RestoreTable -{ - -} - diff --git a/module/Storage/Module.php b/module/Storage/Module.php index 089f489f..0d843918 100644 --- a/module/Storage/Module.php +++ b/module/Storage/Module.php @@ -3,7 +3,7 @@ namespace Storage; use Storage\Model\Storage; -use Storage\Model\StorageTable; +use Storage\Model\StorageModel; class Module { @@ -27,4 +27,16 @@ public function getConfig() return include __DIR__ . '/config/module.config.php'; } + public function getServiceConfig() + { + return array( + 'factories' => array( + 'Storage\Model\StorageModel' => function() { + $model = new StorageModel(); + return $model; + } + ) + ); + } + } diff --git a/module/Storage/src/Storage/Controller/StorageController.php b/module/Storage/src/Storage/Controller/StorageController.php index f3b342af..3a730415 100644 --- a/module/Storage/src/Storage/Controller/StorageController.php +++ b/module/Storage/src/Storage/Controller/StorageController.php @@ -33,11 +33,13 @@ class StorageController extends AbstractActionController { + protected $storageModel; + public function indexAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $storages = $this->getStorages(); + $storages = $this->getStorageModel()->getStorages(); $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; $page = (int) $this->params()->fromQuery('page'); @@ -77,12 +79,13 @@ public function autochangerAction() } } - private function getStorages() + public function getStorageModel() { - $director = $this->getServiceLocator()->get('director'); - $result = $director->send_command("list storages", 2, null); - $storages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $storages['result']['storages']; + if(!$this->storageModel) { + $sm = $this->getServiceLocator(); + $this->storageModel = $sm->get('Storage\Model\StorageModel'); + } + return $this->storageModel; } } diff --git a/module/Storage/src/Storage/Model/StorageTable.php b/module/Storage/src/Storage/Model/StorageModel.php similarity index 57% rename from module/Storage/src/Storage/Model/StorageTable.php rename to module/Storage/src/Storage/Model/StorageModel.php index a31753eb..5ed45471 100644 --- a/module/Storage/src/Storage/Model/StorageTable.php +++ b/module/Storage/src/Storage/Model/StorageModel.php @@ -25,7 +25,36 @@ namespace Storage\Model; -class StorageTable +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +class StorageModel 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 getStorages() + { + $cmd = 'list storages'; + $this->director = $this->getServiceLocator()->get('director'); + $result = $this->director->send_command($cmd, 2, null); + $storages = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $storages['result']['storages']; + } + }