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,