From 9f383772be70e9090d4ca25b61a0f13a09a55869 Mon Sep 17 00:00:00 2001
From: Justus Dieckmann <justusdieckmann@wwu.de>
Date: Thu, 27 Apr 2023 14:37:56 +0200
Subject: [PATCH] Workflow backup: Do not save attributes when they are null

---
 .../backup/backup_lifecycle_workflow.php      | 20 ++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/classes/local/backup/backup_lifecycle_workflow.php b/classes/local/backup/backup_lifecycle_workflow.php
index 743a056..2e76889 100644
--- a/classes/local/backup/backup_lifecycle_workflow.php
+++ b/classes/local/backup/backup_lifecycle_workflow.php
@@ -107,7 +107,9 @@ class backup_lifecycle_workflow {
      */
     private function write_workflow() {
         foreach (get_object_vars($this->workflow) as $prop => $value) {
-            $this->writer->writeAttribute($prop, $value);
+            if (!is_null($value)) {
+                $this->writer->writeAttribute($prop, $value);
+            }
         }
     }
 
@@ -118,13 +120,17 @@ class backup_lifecycle_workflow {
         foreach ($this->trigger as $trigger) {
             $this->writer->startElement("trigger");
             foreach (get_object_vars($trigger) as $prop => $value) {
-                $this->writer->writeAttribute($prop, $value);
+                if (!is_null($value)) {
+                    $this->writer->writeAttribute($prop, $value);
+                }
             }
             $settings = settings_manager::get_settings($trigger->id, settings_type::TRIGGER);
             foreach ($settings as $name => $value) {
                 $this->writer->startElement("setting");
                 $this->writer->writeAttribute('name', $name);
-                $this->writer->writeAttribute('value', $value);
+                if (!is_null($value)) {
+                    $this->writer->writeAttribute('value', $value);
+                }
                 $this->writer->endElement();
             }
             $this->writer->endElement();
@@ -139,13 +145,17 @@ class backup_lifecycle_workflow {
         foreach ($this->steps as $step) {
             $this->writer->startElement("step");
             foreach (get_object_vars($step) as $prop => $value) {
-                $this->writer->writeAttribute($prop, $value);
+                if (!is_null($value)) {
+                    $this->writer->writeAttribute($prop, $value);
+                }
             }
             $settings = settings_manager::get_settings($step->id, settings_type::STEP);
             foreach ($settings as $name => $value) {
                 $this->writer->startElement("setting");
                 $this->writer->writeAttribute('name', $name);
-                $this->writer->writeAttribute('value', $value);
+                if (!is_null($value)) {
+                    $this->writer->writeAttribute('value', $value);
+                }
                 $this->writer->endElement();
             }
             $this->writer->endElement();
-- 
GitLab