SkipDuplicates: new property modifier

fixes #2215
This commit is contained in:
Thomas Gelf 2020-11-02 15:05:52 +01:00
parent f42028c40f
commit 18f9e729e4
3 changed files with 29 additions and 0 deletions

View File

@ -28,6 +28,7 @@ next (will be 1.8.0)
* FEATURE: New Property Modifier: ListToObject (#2062)
* FEATURE: Property Modifier: convert binary UUID to HEX presentation (#2138)
* FEATURE: Property Modifier: get Host by Address (#2210)
* FEATURE: Property Modifier: skip duplicates (#2215)
* FEATURE: Import Sources now allow to download previewed data as JSON (#2096)
* FEATURE: UTF8 validation for failed imports gives better error message (#2143)
* FIX: LDAP Import is now able to paginate limited results (#2019)

View File

@ -0,0 +1,26 @@
<?php
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
class PropertyModifierSkipDuplicates extends PropertyModifierHook
{
private $seen = [];
public function getName()
{
return mt('director', 'Skip row if this value appears more than once');
}
public function transform($value)
{
if (isset($this->seen[$value])) {
$this->rejectRow();
}
$this->seen[$value] = true;
return $value;
}
}

View File

@ -41,6 +41,7 @@ use Icinga\Module\Director\PropertyModifier\PropertyModifierRegexReplace;
use Icinga\Module\Director\PropertyModifier\PropertyModifierRegexSplit;
use Icinga\Module\Director\PropertyModifier\PropertyModifierRejectOrSelect;
use Icinga\Module\Director\PropertyModifier\PropertyModifierReplace;
use Icinga\Module\Director\PropertyModifier\PropertyModifierSkipDuplicates;
use Icinga\Module\Director\PropertyModifier\PropertyModifierSplit;
use Icinga\Module\Director\PropertyModifier\PropertyModifierStripDomain;
use Icinga\Module\Director\PropertyModifier\PropertyModifierSubstring;
@ -105,6 +106,7 @@ $directorHooks = [
PropertyModifierRegexSplit::class,
PropertyModifierRejectOrSelect::class,
PropertyModifierReplace::class,
PropertyModifierSkipDuplicates::class,
PropertyModifierSplit::class,
PropertyModifierStripDomain::class,
PropertyModifierSubstring::class,