[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: IniRepository: Don' t require a key column before the onInsert trigger

git at icinga.org git at icinga.org
Wed Nov 2 12:55:25 CET 2016


Module: icingaweb2
Branch: feature/announce-banner-11198
Commit: 82c7a5105069e6b2c61e55942937b7bac5380700
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=82c7a5105069e6b2c61e55942937b7bac5380700

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Mon Oct 31 08:35:45 2016 +0100

IniRepository: Don't require a key column before the onInsert trigger

fixes #13005

---

 library/Icinga/Repository/IniRepository.php |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/library/Icinga/Repository/IniRepository.php b/library/Icinga/Repository/IniRepository.php
index 04b25c5..b292dc2 100644
--- a/library/Icinga/Repository/IniRepository.php
+++ b/library/Icinga/Repository/IniRepository.php
@@ -186,13 +186,14 @@ abstract class IniRepository extends Repository implements Extensible, Updatable
     public function insert($target, array $data)
     {
         $newData = $this->requireStatementColumns($target, $data);
-        $section = $this->extractSectionName($newData);
+        $config = $this->onInsert($target, new ConfigObject($newData));
+        $section = $this->extractSectionName($config);
 
         if ($this->ds->hasSection($section)) {
             throw new StatementException(t('Cannot insert. Section "%s" does already exist'), $section);
         }
 
-        $this->ds->setSection($section, $this->onInsert($target, new ConfigObject($newData)));
+        $this->ds->setSection($section, $config);
 
         try {
             $this->ds->saveIni();
@@ -301,23 +302,25 @@ abstract class IniRepository extends Repository implements Extensible, Updatable
     }
 
     /**
-     * Extract and return the section name off of the given $data
+     * Extract and return the section name off of the given $config
      *
-     * @param   array   $data
+     * @param   array|ConfigObject  $config
      *
      * @return  string
      *
      * @throws  ProgrammingError    In case no valid section name is available
      */
-    protected function extractSectionName(array & $data)
+    protected function extractSectionName( & $config)
     {
         $keyColumn = $this->ds->getConfigObject()->getKeyColumn();
-        if (! isset($data[$keyColumn])) {
-            throw new ProgrammingError('$data does not provide a value for key column "%s"', $keyColumn);
+        if (! is_array($config) && !$config instanceof ConfigObject) {
+            throw new ProgrammingError('$config is neither an array nor a ConfigObject');
+        } elseif (! isset($config[$keyColumn])) {
+            throw new ProgrammingError('$config does not provide a value for key column "%s"', $keyColumn);
         }
 
-        $section = $data[$keyColumn];
-        unset($data[$keyColumn]);
+        $section = $config[$keyColumn];
+        unset($config[$keyColumn]);
         return $section;
     }
 }



More information about the icinga-checkins mailing list