Skip to content

Commit 2448ecc

Browse files
committed
Actually return null on missing users
Several objects with getUser() functions (document, packet, etc) were expecting a null user if the ID wasn't found, but a UserNotFoundException was being thrown instead which prevented some index pages from being displayed. Adds User::findUserById($id) function to libraries\User. Returns the user object or null. Updates some objects to use this.
1 parent d8639da commit 2448ecc

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

src/libraries/Document.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ public function getURI() {
265265
}
266266

267267
public function getUser() {
268-
if (is_null($this->user_id)) return null;
269-
return new User($this->user_id);
268+
return User::findUserById($this->user_id);
270269
}
271270

272271
public function getUserId() {

src/libraries/NewsPost.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ public function getURI() {
302302
}
303303

304304
public function getUser() {
305-
if (is_null($this->user_id)) return null;
306-
return new User($this->user_id);
305+
return User::findUserById($this->user_id);
307306
}
308307

309308
public function getUserId() {

src/libraries/Packet.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,7 @@ public function getUsedBy() {
523523
}
524524

525525
public function getUser() {
526-
if ( is_null( $this->user_id )) {
527-
return null;
528-
}
529-
530-
return new User( $this->user_id );
526+
return User::findUserById($this->user_id);
531527
}
532528

533529
public function getUserId() {

src/libraries/Server.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ public function getUpdatedDateTime() {
177177
}
178178

179179
public function getUser() {
180-
if (is_null($this->user_id)) return null;
181-
return new User($this->user_id);
180+
return User::findUserById($this->user_id);
182181
}
183182

184183
public function getUserId() {

src/libraries/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,16 @@ public function getAcl($acl) {
341341
return ($this->options_bitmask & $acl);
342342
}
343343

344+
public static function findUserById($user_id) {
345+
if (is_null($user_id)) return null;
346+
347+
try {
348+
return new User($user_id);
349+
} catch (UserNotFoundException $e) {
350+
return null;
351+
}
352+
}
353+
344354
public static function &getAllUsers(
345355
$order = null, $limit = null, $index = null
346356
) {

0 commit comments

Comments
 (0)