From b4e47246b1d8642e64bb852b836ca962d5101116 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 27 Oct 2020 07:48:56 +0200 Subject: [PATCH] Updated record tests --- app/controllers/api/account.php | 48 ++++++++++++++------------------- app/controllers/api/teams.php | 14 +++++----- app/controllers/api/users.php | 19 +++++-------- 3 files changed, 33 insertions(+), 48 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index eb76e74401..53bd8bb664 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -202,15 +202,13 @@ App::post('/v1/account/sessions') 'deviceModel' => $dd->getModel(), ]); - try { - $record = $geodb->get($request->getIP()); + $record = $geodb->get($request->getIP()); - if($record) { - $session - ->setAttribute('countryCode', \strtolower($record['country']['iso_code'])) - ; - } - } catch (\Exception $e) { + if($record) { + $session + ->setAttribute('countryCode', \strtolower($record['country']['iso_code'])) + ; + } else { $session ->setAttribute('countryCode', '--') ; @@ -542,15 +540,13 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') 'deviceModel' => $dd->getModel(), ]); - try { - $record = $geodb->get($request->getIP()); + $record = $geodb->get($request->getIP()); - if ($record) { - $session - ->setAttribute('countryCode', \strtolower($record['country']['iso_code'])) - ; - } - } catch (\Exception $e) { + if($record) { + $session + ->setAttribute('countryCode', \strtolower($record['country']['iso_code'])) + ; + } else { $session ->setAttribute('countryCode', '--') ; @@ -761,20 +757,16 @@ App::get('/v1/account/logs') 'deviceModel' => $dd->getModel(), ]); - try { - $record = $geodb->get($log['ip']); + $record = $geodb->get($log['ip']); - if ($record) { - $output[$i]['countryCode'] = \strtolower($record['country']['iso_code']); - $output[$i]['countryCode'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); - } else { - $output[$i]['countryCode'] = '--'; - $output[$i]['countryCode'] = $locale->getText('locale.country.unknown'); - } - } catch (\Exception $e) { - $output[$i]->setAttribute('countryCode', '--'); - $output[$i]->setAttribute('countryName', $locale->getText('locale.country.unknown')); + if ($record) { + $output[$i]['countryCode'] = \strtolower($record['country']['iso_code']); + $output[$i]['countryCode'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); + } else { + $output[$i]['countryCode'] = '--'; + $output[$i]['countryCode'] = $locale->getText('locale.country.unknown'); } + } $response->dynamic(new Document(['logs' => $output]), Response::MODEL_LOG_LIST); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 9b60606a3b..e9e479ceb0 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -569,15 +569,13 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') 'deviceModel' => $dd->getModel(), ]); - try { - $record = $geodb->get($request->getIP()); + $record = $geodb->get($request->getIP()); - if ($record) { - $session - ->setAttribute('countryCode', \strtolower($record['country']['iso_code'])) - ; - } - } catch (\Exception $e) { + if($record) { + $session + ->setAttribute('countryCode', \strtolower($record['country']['iso_code'])) + ; + } else { $session ->setAttribute('countryCode', '--') ; diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 69c5e0c3b9..a0f8fcebd8 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -284,19 +284,14 @@ App::get('/v1/users/:userId/logs') 'deviceModel' => $dd->getModel(), ]); - try { - $record = $geodb->get($log['ip']); + $record = $geodb->get($log['ip']); - if($record){ - $output[$i]['countryCode'] = \strtolower($record['country']['iso_code']); - $output[$i]['countryName'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); - } else{ - $output[$i]['countryCode'] = '--'; - $output[$i]['countryName'] = $locale->getText('locale.country.unknown'); - } - } catch (\Exception $e) { - $output[$i]->setAttribute('countryCode', '--'); - $output[$i]->setAttribute('countryName', $locale->getText('locale.country.unknown')); + if($record){ + $output[$i]['countryCode'] = \strtolower($record['country']['iso_code']); + $output[$i]['countryName'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); + } else { + $output[$i]['countryCode'] = '--'; + $output[$i]['countryName'] = $locale->getText('locale.country.unknown'); } }