From 46116209730837ab510865e917af65178e1f7593 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Thu, 30 Jun 2022 05:44:33 +0000
Subject: [PATCH] fix error in rrv2 models, fixes #1232

Closes #1232

Merge request studip/studip!744
---
 lib/models/resources/Resource.class.php       |  6 ++++--
 .../resources/ResourceBooking.class.php       |  2 ++
 .../resources/ResourceCategory.class.php      | 21 ++++++++-----------
 .../ResourcePropertyDefinition.class.php      |  4 +++-
 .../resources/ResourceRequest.class.php       |  2 +-
 5 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/lib/models/resources/Resource.class.php b/lib/models/resources/Resource.class.php
index c7c5b77a4c2..0cdd517a060 100644
--- a/lib/models/resources/Resource.class.php
+++ b/lib/models/resources/Resource.class.php
@@ -1581,7 +1581,7 @@ class Resource extends SimpleORMap implements StudipItem
      * @param mixed $state The state of the resource property.
      * @param User|null $user The user who wishes to set the property.
      *
-     * @return True, if the property state could be set, false otherwise.
+     * @return bool True, if the property state could be set, false otherwise.
      */
     public function setProperty(string $name, $state = '', $user = null)
     {
@@ -1638,6 +1638,8 @@ class Resource extends SimpleORMap implements StudipItem
             }
             return true;
         }
+
+        return false;
     }
 
     /**
@@ -2395,7 +2397,7 @@ class Resource extends SimpleORMap implements StudipItem
             return $perm_string;
         }
 
-
+        return '';
     }
 
     /**
diff --git a/lib/models/resources/ResourceBooking.class.php b/lib/models/resources/ResourceBooking.class.php
index 58c8ecb09c3..7f1fe03b8bc 100644
--- a/lib/models/resources/ResourceBooking.class.php
+++ b/lib/models/resources/ResourceBooking.class.php
@@ -1816,6 +1816,8 @@ class ResourceBooking extends SimpleORMap implements PrivacyObject, Studip\Calen
                 return 'daily';
             }
         }
+
+        return '';
     }
 
 
diff --git a/lib/models/resources/ResourceCategory.class.php b/lib/models/resources/ResourceCategory.class.php
index 0f7fae1e51d..2961ca2afba 100644
--- a/lib/models/resources/ResourceCategory.class.php
+++ b/lib/models/resources/ResourceCategory.class.php
@@ -339,19 +339,16 @@ class ResourceCategory extends SimpleORMap
         if ($existing_property) {
             $existing_property->requestable = $requestable ? '1' : '0';
             $existing_property->protected   = $protected ? '1' : '0';
-            if ($existing_property->isDirty()) {
-                if ($existing_property->store()) {
-                    return $existing_property;
-                } else {
-                    throw new ResourcePropertyException(
-                        sprintf(
-                            _('Fehler beim Aktualisieren der Eigenschaft %1$s (vom Typ %2$s)!'),
-                            $name,
-                            $type
-                        )
-                    );
-                }
+            if ($existing_property->isDirty() && !$existing_property->store()) {
+                throw new ResourcePropertyException(
+                    sprintf(
+                        _('Fehler beim Aktualisieren der Eigenschaft %1$s (vom Typ %2$s)!'),
+                        $name,
+                        $type
+                    )
+                );
             }
+            return $existing_property;
         } else {
             $definition = ResourcePropertyDefinition::findOneBySql(
                 'name = :name AND type = :type',
diff --git a/lib/models/resources/ResourcePropertyDefinition.class.php b/lib/models/resources/ResourcePropertyDefinition.class.php
index 1d5833026aa..b7d6b6eaa0a 100644
--- a/lib/models/resources/ResourcePropertyDefinition.class.php
+++ b/lib/models/resources/ResourcePropertyDefinition.class.php
@@ -298,7 +298,7 @@ class ResourcePropertyDefinition extends SimpleORMap
                 $invalid_state = true;
             }
         } elseif ($this->type == 'num') {
-            if (!preg_match('[0-9.]+', $state)) {
+            if (!preg_match('/[0-9.]+/', $state)) {
                 //not a number
                 $invalid_state = true;
             }
@@ -375,6 +375,8 @@ class ResourcePropertyDefinition extends SimpleORMap
             $property->state = $state;
             return $property;
         }
+
+        throw new Exception('Could not validate state');
     }
 
     public function __toString()
diff --git a/lib/models/resources/ResourceRequest.class.php b/lib/models/resources/ResourceRequest.class.php
index f539d646bda..1a1dbaaa194 100644
--- a/lib/models/resources/ResourceRequest.class.php
+++ b/lib/models/resources/ResourceRequest.class.php
@@ -1365,7 +1365,7 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
                     $parts[] = $rra->appointment->getFullname('include-room');
                 }
             }
-            $strings[] .= implode('; ', $parts);
+            $strings[] = implode('; ', $parts);
         } elseif ($this->termin_id) {
             if ($this->date) {
                 $strings[] = $this->date->getFullname('include-room');
-- 
GitLab