mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 09:14:09 +02:00
RepositoryByObjectHelper: throw a nice exception
...when no Db is given
This commit is contained in:
parent
c51642a673
commit
2bf1b3f429
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Repository;
|
namespace Icinga\Module\Director\Repository;
|
||||||
|
|
||||||
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Objects\IcingaObject;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
|
|
||||||
@ -37,7 +38,9 @@ trait RepositoryByObjectHelper
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IcingaObject $object
|
* @param IcingaObject $object
|
||||||
|
* @param Db|null $connection
|
||||||
* @return static
|
* @return static
|
||||||
|
* @throws ProgrammingError
|
||||||
*/
|
*/
|
||||||
public static function instanceByObject(IcingaObject $object, Db $connection = null)
|
public static function instanceByObject(IcingaObject $object, Db $connection = null)
|
||||||
{
|
{
|
||||||
@ -46,12 +49,13 @@ trait RepositoryByObjectHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! $connection) {
|
if (! $connection) {
|
||||||
var_dump($object->hasBeenLoadedFromDb()); exit;
|
throw new ProgrammingError(
|
||||||
echo '<pre>';
|
'Cannot use repository for %s "%s" as it has no DB connection',
|
||||||
debug_print_backtrace();
|
$object->getShortTableName(),
|
||||||
echo '</pre>';
|
$object->getObjectName()
|
||||||
throw new \Exception('SDFA');
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::instanceByType(
|
return static::instanceByType(
|
||||||
$object->getShortTableName(),
|
$object->getShortTableName(),
|
||||||
$connection
|
$connection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user