From fe58e4f4220d6685b91bf516374e33936e1075e3 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 14 Jan 2018 17:47:26 +0100 Subject: database: updated checks for selectOne --- includes/pages/user_myshifts.php | 1 - 1 file changed, 1 deletion(-) (limited to 'includes/pages/user_myshifts.php') diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index f605792f..5819f5c6 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -32,7 +32,6 @@ function user_myshifts() } $shifts_user = DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$shift_entry_id]); - if ($request->has('reset')) { if ($request->input('reset') == 'ack') { User_reset_api_key($user); -- cgit v1.2.3-54-g00ecf From 175c335810817ff3e989f368889274d3f09c08b1 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 29 Aug 2018 18:08:45 +0200 Subject: Db::selectOne() should return null if result is empty --- includes/model/Shifts_model.php | 2 +- includes/pages/user_myshifts.php | 2 +- src/Database/Db.php | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'includes/pages/user_myshifts.php') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 94513ff3..b5e3a205 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -182,7 +182,7 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) /** * @param array $shift * @param array $angeltype - * @return array + * @return array|null */ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) { diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 5819f5c6..b61fc1e4 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -71,7 +71,7 @@ function user_myshifts() $shifts_user['UID'], ] ); - if (count($shift) > 0) { + if (!empty($shift)) { $freeloaded = $shift['freeloaded']; $freeload_comment = $shift['freeload_comment']; diff --git a/src/Database/Db.php b/src/Database/Db.php index f34d1564..c0871e68 100644 --- a/src/Database/Db.php +++ b/src/Database/Db.php @@ -45,14 +45,19 @@ class Db * * @param string $query * @param array $bindings - * @return array + * @return array|null */ public static function selectOne($query, array $bindings = []) { $result = self::connection()->selectOne($query, $bindings); // @TODO: remove typecast - return (array)$result; + $result = (array)$result; + if (empty($result)) { + return null; + } + + return $result; } /** -- cgit v1.2.3-54-g00ecf