Skip to content

Commit

Permalink
fix: job files report error using Bacula >= 11.0.0
Browse files Browse the repository at this point in the history
Fix issue using job files report with Bacula version 11.0.0 or higher.

Resolve: #202
  • Loading branch information
dfranco committed Dec 28, 2023
1 parent f242c95 commit 4f2bedd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
10 changes: 8 additions & 2 deletions application/config/container-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\CsrfErrorHandler;
use App\Libs\FileConfig;
use App\Tables\CatalogTable;
use App\Tables\ClientTable;
use App\Tables\JobFileTable;
use App\Tables\JobTable;
Expand Down Expand Up @@ -63,8 +64,13 @@
VolumeTable::class => function (SessionInterface $session) {
return new VolumeTable(DatabaseFactory::getDatabase($session->get('catalog_id', 0)));
},
JobFileTable::class => function (SessionInterface $session) {
return new JobFileTable(DatabaseFactory::getDatabase($session->get('catalog_id', 0)));
JobFileTable::class => function (SessionInterface $session, ContainerInterface $container) {
return new JobFileTable(
DatabaseFactory::getDatabase($session->get('catalog_id', 0)),
$container->get(CatalogTable::class));
},
CatalogTable::class => function (SessionInterface $session) {
return new CatalogTable(DatabaseFactory::getDatabase($session->get('catalog_id', 0)));
},
LogTable::class => function (SessionInterface $session) {
return new LogTable(DatabaseFactory::getDatabase($session->get('catalog_id', 0)));
Expand Down
23 changes: 10 additions & 13 deletions application/tables/JobFileTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
namespace App\Tables;

use Core\Db\CDBQuery;
use Core\Db\Database;
use Core\Db\DatabaseFactory;
use Core\Db\Table;
use Exception;
Expand All @@ -39,6 +40,13 @@ class JobFileTable extends Table
* @var string|null
*/
protected ?string $tablename = 'File';
private CatalogTable $catalogTable;

public function __construct(Database $db, CatalogTable $catalogTable)
{
parent::__construct($db);
$this->catalogTable = $catalogTable;
}

/**
* @param $jobId
Expand All @@ -50,13 +58,8 @@ class JobFileTable extends Table
*/
public function getJobFiles($jobId, $limit, $offset, string $filename = '')
{
$catalog = new CatalogTable(
DatabaseFactory::getDatabase(
(new PhpSession())->get('catalog_id', 0)
));

// Catalog version prior to Bacula 11.0.x
if ($catalog->getCatalogVersion() < 1016) {
if ($this->catalogTable->getCatalogVersion() < 1016) {
$fields = array('Job.Name', 'Job.JobStatus', 'File.FileIndex', 'Path.Path', 'Filename.Name AS Filename');
$where = array("File.JobId = $jobId");
if (! empty($filename)) {
Expand Down Expand Up @@ -109,13 +112,7 @@ public function getJobFiles($jobId, $limit, $offset, string $filename = '')
*/
public function countJobFiles(int $jobId, string $filename = '')
{
$catalog = new CatalogTable(
DatabaseFactory::getDatabase(
(new PhpSession())->get('catalog_id', 0)
)
);

if ($catalog->getCatalogVersion() < 1016) {
if ($this->catalogTable->getCatalogVersion() < 1016) {
$sql_query = "SELECT COUNT(*) as count
FROM File, Path, Filename, Job
WHERE File.JobId = $jobId
Expand Down

0 comments on commit 4f2bedd

Please sign in to comment.