From bd6c66696610b29a9d8e384511bd565d811c6357 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 9 Feb 2023 14:06:41 +1100 Subject: [PATCH] Throw human readable exceptions in migrations --- .../ClientHostedMigrationException.php | 19 ++++++++++++++++ app/Exceptions/FilePermissionsFailure.php | 10 +++++++++ .../GenericPaymentDriverFailure.php | 10 +++++++++ app/Exceptions/ImportCompanyFailed.php | 10 +++++++++ app/Exceptions/InternalPDFFailure.php | 10 +++++++++ app/Exceptions/MigrationValidatorFailed.php | 10 +++++++++ app/Exceptions/NonExistingBackupFile.php | 10 +++++++++ app/Exceptions/NonExistingMigrationFile.php | 10 +++++++++ app/Exceptions/PaymentFailed.php | 10 +++++++++ app/Exceptions/PaymentRefundFailed.php | 10 +++++++++ app/Exceptions/PhantomPDFFailure.php | 10 +++++++++ .../ProcessingMigrationArchiveFailed.php | 10 +++++++++ app/Exceptions/ResourceDependencyMissing.php | 10 +++++++++ .../ResourceNotAvailableForMigration.php | 10 +++++++++ app/Exceptions/StripeConnectFailure.php | 10 +++++++++ app/Exceptions/SystemError.php | 10 +++++++++ app/Exceptions/YodleeApiException.php | 10 +++++++++ app/Jobs/Util/Import.php | 22 +++++++++---------- app/Mail/MigrationFailed.php | 18 ++++++++++++++- 19 files changed, 206 insertions(+), 13 deletions(-) create mode 100644 app/Exceptions/ClientHostedMigrationException.php diff --git a/app/Exceptions/ClientHostedMigrationException.php b/app/Exceptions/ClientHostedMigrationException.php new file mode 100644 index 000000000000..0f14ee0c7103 --- /dev/null +++ b/app/Exceptions/ClientHostedMigrationException.php @@ -0,0 +1,19 @@ +whereIn('email', array_column($data, 'email'))->count(); - $db2_count = User::withTrashed()->whereIn('email', array_column($data, 'email'))->count(); - - } - + $db1_count = User::on('db-ninja-01')->withTrashed()->whereIn('email', array_column($data, 'email'))->count(); + $db2_count = User::on('db-ninja-02')->withTrashed()->whereIn('email', array_column($data, 'email'))->count(); MultiDB::setDb($current_db); + if($db2_count == 0 && $db1_count == 0) + return true; + + if($db1_count >= 1 && $db2_count >= 1) + return false; + return true; } @@ -613,8 +611,8 @@ class Import implements ShouldQueue */ private function processUsers(array $data): void { - if(!$this->testUserDbLocationSanity()) - throw new ClientHostedMigrationException('You have multiple accounts registered in the system, please contact us to resolve.', 400); + if(!$this->testUserDbLocationSanity($data)) + throw new ClientHostedMigrationException('You have users that belong to different accounts registered in the system, please contact us to resolve.', 400); User::unguard(); diff --git a/app/Mail/MigrationFailed.php b/app/Mail/MigrationFailed.php index af9fc209b125..44be3af46b41 100644 --- a/app/Mail/MigrationFailed.php +++ b/app/Mail/MigrationFailed.php @@ -1,7 +1,18 @@ company->getLocale()); + + $special_message = ''; + + if($this->exception instanceof ClientHostedMigrationException) + $special_message = $this->content; return $this ->from(config('mail.from.address'), config('mail.from.name')) ->text('email.migration.failed_text') ->view('email.migration.failed', [ - 'special_message' => '', + 'special_message' => $special_message, 'logo' => $this->company->present()->logo(), 'settings' => $this->company->settings, 'is_system' => $this->is_system,