Implement a mail router which can centralise mail jobs

This commit is contained in:
= 2020-08-08 09:28:36 +10:00
parent 1a04e6429b
commit e6afbb3bcf
3 changed files with 166 additions and 80 deletions

View File

@ -69,4 +69,15 @@ class BaseMailerJob implements ShouldQueue
} }
public function logMailError($errors, $recipient_object)
{
SystemLogger::dispatch(
$errors,
SystemLog::CATEGORY_MAIL,
SystemLog::EVENT_MAIL_SEND,
SystemLog::TYPE_FAILURE,
$recipient_object
);
}
} }

View File

@ -0,0 +1,75 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Mail;
use App\Jobs\Mail\BaseMailerJob;
use App\Jobs\Util\SystemLogger;
use App\Libraries\Google\Google;
use App\Libraries\MultiDB;
use App\Mail\Admin\EntityNotificationMailer;
use App\Mail\Admin\EntitySentObject;
use App\Models\Company;
use App\Models\SystemLog;
use App\Models\User;
use App\Providers\MailServiceProvider;
use Dacastro4\LaravelGmail\Services\Message\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Mail;
/*Multi Mailer Router implemented*/
class MailRouter extends BaseMailerJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $mailable;
public $company;
public $to_user; //User or ClientContact
public $sending_method;
public function __construct(Mailable $mailable, Company $company, $to_user, string $sending_method)
{
$this->mailable = $mailable;
$this->company = $company;
$this->to_user = $to_user;
$this->sending_method = $sending_method;
}
public function handle()
{
MultiDB::setDb($this->company->db);
//if we need to set an email driver do it now
$this->setMailDriver($sending_method);
//send email
Mail::to($this->to_user->email)
->send($this->mailable);
//catch errors
if (count(Mail::failures()) > 0) {
$this->logMailError(Mail::failures(), $this->to_user);
}
}
}

160
composer.lock generated
View File

@ -107,16 +107,16 @@
}, },
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.147.8", "version": "3.147.14",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "b121ee1d69d3a1200ebc22d937cd40043b96a940" "reference": "2ac5757aee4333c382c222880a51bd56930dafc4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/b121ee1d69d3a1200ebc22d937cd40043b96a940", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/2ac5757aee4333c382c222880a51bd56930dafc4",
"reference": "b121ee1d69d3a1200ebc22d937cd40043b96a940", "reference": "2ac5757aee4333c382c222880a51bd56930dafc4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -188,7 +188,7 @@
"s3", "s3",
"sdk" "sdk"
], ],
"time": "2020-07-29T18:16:33+00:00" "time": "2020-08-06T18:18:37+00:00"
}, },
{ {
"name": "checkout/checkout-sdk-php", "name": "checkout/checkout-sdk-php",
@ -420,16 +420,16 @@
}, },
{ {
"name": "composer/composer", "name": "composer/composer",
"version": "1.10.9", "version": "1.10.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/composer/composer.git", "url": "https://github.com/composer/composer.git",
"reference": "83c3250093d5491600a822e176b107a945baf95a" "reference": "32966a3b1d48bc01472a8321fd6472b44fad033a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/composer/composer/zipball/83c3250093d5491600a822e176b107a945baf95a", "url": "https://api.github.com/repos/composer/composer/zipball/32966a3b1d48bc01472a8321fd6472b44fad033a",
"reference": "83c3250093d5491600a822e176b107a945baf95a", "reference": "32966a3b1d48bc01472a8321fd6472b44fad033a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -510,7 +510,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-07-16T10:57:00+00:00" "time": "2020-08-03T09:35:19+00:00"
}, },
{ {
"name": "composer/package-versions-deprecated", "name": "composer/package-versions-deprecated",
@ -1103,38 +1103,24 @@
"sqlserver", "sqlserver",
"sqlsrv" "sqlsrv"
], ],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
"type": "tidelift"
}
],
"time": "2020-04-20T17:19:26+00:00" "time": "2020-04-20T17:19:26+00:00"
}, },
{ {
"name": "doctrine/event-manager", "name": "doctrine/event-manager",
"version": "1.1.0", "version": "1.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/event-manager.git", "url": "https://github.com/doctrine/event-manager.git",
"reference": "629572819973f13486371cb611386eb17851e85c" "reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/doctrine/event-manager/zipball/629572819973f13486371cb611386eb17851e85c", "url": "https://api.github.com/repos/doctrine/event-manager/zipball/41370af6a30faa9dc0368c4a6814d596e81aba7f",
"reference": "629572819973f13486371cb611386eb17851e85c", "reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.1" "php": "^7.1 || ^8.0"
}, },
"conflict": { "conflict": {
"doctrine/common": "<2.9@dev" "doctrine/common": "<2.9@dev"
@ -1193,7 +1179,21 @@
"event system", "event system",
"events" "events"
], ],
"time": "2019-11-10T09:48:07+00:00" "funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager",
"type": "tidelift"
}
],
"time": "2020-05-29T18:28:51+00:00"
}, },
{ {
"name": "doctrine/inflector", "name": "doctrine/inflector",
@ -1747,16 +1747,16 @@
}, },
{ {
"name": "google/apiclient-services", "name": "google/apiclient-services",
"version": "v0.141", "version": "v0.142",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/googleapis/google-api-php-client-services.git", "url": "https://github.com/googleapis/google-api-php-client-services.git",
"reference": "4ba7279b0a56366e4f19b9d1a1b5456f99353b6f" "reference": "3baf0a665cd08975314214b075f28765c97282ae"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/4ba7279b0a56366e4f19b9d1a1b5456f99353b6f", "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/3baf0a665cd08975314214b075f28765c97282ae",
"reference": "4ba7279b0a56366e4f19b9d1a1b5456f99353b6f", "reference": "3baf0a665cd08975314214b075f28765c97282ae",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1780,7 +1780,7 @@
"keywords": [ "keywords": [
"google" "google"
], ],
"time": "2020-07-27T00:25:27+00:00" "time": "2020-07-28T00:24:58+00:00"
}, },
{ {
"name": "google/auth", "name": "google/auth",
@ -2464,16 +2464,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v6.18.31", "version": "v6.18.35",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "a731824421f9ebc586728ea9c7cff231a249aaa9" "reference": "baec6c2d7f433594cb858c35c2a2946df7ecac13"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/a731824421f9ebc586728ea9c7cff231a249aaa9", "url": "https://api.github.com/repos/laravel/framework/zipball/baec6c2d7f433594cb858c35c2a2946df7ecac13",
"reference": "a731824421f9ebc586728ea9c7cff231a249aaa9", "reference": "baec6c2d7f433594cb858c35c2a2946df7ecac13",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2608,7 +2608,7 @@
"framework", "framework",
"laravel" "laravel"
], ],
"time": "2020-07-27T18:23:18+00:00" "time": "2020-08-07T15:06:09+00:00"
}, },
{ {
"name": "laravel/slack-notification-channel", "name": "laravel/slack-notification-channel",
@ -3613,25 +3613,25 @@
}, },
{ {
"name": "mtdowling/jmespath.php", "name": "mtdowling/jmespath.php",
"version": "2.5.0", "version": "2.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/jmespath/jmespath.php.git", "url": "https://github.com/jmespath/jmespath.php.git",
"reference": "52168cb9472de06979613d365c7f1ab8798be895" "reference": "42dae2cbd13154083ca6d70099692fef8ca84bfb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/52168cb9472de06979613d365c7f1ab8798be895", "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/42dae2cbd13154083ca6d70099692fef8ca84bfb",
"reference": "52168cb9472de06979613d365c7f1ab8798be895", "reference": "42dae2cbd13154083ca6d70099692fef8ca84bfb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.4.0", "php": "^5.4 || ^7.0 || ^8.0",
"symfony/polyfill-mbstring": "^1.4" "symfony/polyfill-mbstring": "^1.17"
}, },
"require-dev": { "require-dev": {
"composer/xdebug-handler": "^1.2", "composer/xdebug-handler": "^1.4",
"phpunit/phpunit": "^4.8.36|^7.5.15" "phpunit/phpunit": "^4.8.36 || ^7.5.15"
}, },
"bin": [ "bin": [
"bin/jp.php" "bin/jp.php"
@ -3639,7 +3639,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.5-dev" "dev-master": "2.6-dev"
} }
}, },
"autoload": { "autoload": {
@ -3666,7 +3666,7 @@
"json", "json",
"jsonpath" "jsonpath"
], ],
"time": "2019-12-30T18:03:34+00:00" "time": "2020-07-31T21:01:56+00:00"
}, },
{ {
"name": "myclabs/php-enum", "name": "myclabs/php-enum",
@ -3716,16 +3716,16 @@
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "2.37.0", "version": "2.38.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/briannesbitt/Carbon.git", "url": "https://github.com/briannesbitt/Carbon.git",
"reference": "1f61206de973d67f36ce50f041c792ddac663c3e" "reference": "d8f6a6a91d1eb9304527b040500f61923e97674b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/1f61206de973d67f36ce50f041c792ddac663c3e", "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/d8f6a6a91d1eb9304527b040500f61923e97674b",
"reference": "1f61206de973d67f36ce50f041c792ddac663c3e", "reference": "d8f6a6a91d1eb9304527b040500f61923e97674b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3740,7 +3740,7 @@
"kylekatarnls/multi-tester": "^2.0", "kylekatarnls/multi-tester": "^2.0",
"phpmd/phpmd": "^2.8", "phpmd/phpmd": "^2.8",
"phpstan/extension-installer": "^1.0", "phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.30", "phpstan/phpstan": "^0.12.35",
"phpunit/phpunit": "^7.5 || ^8.0", "phpunit/phpunit": "^7.5 || ^8.0",
"squizlabs/php_codesniffer": "^3.4" "squizlabs/php_codesniffer": "^3.4"
}, },
@ -3801,7 +3801,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-07-28T06:04:54+00:00" "time": "2020-08-04T19:12:46+00:00"
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
@ -6111,16 +6111,16 @@
}, },
{ {
"name": "stripe/stripe-php", "name": "stripe/stripe-php",
"version": "v7.45.0", "version": "v7.46.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/stripe/stripe-php.git", "url": "https://github.com/stripe/stripe-php.git",
"reference": "21e5001f5e0d787e4755c8bfc00e578dce9ae058" "reference": "fd57205d3e3a1dccab80538654128d5c46a1f5ac"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/stripe/stripe-php/zipball/21e5001f5e0d787e4755c8bfc00e578dce9ae058", "url": "https://api.github.com/repos/stripe/stripe-php/zipball/fd57205d3e3a1dccab80538654128d5c46a1f5ac",
"reference": "21e5001f5e0d787e4755c8bfc00e578dce9ae058", "reference": "fd57205d3e3a1dccab80538654128d5c46a1f5ac",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -6164,7 +6164,7 @@
"payment processing", "payment processing",
"stripe" "stripe"
], ],
"time": "2020-07-29T04:29:52+00:00" "time": "2020-08-07T22:11:58+00:00"
}, },
{ {
"name": "swiftmailer/swiftmailer", "name": "swiftmailer/swiftmailer",
@ -7202,7 +7202,7 @@
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git", "url": "https://github.com/symfony/polyfill-ctype.git",
@ -7278,7 +7278,7 @@
}, },
{ {
"name": "symfony/polyfill-iconv", "name": "symfony/polyfill-iconv",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-iconv.git", "url": "https://github.com/symfony/polyfill-iconv.git",
@ -7355,16 +7355,16 @@
}, },
{ {
"name": "symfony/polyfill-intl-idn", "name": "symfony/polyfill-intl-idn",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-idn.git", "url": "https://github.com/symfony/polyfill-intl-idn.git",
"reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe" "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/bc6549d068d0160e0f10f7a5a23c7d1406b95ebe", "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/5dcab1bc7146cf8c1beaa4502a3d9be344334251",
"reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe", "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -7436,11 +7436,11 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-07-14T12:35:20+00:00" "time": "2020-08-04T06:02:08+00:00"
}, },
{ {
"name": "symfony/polyfill-intl-normalizer", "name": "symfony/polyfill-intl-normalizer",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git",
@ -7521,7 +7521,7 @@
}, },
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git", "url": "https://github.com/symfony/polyfill-mbstring.git",
@ -7598,7 +7598,7 @@
}, },
{ {
"name": "symfony/polyfill-php70", "name": "symfony/polyfill-php70",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php70.git", "url": "https://github.com/symfony/polyfill-php70.git",
@ -7675,7 +7675,7 @@
}, },
{ {
"name": "symfony/polyfill-php72", "name": "symfony/polyfill-php72",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php72.git", "url": "https://github.com/symfony/polyfill-php72.git",
@ -7748,7 +7748,7 @@
}, },
{ {
"name": "symfony/polyfill-php73", "name": "symfony/polyfill-php73",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php73.git", "url": "https://github.com/symfony/polyfill-php73.git",
@ -7824,7 +7824,7 @@
}, },
{ {
"name": "symfony/polyfill-php80", "name": "symfony/polyfill-php80",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php80.git", "url": "https://github.com/symfony/polyfill-php80.git",
@ -7904,7 +7904,7 @@
}, },
{ {
"name": "symfony/polyfill-uuid", "name": "symfony/polyfill-uuid",
"version": "v1.18.0", "version": "v1.18.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-uuid.git", "url": "https://github.com/symfony/polyfill-uuid.git",
@ -10937,16 +10937,16 @@
}, },
{ {
"name": "swagger-api/swagger-ui", "name": "swagger-api/swagger-ui",
"version": "v3.30.2", "version": "v3.31.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/swagger-api/swagger-ui.git", "url": "https://github.com/swagger-api/swagger-ui.git",
"reference": "d8521c1bc067cfa57108ecf8f1a513db039ff1da" "reference": "752488edf7ff5b3f98fde2d069e4cd5eff150cd0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/swagger-api/swagger-ui/zipball/d8521c1bc067cfa57108ecf8f1a513db039ff1da", "url": "https://api.github.com/repos/swagger-api/swagger-ui/zipball/752488edf7ff5b3f98fde2d069e4cd5eff150cd0",
"reference": "d8521c1bc067cfa57108ecf8f1a513db039ff1da", "reference": "752488edf7ff5b3f98fde2d069e4cd5eff150cd0",
"shasum": "" "shasum": ""
}, },
"type": "library", "type": "library",
@ -10990,7 +10990,7 @@
"swagger", "swagger",
"ui" "ui"
], ],
"time": "2020-07-22T20:37:48+00:00" "time": "2020-07-30T18:09:18+00:00"
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",