From a8f186c92114ad03aa00852c1b07a996f90fb5c4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 16 Nov 2020 13:41:43 +1100 Subject: [PATCH 1/5] Remove redundant entity notification --- app/Jobs/RecurringInvoice/SendRecurring.php | 7 +++---- app/Listeners/Invoice/InvoiceEmailedNotification.php | 5 +---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 56d155479b4c..3df78415c903 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -56,8 +56,6 @@ class SendRecurring implements ShouldQueue */ public function handle() : void { - info(" in the handle "); - // Generate Standard Invoice $invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client); @@ -99,8 +97,9 @@ class SendRecurring implements ShouldQueue $this->recurring_invoice->save(); - if ($invoice->invitations->count() > 0) - event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); + //this is duplicated!! + // if ($invoice->invitations->count() > 0) + // event(new InvoiceWasEmailed($invoice->invitations->first(), $invoice->company, Ninja::eventVars())); } diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index dfd71d8b9cc7..95dec6fe1c2d 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -60,12 +60,9 @@ class InvoiceEmailedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) { unset($methods[$key]); - //Fire mail notification here!!! - //This allows us better control of how we - //handle the mailer - EntitySentMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company); $first_notification_sent = false; + } $notification->method = $methods; From 77929a6bc3582af6575f557cac404815d211cfa1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 16 Nov 2020 15:40:52 +1100 Subject: [PATCH 2/5] Minor fixes for bulk import --- app/Console/Commands/ImportMigrations.php | 5 +++-- app/Jobs/Util/StartMigration.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php index af490e426bb8..0a04e1817b2f 100644 --- a/app/Console/Commands/ImportMigrations.php +++ b/app/Console/Commands/ImportMigrations.php @@ -88,14 +88,15 @@ class ImportMigrations extends Command 'confirmation_code' => $this->createDbHash(config('database.default')), ]); +CompanyToken::unguard(); $company_token = CompanyToken::create([ 'user_id' => $user->id, 'company_id' => $company->id, 'account_id' => $account->id, - 'name' => 'test token', + 'name' => 'First token', 'token' => Str::random(64), ]); - + $user->companies()->attach($company->id, [ 'account_id' => $account->id, 'is_owner' => 1, diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index 9a911ab024ef..22e215c763d0 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -107,7 +107,7 @@ class StartMigration implements ShouldQueue $data = json_decode(file_get_contents($file), 1); - Import::dispatchNow($data['data'], $this->company, $this->user); + Import::dispatchNow($data, $this->company, $this->user); } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); From 33535273334493d29398a84fcc87b84642744a09 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 16 Nov 2020 21:29:17 +1100 Subject: [PATCH 3/5] Minor fixes for migrations --- app/Console/Commands/ImportMigrations.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php index 0a04e1817b2f..9e1e4a00b2eb 100644 --- a/app/Console/Commands/ImportMigrations.php +++ b/app/Console/Commands/ImportMigrations.php @@ -88,7 +88,8 @@ class ImportMigrations extends Command 'confirmation_code' => $this->createDbHash(config('database.default')), ]); -CompanyToken::unguard(); + CompanyToken::unguard(); + $company_token = CompanyToken::create([ 'user_id' => $user->id, 'company_id' => $company->id, From 5a6d543e345eb9d046f841d01657554ac0cdfe04 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 17 Nov 2020 08:56:52 +1100 Subject: [PATCH 4/5] Minor fixes for imports --- app/Jobs/Util/StartMigration.php | 4 ++-- app/PaymentDrivers/BaseDriver.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index 22e215c763d0..728b9aa182e0 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -51,11 +51,11 @@ class StartMigration implements ShouldQueue * @param User $user * @param Company $company */ - public $tries = 1; + public $tries = 0; public $timeout = 86400; - public $backoff = 86430; + //public $backoff = 86430; public function __construct($filepath, User $user, Company $company) { diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 1ae24f09aeeb..be19bb35c73a 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -1,5 +1,4 @@ Date: Tue, 17 Nov 2020 10:04:10 +1100 Subject: [PATCH 5/5] minor fixes for imports --- app/Console/Commands/SendRemindersCron.php | 4 ++-- app/Jobs/Util/WebhookHandler.php | 8 +++++++- .../Migration/InvoiceMigrationRepository.php | 9 +++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/SendRemindersCron.php b/app/Console/Commands/SendRemindersCron.php index 3f64189f25f3..9ad36e5434c6 100644 --- a/app/Console/Commands/SendRemindersCron.php +++ b/app/Console/Commands/SendRemindersCron.php @@ -66,7 +66,7 @@ class SendRemindersCron extends Command ->cursor(); $invoices->each(function ($invoice){ - WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice); + WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company); }); } @@ -79,7 +79,7 @@ class SendRemindersCron extends Command ->cursor(); $quotes->each(function ($quote){ - WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote); + WebHookHandler::dispatch(Webhook::EVENT_EXPIRED_QUOTE, $quote, $quote->company); }); } } diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index e607c930bc06..7bb753dcb05f 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -21,6 +21,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use League\Fractal\Manager; use League\Fractal\Resource\Item; +use App\Libraries\MultiDB; class WebhookHandler implements ShouldQueue { @@ -30,16 +31,18 @@ class WebhookHandler implements ShouldQueue private $event_id; + private $company; /** * Create a new job instance. * * @param $event_id * @param $entity */ - public function __construct($event_id, $entity) + public function __construct($event_id, $entity, $company) { $this->event_id = $event_id; $this->entity = $entity; + $this->company = $company; } /** @@ -49,6 +52,9 @@ class WebhookHandler implements ShouldQueue */ public function handle() :bool {//todo set multidb here + + MultiDB::setDb($this->company->db); + if (! $this->entity->company || $this->entity->company->is_disabled) { return true; } diff --git a/app/Repositories/Migration/InvoiceMigrationRepository.php b/app/Repositories/Migration/InvoiceMigrationRepository.php index 1b28ec5c52f5..d0a0b53b4ea2 100644 --- a/app/Repositories/Migration/InvoiceMigrationRepository.php +++ b/app/Repositories/Migration/InvoiceMigrationRepository.php @@ -138,10 +138,6 @@ class InvoiceMigrationRepository extends BaseRepository $model = $model->service()->applyNumber()->save(); - if ($model->company->update_products !== false) { - UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company); - } - if ($class->name == Invoice::class || $class->name == RecurringInvoice::class) { if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) { @@ -152,6 +148,11 @@ class InvoiceMigrationRepository extends BaseRepository if (! $model->design_id) { $model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id')); } + + + if ($model->company->update_products !== false) { + UpdateOrCreateProduct::dispatchNow($model->line_items, $model, $model->company); + } } if ($class->name == Credit::class) {