From dfaffc5c7d43cde1401000c02d6f0638059c733d Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Mon, 12 Feb 2024 11:49:59 +0000
Subject: [PATCH] fixes #3739

Closes #3739

Merge request studip/studip!2597
---
 lib/classes/MyRealmModel.php | 2 +-
 lib/models/OERHostOERSI.php  | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/classes/MyRealmModel.php b/lib/classes/MyRealmModel.php
index d82218980ef..1ba90a574e2 100644
--- a/lib/classes/MyRealmModel.php
+++ b/lib/classes/MyRealmModel.php
@@ -677,7 +677,7 @@ class MyRealmModel
 
             // Now sort courses by sem_tree entry order.
             uksort($_tmp_courses[$sem_key], function ($a, $b) use ($order, $max) {
-                return (str_pad($order[$a], $max, '0') - str_pad($order[$b], $max, '0'));
+                return str_pad($order[$a] ?? '', $max, '0') - str_pad($order[$b] ?? '', $max, '0');
             });
 
             //At this point the $_tmp_courses array is sorted by the ordering
diff --git a/lib/models/OERHostOERSI.php b/lib/models/OERHostOERSI.php
index 1b5528bea9f..52e50d35a2b 100644
--- a/lib/models/OERHostOERSI.php
+++ b/lib/models/OERHostOERSI.php
@@ -81,9 +81,9 @@ class OERHostOERSI extends OERHost
                     if (!$material['category']) {
                         $material['category'] = $material->autoDetectCategory();
                     }
-                    $material['front_image_content_type'] = $material_data['_source']['image'] ? 'image/jpg' : null;
+                    $material['front_image_content_type'] = !empty($material_data['_source']['image']) ? 'image/jpg' : null;
                     $material['data'] = [
-                        'front_image_url' => $material_data['_source']['image'],
+                        'front_image_url' => $material_data['_source']['image'] ?? null,
                         'download' => $material_data['_source']['encoding'][0]['contentUrl'] ?: '',
                         'id' => $material_data['_id'],
                         'organization' => $material_data['_source']['sourceOrganization'][0]['name'] ?: $material_data['_source']['publisher'][0]['name']
@@ -102,7 +102,9 @@ class OERHostOERSI extends OERHost
                     $material->setUsers($userdata);
 
                     //set topics:
-                    $material->setTopics($material_data['_source']['keywords']);
+                    if (isset($material_data['_source']['keywords'])) {
+                        $material->setTopics($material_data['_source']['keywords']);
+                    }
 
                 }
             } else {
-- 
GitLab