From cb9fff90ef4d778feed9d51f571bb662ddeeb974 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 13 Mar 2017 22:03:02 +0100 Subject: [PATCH] IcingaObject: add new static helper, expose... ...existing one refs #842 --- library/Director/Objects/IcingaObject.php | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index b5312263..0afcd0f6 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -2214,7 +2214,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } } - protected static function classByType($type) + public static function classByType($type) { // allow for icinga_host and host $type = lcfirst(preg_replace('/^icinga_/', '', $type)); @@ -2306,6 +2306,33 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } } + /** + * @param $type + * @param Db $db + * @return IcingaObject[] + * @throws ProgrammingError + */ + public static function loadAllExternalObjectsByType($type, Db $db) + { + /** @var IcingaObject $class */ + $class = self::classByType($type); + $dummy = $class::create(); + + if (is_array($dummy->getKeyName())) { + throw new ProgrammingError( + 'There is no support for loading external objects of type "%s"', + $type + ); + } else { + $query = $db->getDbAdapter() + ->select() + ->from($dummy->getTableName()) + ->where('object_type = ?', 'external_object'); + + return $class::loadAll($db, $query, 'object_name'); + } + } + public static function fromJson($json, Db $connection = null) { return static::fromPlainObject(json_decode($json), $connection);