Skip to content

Commit 64ef845

Browse files
committed
Fix $current_developer can be null
1 parent b25acd9 commit 64ef845

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/Controller/AppController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,31 @@ public function beforeFilter(EventInterface $event)
141141
{
142142
$controllerName = $this->request->getParam('controller');
143143
$this->set('current_controller', $controllerName);
144-
$notif_count = 0;
145144

146145
$devId = $this->request->getSession()->read('Developer.id');
147-
if ($devId) {
146+
if ($devId !== null) {
148147
$response = $this->checkReadonlyAccess();
149148
if ($response !== null) {
150149
// This is a security check
151150
// The response can be printed if you remove this line
152151
return $response;
153152
}
153+
}
154154

155+
$current_developer = null;
156+
if ($devId !== null) {
157+
// Check if the user still exists in the database
155158
$current_developer = TableRegistry::getTableLocator()->get('Developers')->
156159
findById($devId)->all()->first();
160+
}
157161

162+
$notif_count = 0;
163+
if ($current_developer !== null) {
158164
$notif_count = TableRegistry::getTableLocator()->get('Notifications')->find(
159165
'all',
160-
conditions: ['developer_id' => (int) isset($current_developer) ? $current_developer['id'] : null]
166+
conditions: ['developer_id' => $current_developer['id']]
161167
)->count();
168+
162169
$this->set('current_developer', $current_developer);
163170
$this->set('developer_signed_in', true);
164171

0 commit comments

Comments
 (0)