Skip to content

Commit

Permalink
fixes Icinga#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Zeschko committed Feb 1, 2018
1 parent 07b18f0 commit 2bea41c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Editors
/.idea/
.*.sw[op]
.vscode/

## PHP vendor artifacts
/vendor/
27 changes: 24 additions & 3 deletions library/Fileshipper/ProvidedHook/Director/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public function fetchData()
$basedir = $this->getSetting('basedir');
$filename = $this->getSetting('file_name');
$format = $this->getSetting('file_format');
$merge = $this->getSetting('file_merge');

if ($filename === '*') {
return $this->fetchFiles($basedir, $format);
return $this->fetchFiles($basedir, $format, $merge);
}

return (array) $this->fetchFile($basedir, $filename, $format);
Expand Down Expand Up @@ -98,6 +99,22 @@ public static function addSettingsFormFields(QuickForm $form)
return $form;
}

if ($basename === '*') {
$form->addElement('select', 'file_merge', array(
'label' => $form->translate('Multiple objects merge?'),
'value' => 'no',
'description' => $form->translate(
'Are there multiple objects in every file and should these objects be merged?'
),
'required' => true,
'class' => 'autosubmit',
'multiOptions' => array(
'no' => $form->translate('No'),
'yes' => $form->translate('Yes'),
),
));
}

$filename = sprintf('%s/%s', $basedir, $basename);
switch ($format) {
case 'csv':
Expand Down Expand Up @@ -227,11 +244,15 @@ protected static function addTxtElements(QuickForm $form)
));
}

protected function fetchFiles($basedir, $format)
protected function fetchFiles($basedir, $format, $merge)
{
$result = array();
foreach (static::listFiles($basedir) as $file) {
$result[$file] = (object) $this->fetchFile($basedir, $file, $format);
if($merge === 'yes') {
$result = array_merge($result, (array) $this->fetchFile($basedir, $file, $format));
} else {
$result[$file] = (object) $this->fetchFile($basedir, $file, $format);
}
}

return $result;
Expand Down

0 comments on commit 2bea41c

Please sign in to comment.