diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2025-04-01 09:07:31 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2025-04-01 11:26:24 +0200 |
| commit | 861c32e6889f33faff7f8fbb69d287f9e57d478b (patch) | |
| tree | 76cabe52a2cfe6afd5ac5eb7094c70c5174b306a /lib | |
| parent | fbffec70730f8247b04d94cdcae6f4971b78b91e (diff) | |
prevent php8 warnings, fixes #5441
Closes #5441
Merge request studip/studip!4084
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/classes/MvvPerm.php | 38 | ||||
| -rw-r--r-- | lib/functions.php | 2 | ||||
| -rw-r--r-- | lib/models/ContentTermsOfUse.class.php | 9 | ||||
| -rw-r--r-- | lib/models/Courseware/StructuralElement.php | 18 | ||||
| -rw-r--r-- | lib/models/FileRef.php | 2 | ||||
| -rw-r--r-- | lib/models/SimpleORMap.class.php | 7 | ||||
| -rw-r--r-- | lib/models/Studiengang.php | 6 | ||||
| -rw-r--r-- | lib/models/resources/ResourceBooking.class.php | 4 |
8 files changed, 50 insertions, 36 deletions
diff --git a/lib/classes/MvvPerm.php b/lib/classes/MvvPerm.php index 93f9f44..cc254f5 100644 --- a/lib/classes/MvvPerm.php +++ b/lib/classes/MvvPerm.php @@ -39,7 +39,7 @@ class MvvPerm { */ const PERM_ADMIN = 15; - private static $privileges; + private static $privileges = null; private static $roles; @@ -348,18 +348,18 @@ class MvvPerm { if (count($institutes_assigned_role) === 0 || count(array_intersect($institut_ids, $institutes_assigned_role))) { if (!$status) { - $priv = intval(self::$privileges[$mvv_table]['default_table'][$role->rolename]); + $priv = intval(self::$privileges[$mvv_table]['default_table'][$role->rolename] ?? 0); } else { - $priv = intval(self::$privileges[$mvv_table]['table'][$status][$role->rolename]); + $priv = intval(self::$privileges[$mvv_table]['table'][$status][$role->rolename] ?? 0); } } else { $priv = 0; } } else { if (!$status) { - $priv = intval(self::$privileges[$mvv_table]['default_table'][$role->rolename]); + $priv = intval(self::$privileges[$mvv_table]['default_table'][$role->rolename] ?? 0); } else { - $priv = intval(self::$privileges[$mvv_table]['table'][$status][$role->rolename]); + $priv = intval(self::$privileges[$mvv_table]['table'][$status][$role->rolename] ?? 0); } } @@ -465,33 +465,35 @@ class MvvPerm { if (count($institut_ids)) { $institutes_assigned_role = RolePersistence::getAssignedRoleInstitutes($user_id, $role->roleid); // count($institutes_assigned_role) === 0 means global role. - if (count($institutes_assigned_role) === 0 - || count(array_intersect($institut_ids, $institutes_assigned_role))) { + if ( + count($institutes_assigned_role) === 0 + || count(array_intersect($institut_ids, $institutes_assigned_role)) + ) { $priv = is_array($field) - ? self::$privileges[$mvv_table]['fields'][$field[0]][$field[1]][$status][$role->rolename] - : self::$privileges[$mvv_table]['fields'][$field][$status][$role->rolename]; + ? self::$privileges[$mvv_table]['fields'][$field[0]][$field[1]][$status][$role->rolename] ?? null + : self::$privileges[$mvv_table]['fields'][$field][$status][$role->rolename] ?? null; if (is_null($priv)) { $priv = is_array($field) - ? self::$privileges[$mvv_table]['fields'][$field[0]]['default'][$status][$role->rolename] - : self::$privileges[$mvv_table]['fields'][$field]['default'][$role->rolename]; + ? self::$privileges[$mvv_table]['fields'][$field[0]]['default'][$status][$role->rolename] ?? null + : self::$privileges[$mvv_table]['fields'][$field]['default'][$role->rolename] ?? null; } if (is_null($priv)) { - $priv = self::$privileges[$mvv_table]['default_fields'][$role->rolename]; + $priv = self::$privileges[$mvv_table]['default_fields'][$role->rolename] ?? null; } } else { $priv = 0; } } else { $priv = is_array($field) - ? self::$privileges[$mvv_table]['fields'][$field[0]][$field[1]][$status][$role->rolename] - : self::$privileges[$mvv_table]['fields'][$field][$status][$role->rolename]; + ? self::$privileges[$mvv_table]['fields'][$field[0]][$field[1]][$status][$role->rolename] ?? null + : self::$privileges[$mvv_table]['fields'][$field][$status][$role->rolename] ?? null; if (is_null($priv)) { $priv = is_array($field) - ? self::$privileges[$mvv_table]['fields'][$field[0]]['default'][$status][$role->rolename] - : self::$privileges[$mvv_table]['fields'][$field]['default'][$role->rolename]; + ? self::$privileges[$mvv_table]['fields'][$field[0]]['default'][$status][$role->rolename] ?? null + : self::$privileges[$mvv_table]['fields'][$field]['default'][$role->rolename] ?? null; } if (is_null($priv)) { - $priv = self::$privileges[$mvv_table]['default_fields'][$role->rolename]; + $priv = self::$privileges[$mvv_table]['default_fields'][$role->rolename] ?? null; } } $priv = intval($priv); @@ -564,7 +566,7 @@ class MvvPerm { { if (self::$privileges === null) { $cache = StudipCacheFactory::getCache(); - self::$privileges = unserialize($cache->read(MVV::CACHE_KEY . '/privileges')); + self::$privileges = unserialize($cache->read(MVV::CACHE_KEY . '/privileges')) ?: []; } if (self::$privileges[$mvv_table] === null) { diff --git a/lib/functions.php b/lib/functions.php index 8d639e8..f08ab88 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -717,7 +717,7 @@ function get_users_online_count($active_time = 10) $online_count = $statement->fetchColumn(); $cache->write("online_count/{$active_time}", $online_count, 180); } - if ($GLOBALS['user']->id && $GLOBALS['user']->id !== 'nobody') { + if (User::findCurrent()) { --$online_count; } return $online_count > 0 ? $online_count : 0; diff --git a/lib/models/ContentTermsOfUse.class.php b/lib/models/ContentTermsOfUse.class.php index fb2e592..f87b174 100644 --- a/lib/models/ContentTermsOfUse.class.php +++ b/lib/models/ContentTermsOfUse.class.php @@ -205,10 +205,15 @@ class ContentTermsOfUse extends SimpleORMap $seminar = Seminar::GetInstance($context_id); $timed_admission = $seminar->getAdmissionTimeFrame(); - if ($seminar->admission_prelim + if ( + $seminar->admission_prelim || $seminar->isPasswordProtected() || $seminar->isAdmissionLocked() - || (is_array($timed_admission) && $timed_admission['end_time'] > 0 && $timed_admission['end_time'] < time()) + || ( + $timed_admission + && $timed_admission['end_time'] > 0 + && $timed_admission['end_time'] < time() + ) ) { return true; } diff --git a/lib/models/Courseware/StructuralElement.php b/lib/models/Courseware/StructuralElement.php index 35a0184..4b29313 100644 --- a/lib/models/Courseware/StructuralElement.php +++ b/lib/models/Courseware/StructuralElement.php @@ -267,6 +267,10 @@ class StructuralElement extends \SimpleORMap implements \PrivacyObject, \Feedbac */ public function canEdit($user): bool { + if (!$user) { + return false; + } + if ($GLOBALS['perm']->have_perm('root', $user->id)) { return true; } @@ -322,13 +326,13 @@ class StructuralElement extends \SimpleORMap implements \PrivacyObject, \Feedbac public function canRead($user): bool { // root darf immer - if ($GLOBALS['perm']->have_perm('root', $user->id)) { + if ($user && $GLOBALS['perm']->have_perm('root', $user->id)) { return true; } switch ($this->range_type) { case 'user': - if ($this->range_id === $user->id) { + if ($user && $this->range_id === $user->id) { return true; } @@ -339,7 +343,7 @@ class StructuralElement extends \SimpleORMap implements \PrivacyObject, \Feedbac return $this->hasReadApproval($user); case 'course': - if (!$GLOBALS['perm']->have_studip_perm('user', $this->range_id, $user->id)) { + if (!$user || !$GLOBALS['perm']->have_studip_perm('user', $this->range_id, $user->id)) { return false; } @@ -361,20 +365,20 @@ class StructuralElement extends \SimpleORMap implements \PrivacyObject, \Feedbac public function canVisit($user): bool { // root darf immer - if ($GLOBALS['perm']->have_perm('root', $user->id)) { + if ($user && $GLOBALS['perm']->have_perm('root', $user->id)) { return true; } switch ($this->range_type) { case 'user': - if ($this->range_id === $user->id) { + if ($user && $this->range_id === $user->id) { return true; } return $this->hasReadApproval($user); case 'course': - if (!$GLOBALS['perm']->have_studip_perm('user', $this->range_id, $user->id)) { + if (!$user || !$GLOBALS['perm']->have_studip_perm('user', $this->range_id, $user->id)) { return false; } @@ -1219,7 +1223,7 @@ SQL; if ($this->range_type === 'user') { return 'contents/courseware/courseware/' . $unit->id . '#/structural_element/' . $this->id; } - + return 'course/courseware/courseware/' . $unit->id . '?cid=' . $this->range_id . '#/structural_element/' . $this->id; } diff --git a/lib/models/FileRef.php b/lib/models/FileRef.php index 2a7f485..694c0c5 100644 --- a/lib/models/FileRef.php +++ b/lib/models/FileRef.php @@ -224,7 +224,7 @@ class FileRef extends SimpleORMap implements PrivacyObject, FeedbackRange public function incrementDownloadCounter() { if ( - $this->user_id === User::findCurrent()->id + (User::findCurrent() && $this->user_id === User::findCurrent()->id) || $this->folder instanceof HomeworkFolder ) { return 0; diff --git a/lib/models/SimpleORMap.class.php b/lib/models/SimpleORMap.class.php index aaf2e7d..19b1381 100644 --- a/lib/models/SimpleORMap.class.php +++ b/lib/models/SimpleORMap.class.php @@ -431,8 +431,11 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate self::$schemes = unserialize($cache->read('DB_TABLE_SCHEMES')) ?: []; } if (!isset(self::$schemes[$db_table])) { + $pk = []; + $db_fields = []; + $db = DBManager::get()->query("SHOW COLUMNS FROM $db_table"); - while($rs = $db->fetch(PDO::FETCH_ASSOC)){ + while ($rs = $db->fetch(PDO::FETCH_ASSOC)){ $db_fields[strtolower($rs['Field'])] = [ 'name' => $rs['Field'], 'null' => $rs['Null'], @@ -440,7 +443,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate 'type' => $rs['Type'], 'extra' => $rs['Extra'] ]; - if ($rs['Key'] == 'PRI'){ + if ($rs['Key'] === 'PRI'){ $pk[] = strtolower($rs['Field']); } } diff --git a/lib/models/Studiengang.php b/lib/models/Studiengang.php index ee89abd..432134d 100644 --- a/lib/models/Studiengang.php +++ b/lib/models/Studiengang.php @@ -514,12 +514,12 @@ class Studiengang extends ModuleManagementModelTreeItem $placeholders = [ 'study_course_name', 'degree_name', - 'degree_category' + 'degree_category', ]; $replacements = [ $this->name, - $this->abschluss->name, - $this->abschluss->category->name + $this->abschluss->name ?? '?', + $this->abschluss->category->name ?? '?', ]; return self::formatDisplayName($template, $placeholders, $replacements); } diff --git a/lib/models/resources/ResourceBooking.class.php b/lib/models/resources/ResourceBooking.class.php index 84fc9c7..158d4d1 100644 --- a/lib/models/resources/ResourceBooking.class.php +++ b/lib/models/resources/ResourceBooking.class.php @@ -1737,8 +1737,8 @@ class ResourceBooking extends SimpleORMap implements PrivacyObject, Studip\Calen if ($this->assigned_course_date instanceof CourseDate) { $course = $this->assigned_course_date->course; if ($course instanceof Course) { - $has_perms = $GLOBALS['perm']->have_studip_perm('user', $course->id, $user->id); - $vis_perms = $GLOBALS['perm']->have_perm(Config::get()->SEM_VISIBILITY_PERM, $user->id); + $has_perms = $GLOBALS['perm']->have_studip_perm('user', $course->id, $user->id ?? null); + $vis_perms = $GLOBALS['perm']->have_perm(Config::get()->SEM_VISIBILITY_PERM, $user->id ?? null); if ($has_perms || $vis_perms || $course->visible) { $event_title = $this->getAssignedUserName(); } |
