From 079e6e6514bfa0dea57b706c0196fc5dbd2e3ed3 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 3 Aug 2022 09:01:09 +0200 Subject: [PATCH] ImportExportDeniedProperties: extract logic --- library/Director/Data/Exporter.php | 41 +-------------- .../Data/ImportExportDeniedProperties.php | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 library/Director/Data/ImportExportDeniedProperties.php diff --git a/library/Director/Data/Exporter.php b/library/Director/Data/Exporter.php index c21a9ae5..56982961 100644 --- a/library/Director/Data/Exporter.php +++ b/library/Director/Data/Exporter.php @@ -20,7 +20,6 @@ use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Objects\IcingaTemplateChoice; -use Icinga\Module\Director\Objects\ImportRowModifier; use Icinga\Module\Director\Objects\ImportSource; use Icinga\Module\Director\Objects\InstantiatedViaHook; use Icinga\Module\Director\Objects\SyncRule; @@ -34,29 +33,6 @@ use Zend_Db_Select; class Exporter { - protected static $denyProperties = [ - DirectorJob::class => [ - 'last_attempt_succeeded', - 'last_error_message', - 'ts_last_attempt', - 'ts_last_error', - ], - ImportSource::class => [ - // No state export - 'import_state', - 'last_error_message', - 'last_attempt', - ], - ImportRowModifier::class => [ - // Not state, but to be removed: - 'source_id', - ], - SyncRule::class => [ - 'sync_state', - 'last_error_message', - 'last_attempt', - ], - ]; /** @var Adapter|\Zend_Db_Adapter_Abstract */ protected $db; @@ -89,7 +65,7 @@ class Exporter ? $this->exportIcingaObject($object) : $this->exportDbObject($object); - $this->stripDeniedProperties($props, $object); + ImportExportDeniedProperties::strip($props, $object, $this->showIds); $this->appendTypeSpecificRelations($props, $object); if ($this->chosenProperties !== null) { @@ -344,21 +320,6 @@ class Exporter return $db->fetchOne($query); } - protected function stripDeniedProperties(array &$props, DbObject $object) - { - // TODO: this used to exist. Double-check all imports to verify it's not in use - // $originalId = $props['id']; - if (! $this->showIds) { - unset($props['id']); - } - $class = get_class($object); - if (isset(self::$denyProperties[$class])) { - foreach (self::$denyProperties[$class] as $key) { - unset($props[$key]); - } - } - } - protected function exportRowModifiers(ImportSource $object) { $modifiers = []; diff --git a/library/Director/Data/ImportExportDeniedProperties.php b/library/Director/Data/ImportExportDeniedProperties.php new file mode 100644 index 00000000..747eb0fc --- /dev/null +++ b/library/Director/Data/ImportExportDeniedProperties.php @@ -0,0 +1,52 @@ + [ + 'last_attempt_succeeded', + 'last_error_message', + 'ts_last_attempt', + 'ts_last_error', + ], + ImportSource::class => [ + // No state export + 'import_state', + 'last_error_message', + 'last_attempt', + ], + ImportRowModifier::class => [ + // Not state, but to be removed: + 'source_id', + ], + SyncRule::class => [ + 'sync_state', + 'last_error_message', + 'last_attempt', + ], + ]; + + public static function strip(array &$props, DbObject $object, $showIds = false) + { + // TODO: this used to exist. Double-check all imports to verify it's not in use + // $originalId = $props['id']; + + if (! $showIds) { + unset($props['id']); + } + $class = get_class($object); + if (isset(self::$denyProperties[$class])) { + foreach (self::$denyProperties[$class] as $key) { + unset($props[$key]); + } + } + } +}