Skip to content

Wrong return type in App\Table\VolumeTable::getDiskUsage() #231

@gribnut

Description

@gribnut

Describe the bug
When viewing "Director(s)" report, throws exception due to int returned from VolumeTable->getDiskUsage() in VolumeTable.php.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Reports->Director(s)'
  2. See error

Expected behavior
No error/exception. VolumeTable->getDiskUsage() return string instead of int.

Screenshots
Error:
App\Table\VolumeTable::getDiskUsage(): Return value must be of type string, int returned
File: bacula-web-9.5.1/application/Controller/DirectorController.php on line 102 in function App\Table\VolumeTable->getDiskUsage

Desktop (please complete the following information):

  • OS: Ubuntu 24.04.1
  • Browser: Chrome
  • Version: 9.5.1
  • PHP version: 8.3.6
  • Bacula 13.04 using sqlite3 database

Additional context
Possible that issue may be specific to Bacula 13.04 and/or using sqlite3 database. Should be safe to wrap return of VolumeTable->getDiskUsage() with strval() to ensure value is a string in case there is mix of types in different versions of Bacula or database type.

// Sample code change
public function getDiskUsage(): string
{
    $fields = ['SUM(Media.VolBytes) as bytes_size'];
    $statment = [
        'table' => $this->tablename,
        'fields' => $fields
    ];

    // Run SQL query
    $result = $this->run_query(CDBQuery::get_Select($statment));

    $result = $result->fetch();
    return strval($result['bytes_size']);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions