Files
firefly-iii/app/Jobs/MailError.php

97 lines
3.0 KiB
PHP
Raw Normal View History

<?php
/**
* MailError.php
2020-02-07 11:16:38 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Jobs;
2018-03-25 09:01:43 +02:00
use Exception;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Message;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;
use Mail;
/**
2017-11-15 12:25:49 +01:00
* Class MailError.
*
2019-07-31 16:53:09 +02:00
* @codeCoverageIgnore
*/
class MailError extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
2018-07-22 15:20:45 +02:00
/** @var string Destination */
protected $destination;
2018-07-22 15:20:45 +02:00
/** @var array Exception information */
protected $exception;
2018-07-22 15:20:45 +02:00
/** @var string IP address */
protected $ipAddress;
2018-07-22 15:20:45 +02:00
/** @var array User information */
2016-04-28 10:59:36 +02:00
protected $userData;
/**
* MailError constructor.
*
2016-04-28 10:59:36 +02:00
* @param array $userData
* @param string $destination
* @param string $ipAddress
2016-03-03 08:29:56 +01:00
* @param array $exceptionData
*/
2016-04-28 10:59:36 +02:00
public function __construct(array $userData, string $destination, string $ipAddress, array $exceptionData)
{
2016-04-28 10:59:36 +02:00
$this->userData = $userData;
$this->destination = $destination;
$this->ipAddress = $ipAddress;
$this->exception = $exceptionData;
2017-09-14 16:13:25 +02:00
$debug = $exceptionData;
2016-04-28 10:59:36 +02:00
unset($debug['stackTrace']);
Log::error('Exception is: ' . json_encode($debug));
}
/**
* Execute the job.
*/
public function handle()
{
2020-10-23 12:30:12 +02:00
$email = config('firefly.site_owner');
$args = $this->exception;
$args['loggedIn'] = $this->userData['id'] > 0;
$args['user'] = $this->userData;
$args['ipAddress'] = $this->ipAddress;
if ($this->attempts() < 3) {
try {
Mail::send(
2017-11-15 10:52:29 +01:00
['emails.error-html', 'emails.error-text'],
$args,
function (Message $message) use ($email) {
2017-11-15 12:25:49 +01:00
if ('mail@example.com' !== $email) {
2020-10-23 12:30:12 +02:00
$message->to($email, $email)->subject((string)trans('email.error_subject'));
}
}
);
2018-03-25 09:01:43 +02:00
} catch (Exception $e) {
Log::error('Exception when mailing: ' . $e->getMessage());
}
}
}
}