From e6d4ea1ab6d97d9fc311ff7158634cd59b51e64a Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 25 Nov 2024 13:56:31 -0600 Subject: [PATCH] Tweak how User::$Benefits getter --- lib/User.php | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/User.php b/lib/User.php index c0b3053d..038a1be4 100644 --- a/lib/User.php +++ b/lib/User.php @@ -101,19 +101,24 @@ class User{ protected function GetBenefits(): Benefits{ if(!isset($this->_Benefits)){ - $result = Db::Query(' - SELECT * - from Benefits - where UserId = ? - ', [$this->UserId], Benefits::class); + if(isset($this->UserId)){ + $result = Db::Query(' + SELECT * + from Benefits + where UserId = ? + ', [$this->UserId], Benefits::class); - if(sizeof($result) == 0){ - $this->_Benefits = new Benefits(); - $this->_IsRegistered = false; + if(sizeof($result) == 0){ + $this->_Benefits = new Benefits(); + $this->_IsRegistered = false; + } + else{ + $this->_Benefits = $result[0]; + $this->_IsRegistered = true; + } } else{ - $this->_Benefits = $result[0]; - $this->_IsRegistered = true; + $this->_Benefits = new Benefits(); } } @@ -167,12 +172,6 @@ class User{ $this->PasswordHash = null; } - if(!isset($this->_Benefits)){ - // Set this for validation purposes. - // Skip the accessor because it will attempt to use `$this->UserId` which may not be set yet. - $this->_Benefits = new Benefits(); - } - // Some benefits require this `User` to have a password set. if($this->Benefits->RequiresPassword && $this->PasswordHash === null){ $error->Add(new Exceptions\BenefitsRequirePasswordException());