Skip to content

Commit

Permalink
Refactoring: Client Model
Browse files Browse the repository at this point in the history
Moves getDirectorVersion() into its context,
the Director Model.
  • Loading branch information
fbergkemper committed Aug 3, 2016
1 parent 6d42525 commit c348542
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
13 changes: 7 additions & 6 deletions module/Auth/src/Auth/Controller/AuthController.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-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2016 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 Down Expand Up @@ -34,6 +34,7 @@
class AuthController extends AbstractActionController
{

protected $directorModel = null;
protected $bsock = null;

public function indexAction()
Expand Down Expand Up @@ -91,7 +92,7 @@ public function loginAction()
$updates = json_decode($bareos_updates, true);

try {
$dird_version = $this->getClientModel()->getDirectorVersion($this->bsock);
$dird_version = $this->getDirectorModel()->getDirectorVersion($this->bsock);
$this->bsock->disconnect();
}
catch(Exception $e) {
Expand Down Expand Up @@ -190,13 +191,13 @@ public function logoutAction()
return $this->redirect()->toRoute('auth', array('action' => 'login'));
}

public function getClientModel()
public function getDirectorModel()
{
if(!$this->clientModel) {
if(!$this->directorModel) {
$sm = $this->getServiceLocator();
$this->clientModel = $sm->get('Client\Model\ClientModel');
$this->directorModel = $sm->get('Director\Model\DirectorModel');
}
return $this->clientModel;
return $this->directorModel;
}

}
12 changes: 11 additions & 1 deletion module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -33,6 +33,7 @@ class ClientController extends AbstractActionController
{

protected $clientModel = null;
protected $directorModel = null;
protected $bsock = null;

public function indexAction()
Expand Down Expand Up @@ -153,7 +154,7 @@ public function getDataAction()
try {
$this->bsock = $this->getServiceLocator()->get('director');
$clients = $this->getClientModel()->getClients($this->bsock);
$dird_version = $this->getClientModel()->getDirectorVersion($this->bsock);
$dird_version = $this->getDirectorModel()->getDirectorVersion($this->bsock);
$this->bsock->disconnect();
}
catch(Exception $e) {
Expand Down Expand Up @@ -318,4 +319,13 @@ public function getClientModel()
}
return $this->clientModel;
}

public function getDirectorModel()
{
if(!$this->directorModel) {
$sm = $this->getServiceLocator();
$this->directorModel = $sm->get('Director\Model\DirectorModel');
}
return $this->directorModel;
}
}
14 changes: 0 additions & 14 deletions module/Client/src/Client/Model/ClientModel.php
Expand Up @@ -27,7 +27,6 @@

class ClientModel
{

public function getClients(&$bsock=null)
{
if(isset($bsock)) {
Expand Down Expand Up @@ -112,17 +111,4 @@ public function disableClient(&$bsock=null, $name=null)
throw new \Exception('Missing argument.');
}
}

public function getDirectorVersion(&$bsock=null)
{
if(isset($bsock)) {
$cmd = 'version';
$result = $bsock->send_command($cmd, 2, null);
$version = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $version['result']['version'];
}
else {
throw new \Exception('Missing argument.');
}
}
}
12 changes: 12 additions & 0 deletions module/Director/src/Director/Model/DirectorModel.php
Expand Up @@ -27,6 +27,18 @@

class DirectorModel
{
public function getDirectorVersion(&$bsock=null)
{
if(isset($bsock)) {
$cmd = 'version';
$result = $bsock->send_command($cmd, 2, null);
$version = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $version['result']['version'];
}
else {
throw new \Exception('Missing argument.');
}
}

public function getDirectorStatus(&$bsock=null)
{
Expand Down

0 comments on commit c348542

Please sign in to comment.