From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Web/Widget/IcingaConfigDiff.php | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 library/Director/Web/Widget/IcingaConfigDiff.php (limited to 'library/Director/Web/Widget/IcingaConfigDiff.php') diff --git a/library/Director/Web/Widget/IcingaConfigDiff.php b/library/Director/Web/Widget/IcingaConfigDiff.php new file mode 100644 index 0000000..800f1d9 --- /dev/null +++ b/library/Director/Web/Widget/IcingaConfigDiff.php @@ -0,0 +1,58 @@ + $diff) { + $this->add([ + Html::tag('h3', $filename), + $diff + ]); + } + } + + /** + * @param IcingaConfig $oldConfig + * @param IcingaConfig $newConfig + * @return ValidHtml[] + */ + public static function getDiffs(IcingaConfig $oldConfig, IcingaConfig $newConfig) + { + $oldFileNames = $oldConfig->getFileNames(); + $newFileNames = $newConfig->getFileNames(); + + $fileNames = array_merge($oldFileNames, $newFileNames); + + $diffs = []; + foreach ($fileNames as $filename) { + if (in_array($filename, $oldFileNames)) { + $left = $oldConfig->getFile($filename)->getContent(); + } else { + $left = ''; + } + + if (in_array($filename, $newFileNames)) { + $right = $newConfig->getFile($filename)->getContent(); + } else { + $right = ''; + } + if ($left === $right) { + continue; + } + + $diffs[$filename] = new SideBySideDiff(new PhpDiff($left, $right)); + } + + return $diffs; + } +} -- cgit v1.2.3