Skip to content

Commit

Permalink
Merge pull request #201 from Icinga/fix-getdb
Browse files Browse the repository at this point in the history
Drop `getDb()` resource param & add return type hint
  • Loading branch information
yhabteab authored Aug 21, 2023
2 parents b1dd215 + 76fe101 commit 6ab233d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions library/Reporting/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
use Icinga\Application\Config;
use Icinga\Data\ResourceFactory;
use ipl\Sql;
use PDO;

trait Database
{
protected function getDb($resource = null)
protected function getDb(): RetryConnection
{
$config = new Sql\Config(ResourceFactory::getResourceConfig(
$resource ?: Config::module('reporting')->get('backend', 'resource', 'reporting')
));
$config = new Sql\Config(
ResourceFactory::getResourceConfig(
Config::module('reporting')->get('backend', 'resource', 'reporting')
)
);

$config->options = [\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ];
$config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
if ($config->db === 'mysql') {
$config->options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
$config->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
}

$conn = new RetryConnection($config);

return $conn;
return new RetryConnection($config);
}

protected function listTimeframes()
Expand Down

0 comments on commit 6ab233d

Please sign in to comment.