2016-02-24 13:13:55 -06:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* MailError.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
2016-05-20 01:57:45 -05:00
|
|
|
declare(strict_types = 1);
|
2016-02-24 13:13:55 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Jobs;
|
|
|
|
|
|
|
|
use ErrorException;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Mail\Message;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Log;
|
|
|
|
use Mail;
|
|
|
|
use Swift_TransportException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class MailError
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Jobs
|
|
|
|
*/
|
|
|
|
class MailError extends Job implements ShouldQueue
|
|
|
|
{
|
|
|
|
use InteractsWithQueue, SerializesModels;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $destination;
|
|
|
|
/** @var array */
|
|
|
|
protected $exception;
|
|
|
|
/** @var string */
|
2016-03-14 14:50:19 -05:00
|
|
|
protected $ipAddress;
|
2016-04-28 03:59:36 -05:00
|
|
|
/** @var array */
|
|
|
|
protected $userData;
|
2016-02-24 13:13:55 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MailError constructor.
|
|
|
|
*
|
2016-04-28 03:59:36 -05:00
|
|
|
* @param array $userData
|
2016-02-24 13:13:55 -06:00
|
|
|
* @param string $destination
|
2016-03-14 14:50:19 -05:00
|
|
|
* @param string $ipAddress
|
2016-03-03 01:29:56 -06:00
|
|
|
* @param array $exceptionData
|
|
|
|
*
|
2016-02-24 13:13:55 -06:00
|
|
|
*/
|
2016-04-28 03:59:36 -05:00
|
|
|
public function __construct(array $userData, string $destination, string $ipAddress, array $exceptionData)
|
2016-02-24 13:13:55 -06:00
|
|
|
{
|
2016-04-28 03:59:36 -05:00
|
|
|
$this->userData = $userData;
|
2016-02-24 13:13:55 -06:00
|
|
|
$this->destination = $destination;
|
2016-03-14 14:50:19 -05:00
|
|
|
$this->ipAddress = $ipAddress;
|
2016-02-24 13:13:55 -06:00
|
|
|
$this->exception = $exceptionData;
|
|
|
|
|
2016-04-28 03:59:36 -05:00
|
|
|
$debug = $exceptionData;
|
|
|
|
unset($debug['stackTrace']);
|
|
|
|
Log::error('Exception is: ' . json_encode($debug));
|
2016-02-24 13:13:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
if ($this->attempts() < 3) {
|
|
|
|
// mail?
|
|
|
|
try {
|
2016-02-24 13:44:39 -06:00
|
|
|
$email = env('SITE_OWNER');
|
|
|
|
$args = $this->exception;
|
2016-04-28 03:59:36 -05:00
|
|
|
$args['loggedIn'] = $this->userData['id'] > 0;
|
|
|
|
$args['user'] = $this->userData;
|
2016-03-14 14:50:19 -05:00
|
|
|
$args['ip'] = $this->ipAddress;
|
2016-02-24 13:13:55 -06:00
|
|
|
|
|
|
|
Mail::send(
|
|
|
|
['emails.error-html', 'emails.error'], $args,
|
|
|
|
function (Message $message) use ($email) {
|
|
|
|
if ($email != 'mail@example.com') {
|
|
|
|
$message->to($email, $email)->subject('Caught an error in Firely III.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (Swift_TransportException $e) {
|
|
|
|
// could also not mail! :o
|
|
|
|
Log::error('Swift Transport Exception' . $e->getMessage());
|
|
|
|
} catch (ErrorException $e) {
|
|
|
|
Log::error('ErrorException ' . $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|