diff --git a/app/Http/Controllers/CronController.php b/app/Http/Controllers/CronController.php index 31c7939f26..a10531c1ae 100644 --- a/app/Http/Controllers/CronController.php +++ b/app/Http/Controllers/CronController.php @@ -25,32 +25,42 @@ class CronController extends Controller if (strlen(env('SENDGRID_USERNAME')) > 0 && strlen(env('SENDGRID_PASSWORD')) > 0) { - $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)); + $set = [ + 'blocks' => 'https://api.sendgrid.com/api/blocks.get.json', + 'bounces' => 'https://api.sendgrid.com/api/bounces.get.json', + 'invalids' => 'https://api.sendgrid.com/api/invalidemails.get.json', - /* - * Loop the result, if any. - */ - if (is_array($data)) { - echo 'Found ' . count($data) . ' entries in the SendGrid bounce list.' . "\n"; - foreach ($data as $entry) { - $address = $entry->email; - $user = User::where('email', $address)->where('blocked', 0)->first(); - if (!is_null($user)) { - echo 'Found a user: ' . $address . ', who is now blocked.' . "\n"; - $user->blocked = 1; - $user->blocked_code = 'bounced'; - $user->password = 'bounced'; - $user->save(); - } else { - echo 'Found no user: ' . $address . ', did nothing.' . "\n"; + ]; + echo '
'; + foreach ($set as $name => $URL) { + + + $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)) { + echo 'Found ' . count($data) . ' entries in the SendGrid ' . $name . ' list.' . "\n"; + foreach ($data as $entry) { + $address = $entry->email; + $user = User::where('email', $address)->where('blocked', 0)->first(); + if (!is_null($user)) { + echo 'Found a user: ' . $address . ', who is now blocked.' . "\n"; + $user->blocked = 1; + $user->blocked_code = 'bounced'; + $user->password = 'bounced'; + $user->save(); + } else { + echo 'Found no user: ' . $address . ', did nothing.' . "\n"; + } } } }