From d1d4a5293453f7f4c844175878893e294c07980c Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 24 Jul 2015 13:23:02 +0200 Subject: [PATCH] Catch empty send grid credentials. --- app/Http/Controllers/CronController.php | 43 +++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/CronController.php b/app/Http/Controllers/CronController.php index 1e90bda468..c3774a9afe 100644 --- a/app/Http/Controllers/CronController.php +++ b/app/Http/Controllers/CronController.php @@ -23,27 +23,30 @@ class CronController extends Controller public function sendgrid() { - $URL = 'https://api.sendgrid.com/api/bounces.get.json'; - $parameters = [ - 'api_user' => env('SENDGRID_USERNAME'), - 'api_key' => env('SENDGRID_PASSWORD'), - 'date' => 1, - 'days' => 7 - ]; - $fullURL = $URL . '?' . http_build_query($parameters); - $data = json_decode(file_get_contents($fullURL)); + if (strlen(env('SENDGRID_USERNAME')) > 0 && strlen(env('SENDGRID_PASSWORD')) > 0) { - /* - * Loop the result, if any. - */ - if (is_array($data)) { - foreach ($data as $entry) { - $address = $entry->email; - $user = User::where('email', $address)->where('blocked', 0)->first(); - if (!is_null($user)) { - $user->blocked = 1; - $user->password = 'bounced'; - $user->save(); + $URL = 'https://api.sendgrid.com/api/bounces.get.json'; + $parameters = [ + 'api_user' => env('SENDGRID_USERNAME'), + 'api_key' => env('SENDGRID_PASSWORD'), + 'date' => 1, + 'days' => 7 + ]; + $fullURL = $URL . '?' . http_build_query($parameters); + $data = json_decode(file_get_contents($fullURL)); + + /* + * Loop the result, if any. + */ + if (is_array($data)) { + foreach ($data as $entry) { + $address = $entry->email; + $user = User::where('email', $address)->where('blocked', 0)->first(); + if (!is_null($user)) { + $user->blocked = 1; + $user->password = 'bounced'; + $user->save(); + } } } }