From 48c36d000468296928066a236e2fac36b4339f57 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 31 Jul 2022 19:11:32 +1000 Subject: [PATCH] Fixes for mailers --- app/Helpers/Mail/GmailTransport.php | 4 +- app/Helpers/Mail/Office365MailTransport.php | 4 +- app/Http/Controllers/ImportController.php | 3 +- app/Http/Middleware/QueryLogging.php | 10 +-- app/Jobs/Import/CSVIngest.php | 14 +--- app/Jobs/Mail/NinjaMailerJob.php | 4 +- app/Mail/TemplateEmail.php | 2 + app/Mail/VendorTemplateEmail.php | 2 + app/Services/Credit/SendEmail.php | 5 +- app/Services/Invoice/InvoiceService.php | 6 +- config/logging.php | 2 +- config/services.php | 85 ++++++++++----------- routes/api.php | 8 +- routes/client.php | 2 +- 14 files changed, 73 insertions(+), 78 deletions(-) diff --git a/app/Helpers/Mail/GmailTransport.php b/app/Helpers/Mail/GmailTransport.php index b88c124aa88b..4117e710fdbe 100644 --- a/app/Helpers/Mail/GmailTransport.php +++ b/app/Helpers/Mail/GmailTransport.php @@ -34,8 +34,8 @@ class GmailTransport extends AbstractTransport nlog("in Do Send"); $message = MessageConverter::toEmail($message->getOriginalMessage()); - $token = $message->getHeaders()->get('GmailToken')->getValue(); - $message->getHeaders()->remove('GmailToken'); + $token = $message->getHeaders()->get('gmailtoken')->getValue(); + $message->getHeaders()->remove('gmailtoken'); $client = new Client(); $client->setClientId(config('ninja.auth.google.client_id')); diff --git a/app/Helpers/Mail/Office365MailTransport.php b/app/Helpers/Mail/Office365MailTransport.php index f50f3d8e0043..a4fa9d5e790f 100644 --- a/app/Helpers/Mail/Office365MailTransport.php +++ b/app/Helpers/Mail/Office365MailTransport.php @@ -33,8 +33,8 @@ class Office365MailTransport extends AbstractTransport $symfony_message = MessageConverter::toEmail($message->getOriginalMessage()); $graph = new Graph(); - $token = $symfony_message->getHeaders()->get('GmailToken')->getValue(); - $symfony_message->getHeaders()->remove('GmailToken'); + $token = $symfony_message->getHeaders()->get('gmailtoken')->getValue(); + $symfony_message->getHeaders()->remove('gmailtoken'); $graph->setAccessToken($token); diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index 6447ae292375..f7ec7670d2a9 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -105,7 +105,7 @@ class ImportController extends Controller public function import(ImportRequest $request) { $data = $request->all(); -nlog($data); + if (empty($data['hash'])) { // Create a reference $data['hash'] = $hash = Str::random(32); @@ -113,7 +113,6 @@ nlog($data); /** @var UploadedFile $file */ foreach ($request->files->get('files') as $entityType => $file) { $contents = file_get_contents($file->getPathname()); - // Store the csv in cache with an expiry of 10 minutes Cache::put($hash.'-'.$entityType, base64_encode($contents), 600); } diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index ee85701612a3..0bf364225054 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -35,9 +35,9 @@ class QueryLogging { // Enable query logging for development - if (! Ninja::isHosted() || ! config('beacon.enabled')) { - return $next($request); - } + // if (! Ninja::isHosted() || ! config('beacon.enabled')) { + // return $next($request); + // } $timeStart = microtime(true); DB::enableQueryLog(); @@ -50,8 +50,8 @@ class QueryLogging $timeEnd = microtime(true); $time = $timeEnd - $timeStart; - nlog("Query count = {$count}"); - nlog($queries); + // nlog("Query count = {$count}"); + // nlog($queries); if ($count > 175) { nlog("Query count = {$count}"); diff --git a/app/Jobs/Import/CSVIngest.php b/app/Jobs/Import/CSVIngest.php index 05fea37a0e72..5313050be057 100644 --- a/app/Jobs/Import/CSVIngest.php +++ b/app/Jobs/Import/CSVIngest.php @@ -72,7 +72,7 @@ class CSVIngest implements ShouldQueue set_time_limit(0); - $engine = $this->bootEngine($this->import_type); + $engine = $this->bootEngine(); foreach (['client', 'product', 'invoice', 'payment', 'vendor', 'expense'] as $entity) { $engine->import($entity); @@ -106,29 +106,23 @@ class CSVIngest implements ShouldQueue } } - private function bootEngine(string $import_type) + private function bootEngine() { - switch ($import_type) { + switch ($this->import_type) { case 'csv': return new Csv($this->request, $this->company); - break; case 'waveaccounting': return new Wave($this->request, $this->company); - break; case 'invoicely': return new Invoicely($this->request, $this->company); - break; case 'invoice2go': return new Invoice2Go($this->request, $this->company); - break; case 'zoho': return new Zoho($this->request, $this->company); - break; case 'freshbooks': return new Freshbooks($this->request, $this->company); - break; default: - // code... + nlog("could not return provider"); break; } } diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index c99631e84d28..e3e3d47f12bd 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -228,7 +228,7 @@ class NinjaMailerJob implements ShouldQueue $this->nmo ->mailable ->from($user->email, $user->name()) - ->withSwiftMessage(function ($message) use($token) { + ->withSymfonyMessage(function ($message) use($token) { $message->getHeaders()->addTextHeader('GmailToken', $token); }); @@ -298,7 +298,7 @@ class NinjaMailerJob implements ShouldQueue $this->nmo ->mailable ->from($user->email, $user->name()) - ->withSwiftMessage(function ($message) use($token) { + ->withSymfonyMessage(function ($message) use($token) { $message->getHeaders()->addTextHeader('GmailToken', $token); }); diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 5ad58d4f98ec..4b1c1c2acbc3 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -134,6 +134,8 @@ class TemplateEmail extends Mailable elseif($this->invitation->credit) $path = $this->client->credit_filepath($this->invitation).$this->invitation->credit->numberFormatter().'.pdf'; + sleep(1); + if($path && !Storage::disk(config('filesystems.default'))->exists($path)){ sleep(2); diff --git a/app/Mail/VendorTemplateEmail.php b/app/Mail/VendorTemplateEmail.php index 02992de1d5c9..0fab3bcc9e58 100644 --- a/app/Mail/VendorTemplateEmail.php +++ b/app/Mail/VendorTemplateEmail.php @@ -127,6 +127,8 @@ class VendorTemplateEmail extends Mailable if($this->invitation->purchase_order) $path = $this->vendor->purchase_order_filepath($this->invitation).$this->invitation->purchase_order->numberFormatter().'.pdf'; + sleep(1); + if($path && !Storage::disk(config('filesystems.default'))->exists($path)){ sleep(2); diff --git a/app/Services/Credit/SendEmail.php b/app/Services/Credit/SendEmail.php index e7e6c48fe558..f7c2d5835745 100644 --- a/app/Services/Credit/SendEmail.php +++ b/app/Services/Credit/SendEmail.php @@ -45,10 +45,7 @@ class SendEmail $this->credit->invitations->each(function ($invitation) { if (! $invitation->contact->trashed() && $invitation->contact->email) { - - // $email_builder = (new CreditEmail())->build($invitation, $this->reminder_template); - // EmailCredit::dispatchNow($email_builder, $invitation, $invitation->company); - EmailEntity::dispatchSync($invitation, $invitation->company, $this->reminder_template); + EmailEntity::dispatch($invitation, $invitation->company, $this->reminder_template); } }); diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index bf880d2c875f..2af53ce6b08a 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -421,7 +421,8 @@ class InvoiceService try { if ($force) { $this->invoice->invitations->each(function ($invitation) { - CreateEntityPdf::dispatchSync($invitation); + // CreateEntityPdf::dispatchSync($invitation); + (new CreateEntityPdf($invitation))->handle(); }); return $this; @@ -560,7 +561,8 @@ class InvoiceService public function adjustInventory($old_invoice = []) { if ($this->invoice->company->track_inventory) { - AdjustProductInventory::dispatchSync($this->invoice->company, $this->invoice, $old_invoice); + (new AdjustProductInventory($this->invoice->company, $this->invoice, $old_invoice))->handle(); + // AdjustProductInventory::dispatchSync($this->invoice->company, $this->invoice, $old_invoice); } return $this; diff --git a/config/logging.php b/config/logging.php index e7eb0331b9cd..5be233cfdc7f 100644 --- a/config/logging.php +++ b/config/logging.php @@ -124,7 +124,6 @@ return [ 'emergency' => [ 'path' => storage_path('logs/laravel.log'), ], - ], 'gelf' => [ 'driver' => 'custom', @@ -188,5 +187,6 @@ return [ 'extra_prefix' => null, ], +] ]; diff --git a/config/services.php b/config/services.php index b9b4c24c5a7b..aec15f6fc8d7 100644 --- a/config/services.php +++ b/config/services.php @@ -44,57 +44,56 @@ return [ 'ses' => [ 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), + 'region' => env('SES_REGION', 'us-east-1'), + ], + 'sparkpost' => [ + 'secret' => env('SPARKPOST_SECRET'), + ], - 'sparkpost' => [ - 'secret' => env('SPARKPOST_SECRET'), - ], + 'gmail' => [ + 'token' => '', + ], - 'gmail' => [ - 'token' => '', - ], + 'stripe' => [ + 'model' => App\Models\User::class, + 'key' => env('STRIPE_KEY'), + 'secret' => env('STRIPE_SECRET'), + ], - 'stripe' => [ - 'model' => App\Models\User::class, - 'key' => env('STRIPE_KEY'), - 'secret' => env('STRIPE_SECRET'), - ], + 'github' => [ + 'client_id' => env('GITHUB_CLIENT_ID'), + 'client_secret' => env('GITHUB_CLIENT_SECRET'), + 'redirect' => env('GITHUB_OAUTH_REDIRECT'), + ], - 'github' => [ - 'client_id' => env('GITHUB_CLIENT_ID'), - 'client_secret' => env('GITHUB_CLIENT_SECRET'), - 'redirect' => env('GITHUB_OAUTH_REDIRECT'), - ], + 'google' => [ + 'client_id' => env('GOOGLE_CLIENT_ID'), + 'client_secret' => env('GOOGLE_CLIENT_SECRET'), + 'redirect' => env('GOOGLE_OAUTH_REDIRECT'), + ], - 'google' => [ - 'client_id' => env('GOOGLE_CLIENT_ID'), - 'client_secret' => env('GOOGLE_CLIENT_SECRET'), - 'redirect' => env('GOOGLE_OAUTH_REDIRECT'), - ], + 'facebook' => [ + 'client_id' => env('FACEBOOK_CLIENT_ID'), + 'client_secret' => env('FACEBOOK_CLIENT_SECRET'), + 'redirect' => env('FACEBOOK_OAUTH_REDIRECT'), + ], - 'facebook' => [ - 'client_id' => env('FACEBOOK_CLIENT_ID'), - 'client_secret' => env('FACEBOOK_CLIENT_SECRET'), - 'redirect' => env('FACEBOOK_OAUTH_REDIRECT'), - ], + 'linkedin' => [ + 'client_id' => env('LINKEDIN_CLIENT_ID'), + 'client_secret' => env('LINKEDIN_CLIENT_SECRET'), + 'redirect' => env('LINKEDIN_OAUTH_REDIRECT'), + ], - 'linkedin' => [ - 'client_id' => env('LINKEDIN_CLIENT_ID'), - 'client_secret' => env('LINKEDIN_CLIENT_SECRET'), - 'redirect' => env('LINKEDIN_OAUTH_REDIRECT'), - ], + 'twitter' => [ + 'client_id' => env('TWITTER_CLIENT_ID'), + 'client_secret' => env('TWITTER_CLIENT_SECRET'), + 'redirect' => env('TWITTER_OAUTH_REDIRECT'), + ], - 'twitter' => [ - 'client_id' => env('TWITTER_CLIENT_ID'), - 'client_secret' => env('TWITTER_CLIENT_SECRET'), - 'redirect' => env('TWITTER_OAUTH_REDIRECT'), - ], - - 'bitbucket' => [ - 'client_id' => env('BITBUCKET_CLIENT_ID'), - 'client_secret' => env('BITBUCKET_CLIENT_SECRET'), - 'redirect' => env('BITBUCKET_OAUTH_REDIRECT'), - ], - 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), + 'bitbucket' => [ + 'client_id' => env('BITBUCKET_CLIENT_ID'), + 'client_secret' => env('BITBUCKET_CLIENT_SECRET'), + 'redirect' => env('BITBUCKET_OAUTH_REDIRECT'), ], ]; diff --git a/routes/api.php b/routes/api.php index db70b3de13d1..f5150ec20004 100644 --- a/routes/api.php +++ b/routes/api.php @@ -259,7 +259,7 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale Route::resource('task_scheduler', TaskSchedulerController::class)->except('edit')->parameters(['task_scheduler' => 'scheduler']); Route::get('scheduler', [SchedulerController::class, 'index']); - Route::post('support/messages/send', [SendingController::class]); + Route::post('support/messages/send', SendingController::class); Route::post('self-update', [SelfUpdateController::class, 'update'])->middleware('password_protected'); Route::post('self-update/check_version', [SelfUpdateController::class, 'checkVersion']); @@ -287,7 +287,7 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale Route::post('settings/disable_two_factor', [TwoFactorController::class, 'disableTwoFactor']); - Route::post('verify', [TwilioController::class, 'generate'])->name('verify.generate')->middleware('throttle:5,1'); + Route::post('verify', [TwilioController::class, 'generate'])->name('verify.generate')->middleware('throttle:100,1'); Route::post('verify/confirm', [TwilioController::class, 'confirm'])->name('verify.confirm'); Route::resource('vendors', VendorController::class); // name = (vendors. index / create / show / update / destroy / edit @@ -333,11 +333,11 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale }); Route::match(['get', 'post'], 'payment_webhook/{company_key}/{company_gateway_id}', PaymentWebhookController::class) - ->middleware(['throttle:1000,1','guest']) + ->middleware('throttle:1000,1') ->name('payment_webhook'); Route::match(['get', 'post'], 'payment_notification_webhook/{company_key}/{company_gateway_id}/{client}', PaymentNotificationWebhookController::class) - ->middleware(['throttle:1000,1', 'guest']) + ->middleware('throttle:1000,1') ->name('payment_notification_webhook'); Route::post('api/v1/postmark_webhook', [PostMarkController::class, 'webhook'])->middleware('throttle:1000,1'); diff --git a/routes/client.php b/routes/client.php index 0da85644fd30..574d451de408 100644 --- a/routes/client.php +++ b/routes/client.php @@ -90,7 +90,7 @@ Route::group(['middleware' => ['auth:contact', 'locale', 'domain_db','check_clie Route::get('credits/{credit_invitation}', [App\Http\Controllers\ClientPortal\CreditController::class,'show'])->name('credits.show_invitation'); - Route::get('client/switch_company/{contact}', [App\Http\Controllers\ClientPortal\SwitchCompanyController::class])->name('switch_company'); + Route::get('client/switch_company/{contact}', App\Http\Controllers\ClientPortal\SwitchCompanyController::class)->name('switch_company'); Route::post('documents/download_multiple', [App\Http\Controllers\ClientPortal\DocumentController::class, 'downloadMultiple'])->name('documents.download_multiple'); Route::get('documents/{document}/download', [App\Http\Controllers\ClientPortal\DocumentController::class, 'download'])->name('documents.download');