More checks in the bounce cron job.

This commit is contained in:
James Cole
2015-08-19 19:21:39 +02:00
parent a65d609fdc
commit 21b6ad7a41

View File

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