fix(User): add null and array checks before session data operations

Ensure that session data is only processed if it exists and is an array. This prevents potential errors when attempting to cache or remove user session data. Updated methods `cache_set_userdata` and `cache_rm_userdata` to include necessary checks.
This commit is contained in:
Yury Pikhtarev 2025-06-18 12:41:01 +04:00
commit ec10223528
No known key found for this signature in database

View file

@ -151,7 +151,9 @@ class User
$update_sessions_table = true; $update_sessions_table = true;
} }
Sessions::cache_set_userdata($this->data); if ($this->data) {
Sessions::cache_set_userdata($this->data);
}
} }
} }
@ -335,11 +337,13 @@ class User
*/ */
public function session_end(bool $update_lastvisit = false, bool $set_cookie = true) public function session_end(bool $update_lastvisit = false, bool $set_cookie = true)
{ {
Sessions::cache_rm_userdata($this->data); if ($this->data && is_array($this->data)) {
DB()->query(" Sessions::cache_rm_userdata($this->data);
DELETE FROM " . BB_SESSIONS . " DB()->query("
WHERE session_id = '{$this->data['session_id']}' DELETE FROM " . BB_SESSIONS . "
"); WHERE session_id = '{$this->data['session_id']}'
");
}
if (!IS_GUEST) { if (!IS_GUEST) {
if ($update_lastvisit) { if ($update_lastvisit) {