summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Widget/IcingaConfigDiff.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:31 +0000
commitf66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Web/Widget/IcingaConfigDiff.php
parentInitial commit. (diff)
downloadicingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz
icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Web/Widget/IcingaConfigDiff.php')
-rw-r--r--library/Director/Web/Widget/IcingaConfigDiff.php58
1 files changed, 58 insertions, 0 deletions
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 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Widget;
+
+use gipfl\Diff\HtmlRenderer\SideBySideDiff;
+use gipfl\Diff\PhpDiff;
+use Icinga\Module\Director\IcingaConfig\IcingaConfig;
+use ipl\Html\Html;
+use ipl\Html\HtmlDocument;
+use ipl\Html\ValidHtml;
+
+class IcingaConfigDiff extends HtmlDocument
+{
+ public function __construct(IcingaConfig $left, IcingaConfig $right)
+ {
+ foreach (static::getDiffs($left, $right) as $filename => $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;
+ }
+}