From 23fa92f4cead19cee760a7a86f794573a67e5a6f Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 16 Oct 2023 23:13:38 +0100 Subject: [PATCH] Check that the location is valid before debugging Signed-off-by: snipe --- app/Console/Commands/LdapSync.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index 29b9eced34..afe1070dd0 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -108,13 +108,17 @@ class LdapSync extends Command $location = null; // TODO - this would be better called "$default_location", which is more explicit about its purpose if ($this->option('location') != '') { - $location = Location::where('name', '=', $this->option('location'))->first(); - Log::debug('Location name '.$this->option('location').' passed'); - Log::debug('Importing to '.$location->name.' ('.$location->id.')'); + if ($location = Location::where('name', '=', $this->option('location'))->first()) { + Log::debug('Location name '.$this->option('location').' passed'); + Log::debug('Importing to '.$location->name.' ('.$location->id.')'); + } + } elseif ($this->option('location_id') != '') { - $location = Location::where('id', '=', $this->option('location_id'))->first(); - Log::debug('Location ID '.$this->option('location_id').' passed'); - Log::debug('Importing to '.$location->name.' ('.$location->id.')'); + if ($location = Location::where('id', '=', $this->option('location_id'))->first()) { + Log::debug('Location ID '.$this->option('location_id').' passed'); + Log::debug('Importing to '.$location->name.' ('.$location->id.')'); + } + } if (! isset($location)) {