From c44e164de92052f5cd56bec697e993522d83359d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 4 Nov 2016 10:16:45 +0100 Subject: [PATCH] IniRepository: Introduce method createConfig refs #13034 --- library/Icinga/Repository/IniRepository.php | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/library/Icinga/Repository/IniRepository.php b/library/Icinga/Repository/IniRepository.php index 74fe72154..200513049 100644 --- a/library/Icinga/Repository/IniRepository.php +++ b/library/Icinga/Repository/IniRepository.php @@ -377,6 +377,34 @@ abstract class IniRepository extends Repository implements Extensible, Updatable } } + /** + * Create and return a Config for the given meta and table + * + * @param array $meta + * @param string $table + * + * @return Config + * + * @throws ProgrammingError In case the given meta is invalid + */ + protected function createConfig(array $meta, $table) + { + if (! isset($meta['name'])) { + throw new ProgrammingError('Config file name missing for table "%s"', $table); + } elseif (! isset($meta['keyColumn'])) { + throw new ProgrammingError('Config key column name missing for table "%s"', $table); + } + + if (isset($meta['module'])) { + $config = Config::module($meta['module'], $meta['name']); + } else { + $config = Config::app($meta['name']); + } + + $config->getConfigObject()->setKeyColumn($meta['keyColumn']); + return $config; + } + /** * Extract and return the section name off of the given $config *