From 3727bafaa110451fdf9ae80fc5fe91a7ddad541d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Aug 2021 11:40:58 +1000 Subject: [PATCH] More logging for migrations --- app/Jobs/Util/StartMigration.php | 9 +++++++++ app/Mail/MigrationFailed.php | 3 +++ app/Models/Account.php | 7 +++++++ app/Transformers/AccountTransformer.php | 2 ++ resources/lang/en/texts.php | 1 + resources/views/email/migration/failed.blade.php | 2 +- .../portal/ninja2020/recurring_invoices/show.blade.php | 5 ++--- 7 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index d3c13c5995c7..b4e54a07dc1c 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -133,6 +133,15 @@ class StartMigration implements ShouldQueue Mail::to($this->user->email, $this->user->name())->send(new MigrationFailed($e, $this->company, $e->getMessage())); + if(Ninja::isHosted()){ + + $migration_failed = new MigrationFailed($e, $this->company, $e->getMessage()); + $migration_failed->is_system = true; + + Mail::to('contact@invoiceninja.com', 'Failed Migration')->send($migration_failed); + + } + if (app()->environment() !== 'production') { info($e->getMessage()); } diff --git a/app/Mail/MigrationFailed.php b/app/Mail/MigrationFailed.php index 9c28bd2fbc27..55d6f0838916 100644 --- a/app/Mail/MigrationFailed.php +++ b/app/Mail/MigrationFailed.php @@ -13,6 +13,8 @@ class MigrationFailed extends Mailable public $company; + public $is_system = false; + /** * Create a new message instance. * @@ -38,6 +40,7 @@ class MigrationFailed extends Mailable ->view('email.migration.failed', [ 'logo' => $this->company->present()->logo(), 'settings' => $this->company->settings, + 'is_system' => $this->is_system, ]); } } diff --git a/app/Models/Account.php b/app/Models/Account.php index ae563d050eed..8b0c07dbfd0b 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -363,6 +363,13 @@ class Account extends BaseModel return min($limit, 5000); } + public function emailsSent() + { + if(is_null(Cache::get($this->key))) + return 0; + + return Cache::get($this->key); + } public function emailQuotaExceeded() :bool { diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 57a68d9b1324..c26b35d73e0f 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -80,6 +80,8 @@ class AccountTransformer extends EntityTransformer 'is_scheduler_running' => (bool) $account->is_scheduler_running, 'default_company_id' => (string) $this->encodePrimaryKey($account->default_company_id), 'disable_auto_update' => (bool) config('ninja.disable_auto_update'), + 'emails_sent' => (int) $account->emailsSent(), + 'email_quota' => (int) $account->getDailyEmailLimit(), ]; } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index c9cd5d7ffc7c..091d814aff48 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4291,6 +4291,7 @@ $LANG = array( 'stripe_connect_migration_desc' => 'Invoice Ninja v5 uses Stripe Connect to link your Stripe account to Invoice Ninja. This provides an additional layer of security for your account. Now that you data has migrated, you will need to Authorize Stripe to accept payments in v5.

To do this, navigate to Settings > Online Payments > Configure Gateways. Click on Stripe Connect and then under Settings click Setup Gateway. This will take you to Stripe to authorize Invoice Ninja and on your return your account will be successfully linked!', 'email_quota_exceeded_subject' => 'Account email quota exceeded.', 'email_quota_exceeded_body' => 'In a 24 hour period you have sent :quota emails.
We have paused your outbound emails.

Your email quota will reset at 23:00 UTC.', + 'auto_bill_option' => 'Opt in or out of having this invoice automatically charged.' ); return $LANG; diff --git a/resources/views/email/migration/failed.blade.php b/resources/views/email/migration/failed.blade.php index 487b9d0661a5..e13eca301a56 100644 --- a/resources/views/email/migration/failed.blade.php +++ b/resources/views/email/migration/failed.blade.php @@ -4,7 +4,7 @@

{{ ctrans('texts.migration_failed') }} {{ $company->present()->name() }}

-            @if(\App\Utils\Ninja::isSelfHost())
+            @if(\App\Utils\Ninja::isSelfHost() || $is_system)
                 {!! $exception->getMessage() !!}
                 {!! $content !!}
             @else
diff --git a/resources/views/portal/ninja2020/recurring_invoices/show.blade.php b/resources/views/portal/ninja2020/recurring_invoices/show.blade.php
index 37c12a237047..a2debf49c5b8 100644
--- a/resources/views/portal/ninja2020/recurring_invoices/show.blade.php
+++ b/resources/views/portal/ninja2020/recurring_invoices/show.blade.php
@@ -65,9 +65,8 @@
             
-

Auto Bill

-

Change your update bill - preferences.

+

{{ ctrans('texts.auto_bill') }}

+

{{ ctrans('texts.auto_bill_option')}}