Commit 34718ec5 authored by Marcin Haba's avatar Marcin Haba
Browse files

baculum: Adapt code to use PSR-4 autoloader

parent 181b2e2b
......@@ -37,7 +37,7 @@ examples = examples
configcachedir = $(datadir)/runtime
samplesdir = $(examples)/$(SAMPLETYPE)
webdatadirsrc = $(datadir)/$(webdir)/Class \
webdatadirsrc = $(datadir)/$(webdir)/Modules \
$(datadir)/$(webdir)/Config \
$(datadir)/$(webdir)/JavaScript \
$(datadir)/$(webdir)/Data \
......@@ -46,14 +46,14 @@ webdatadirsrc = $(datadir)/$(webdir)/Class \
$(datadir)/$(webdir)/Pages \
$(datadir)/$(webdir)/Portlets
apidatadirsrc = $(datadir)/$(apidir)/Class \
apidatadirsrc = $(datadir)/$(apidir)/Modules \
$(datadir)/$(apidir)/Config \
$(datadir)/$(apidir)/Layouts \
$(datadir)/$(apidir)/Logs \
$(datadir)/$(apidir)/Pages \
$(datadir)/$(apidir)/Portlets
commondatadirsrc = $(datadir)/$(commondir)/Class \
commondatadirsrc = $(datadir)/$(commondir)/Modules \
$(datadir)/$(commondir)/JavaScript \
$(datadir)/$(commondir)/Pages \
$(datadir)/$(commondir)/Portlets
......
......@@ -19,8 +19,8 @@
*
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.Common.Class.Params');
use Prado\Web\UI\TTemplateControl;
/**
* Main layout.
......
......@@ -20,7 +20,7 @@
<com:BStyleSheet StyleSheetUrl=<%~ ../../vendor/bower-asset/datatables.net-responsive-dt/css/responsive.dataTables.min.css %> />
<com:BStyleSheet StyleSheetUrl=<%~ ../../vendor/bower-asset/datatables.net-buttons-dt/css/buttons.dataTables.min.css %> />
<com:BStyleSheet StyleSheetUrl=<%~ ../../../themes/Baculum-v2/css/baculum.css %> />
<com:Application.Common.Portlets.TableDefaults />
<com:Baculum.Common.Portlets.TableDefaults />
<!-- Top container -->
<div class="w3-bar w3-top w3-black w3-large" style="z-index: 4">
<button type="button" class="w3-bar-item w3-button w3-hover-none w3-hover-text-light-grey" onclick="W3SideBar.open();"><i class="fa fa-bars"></i>  Menu</button>
......@@ -28,7 +28,7 @@
<img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/logo.png" alt="" />
</span>
</div>
<com:Application.API.Portlets.APISideBar />
<com:Baculum.API.Portlets.APISideBar />
<div class="w3-main page_main_el" id="page_main" style="margin-left: 250px; margin-top: 43px;">
<com:TContentPlaceHolder ID="Main" />
<footer class="w3-container w3-right-align w3-small"><%[ Version: ]%> <%=Params::BACULUM_VERSION%></footer>
......
......@@ -19,7 +19,9 @@
*
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
use Prado\Web\UI\TTemplateControl;
/**
* Wizard layout.
*
......
......@@ -20,7 +20,9 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.Common.Class.ConfigFileModule');
namespace Baculum\API\Modules;
use Baculum\Common\Modules\ConfigFileModule;
/**
* Manage API configuration.
......@@ -40,7 +42,7 @@ class APIConfig extends ConfigFileModule {
/**
* API config file path
*/
const CONFIG_FILE_PATH = 'Application.API.Config.api';
const CONFIG_FILE_PATH = 'Baculum.API.Config.api';
/**
* API config file format
......
......@@ -20,11 +20,12 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.Common.Class.Errors');
Prado::using('Application.API.Class.APIConfig');
Prado::using('Application.API.Class.BAPIException');
Prado::using('Application.API.Class.Database');
Prado::using('System.Data.ActiveRecord.TActiveRecord');
namespace Baculum\API\Modules;
use Baculum\Common\Modules\Errors\DatabaseError;
use PDO;
use Prado\Data\ActiveRecord\TActiveRecord;
use Prado\Data\TDbConnection;
/**
* Base API database module.
......@@ -83,7 +84,7 @@ class APIDbModule extends TActiveRecord {
* @param array database parameters from api config
* @param bool force connection try (used when db_params are not saved yet)
* @return object TDbConnection instance or null if errors occured during connecting
* @throws BCatalogExcemption if cataloga access is not supported
* @throws BCatalogException if cataloga access is not supported
*/
public static function getAPIDbConnection(array $db_params, $force = false) {
$db_connection = null;
......
......@@ -20,7 +20,9 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('System.TModule');
namespace Baculum\API\Modules;
use Prado\TModule;
/**
* Abstract API module.
......
......@@ -20,6 +20,10 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
namespace Baculum\API\Modules;
use Prado\Prado;
/**
* API Server layer.
* Introduces main method inherited by particular API server versions.
......@@ -46,7 +50,6 @@ class APIServer extends APIModule {
* Set API server instance.
*
* @param BaculumAPIServer $obj server object
* @return none
*/
public function setServerObj($obj) {
$this->server = $obj;
......
......@@ -20,8 +20,9 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.API.Class.APIServer');
Prado::using('Application.API.Class.APIInterfaces');
namespace Baculum\API\Modules;
use stdClass;
/**
* API Server version 1.
......@@ -36,7 +37,6 @@ class APIServerV1 extends APIServer implements IAPIServer {
/**
* Support for API GET method request.
*
* @return none;
*/
public function get() {
$this->getServerObj()->get();
......@@ -45,7 +45,6 @@ class APIServerV1 extends APIServer implements IAPIServer {
/**
* Support for API PUT method request.
*
* @return none
*/
public function put() {
$id = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
......@@ -92,7 +91,6 @@ class APIServerV1 extends APIServer implements IAPIServer {
/**
* Support for API POST method request.
*
* @return none
*/
public function post() {
$params = new StdClass;
......@@ -105,7 +103,6 @@ class APIServerV1 extends APIServer implements IAPIServer {
/**
* Support for API DELETE method request.
*
* @return none
*/
public function delete() {
$id = null;
......
......@@ -20,8 +20,9 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.API.Class.APIServer');
Prado::using('Application.API.Class.APIInterfaces');
namespace Baculum\API\Modules;
use stdClass;
/**
* API Server version 2.
......@@ -39,7 +40,6 @@ class APIServerV2 extends APIServer implements IAPIServer {
/**
* Support for API GET method request.
*
* @return none;
*/
public function get() {
$this->getServerObj()->get();
......@@ -48,7 +48,6 @@ class APIServerV2 extends APIServer implements IAPIServer {
/**
* Support for API PUT method request.
*
* @return none
*/
public function put() {
$id = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
......@@ -63,7 +62,6 @@ class APIServerV2 extends APIServer implements IAPIServer {
/**
* Support for API POST method request.
*
* @return none
*/
public function post() {
$inputstr = file_get_contents("php://input");
......@@ -77,7 +75,6 @@ class APIServerV2 extends APIServer implements IAPIServer {
/**
* Support for API DELETE method request.
*
* @return none
*/
public function delete() {
$id = null;
......
......@@ -20,7 +20,8 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('System.Web.TUrlMapping');
use Baculum\Common\Modules\BaculumUrlMapping;
use Prado\Web\TUrlMappingPattern;
/**
* Extension default URL mapper for API.
......
......@@ -20,24 +20,9 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.Common.Class.BException');
namespace Baculum\API\Modules;
/**
* API exceptions.
*
* @author Marcin Haba <marcin.haba@bacula.pl>
* @category Exception
* @package Baculum API
*/
class BAPIException extends BException {
}
use Baculum\Common\Modules\BException;
class BCatalogException extends BAPIException {
}
class BConsoleException extends BAPIException {
}
class BConfigException extends BAPIException {
class BAPIException extends BException {
}
?>
<?php
/*
* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
* Copyright (C) 2013-2022 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* 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.
*
* This notice must be preserved when any source code is
* conveyed and/or propagated.
*
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
namespace Baculum\API\Modules;
class BCatalogException extends BAPIException {
}
<?php
/*
* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
* Copyright (C) 2013-2022 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* 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.
*
* This notice must be preserved when any source code is
* conveyed and/or propagated.
*
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
namespace Baculum\API\Modules;
class BConfigException extends BAPIException {
}
<?php
/*
* Bacula(R) - The Network Backup Solution
* Baculum - Bacula web interface
*
* Copyright (C) 2013-2022 Kern Sibbald
*
* The main author of Baculum is Marcin Haba.
* 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.
*
* This notice must be preserved when any source code is
* conveyed and/or propagated.
*
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
namespace Baculum\API\Modules;
class BConsoleException extends BAPIException {
}
......@@ -20,6 +20,8 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
namespace Baculum\API\Modules;
/**
* Bacula LStat value support.
*
......
......@@ -21,7 +21,7 @@
*/
Prado::using('Application.API.Class.APIModule');
namespace Baculum\API\Modules;
/**
* Tools used to show list files command output.
......
......@@ -20,6 +20,8 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
namespace Baculum\API\Modules;
/**
* BVFS module class.
* It provides tools to work with BVFS outputs.
......@@ -66,7 +68,7 @@ class BVFS extends APIModule {
);
}
}
usort($elements, 'sortFilesListByName');
usort($elements, ['BVFS', 'sortFilesListByName']);
return $elements;
}
......@@ -90,21 +92,19 @@ class BVFS extends APIModule {
return $elements;
}
}
/*
* Small sorting callback function to sort files and directories by name.
* Function keeps '.' and '..' names always in the beginning of array.
* Used to sort files and directories from Bvfs.
*/
function sortFilesListByName($a, $b) {
$firstLeft = substr($a['name'], 0, 1);
$firstRight = substr($b['name'], 0, 1);
if ($firstLeft == '.' && $firstRight != '.') {
return -1;
} else if ($firstRight == '.' && $firstLeft != '.') {
return 1;
/*
* Small sorting callback function to sort files and directories by name.
* Function keeps '.' and '..' names always in the beginning of array.
* Used to sort files and directories from Bvfs.
*/
public static function sortFilesListByName($a, $b) {
$firstLeft = substr($a['name'], 0, 1);
$firstRight = substr($b['name'], 0, 1);
if ($firstLeft == '.' && $firstRight != '.') {
return -1;
} else if ($firstRight == '.' && $firstLeft != '.') {
return 1;
}
return strcmp($a['name'], $b['name']);
}
return strcmp($a['name'], $b['name']);
}
?>
}
\ No newline at end of file
......@@ -20,7 +20,10 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.Common.Class.ConfigFileModule');
namespace Baculum\API\Modules;
use Baculum\Common\Modules\Logging;
use Baculum\Common\Modules\ConfigFileModule;
/**
* Manage Bacula configuration.
......
......@@ -20,11 +20,12 @@
* Bacula(R) is a registered trademark of Kern Sibbald.
*/
Prado::using('Application.Common.Class.Params');
Prado::using('Application.Common.Class.Errors');
Prado::using('Application.API.Class.BAPIException');
Prado::using('Application.API.Class.APIModule');
Prado::using('Application.API.Class.APIConfig');
namespace Baculum\API\Modules;
use Baculum\Common\Modules\Logging;
use Baculum\Common\Modules\Errors\BaculaConfigError;
use Baculum\Common\Modules\Errors\JSONToolsError;
use Baculum\Common\Modules\Params;
/**
* Read/write Bacula configuration.
......@@ -301,7 +302,7 @@ class BaculaSetting extends APIModule {
);
}
$overwrite_directive = array_map(
'overwrite_directives_callback',
['BaculaSetting', 'overwrite_directives_callback'],
array_keys($directive_value[$i]),
$values
);
......@@ -572,27 +573,28 @@ class BaculaSetting extends APIModule {
}
return $tool_type;
}
}
function overwrite_directives_callback($directive_name, $directive_value) {
$directive = '';
$overwrite_directives = array(
'Level',
'Pool',
'Storage',
'Messages',
'FullPool',
'DifferentialPool',
'IncrementalPool',
'Accurate',
'Priority',
'SpoolData',
'MaxRunSchedTime',
'NextPool',
'MaxConnectTime'
);
if (in_array($directive_name, $overwrite_directives)) {
$directive = "{$directive_name}={$directive_value}";
public static function overwrite_directives_callback($directive_name, $directive_value) {
$directive = '';
$overwrite_directives = array(
'Level',
'Pool',
'Storage',
'Messages',
'FullPool',
'DifferentialPool',
'IncrementalPool',
'Accurate',
'Priority',
'SpoolData',
'MaxRunSchedTime',
'NextPool',
'MaxConnectTime'
);
if (in_array($directive_name, $overwrite_directives)) {
$directive = "{$directive_name}={$directive_value}";
}
return $directive;
}
return $directive;
}
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment