mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 01:54:29 -04:00
Fixes for tests
This commit is contained in:
parent
49841ae78d
commit
c27636fc13
@ -13,6 +13,7 @@ namespace App\Jobs\Util;
|
||||
|
||||
use App\DataMapper\Analytics\MigrationFailure;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Exceptions\ClientHostedMigrationException;
|
||||
use App\Exceptions\MigrationValidatorFailed;
|
||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||
use App\Exceptions\ResourceDependencyMissing;
|
||||
@ -582,18 +583,44 @@ class Import implements ShouldQueue
|
||||
$validator = null;
|
||||
}
|
||||
|
||||
private function testUserDbLocationSanity(array $data): bool
|
||||
{
|
||||
|
||||
if(Ninja::isSelfHost())
|
||||
return true;
|
||||
|
||||
$current_db = config('database.default');
|
||||
|
||||
foreach (MultiDB::$dbs as $db)
|
||||
{
|
||||
|
||||
MultiDB::setDB($db);
|
||||
|
||||
$db1_count = User::withTrashed()->whereIn('email', array_column($data, 'email'))->count();
|
||||
$db2_count = User::withTrashed()->whereIn('email', array_column($data, 'email'))->count();
|
||||
|
||||
}
|
||||
|
||||
|
||||
MultiDB::setDb($current_db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @throws Exception
|
||||
*/
|
||||
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);
|
||||
|
||||
User::unguard();
|
||||
|
||||
$rules = [
|
||||
'*.first_name' => ['string'],
|
||||
'*.last_name' => ['string'],
|
||||
//'*.email' => ['distinct'],
|
||||
'*.email' => ['distinct', 'email', new ValidUserForCompany()],
|
||||
];
|
||||
|
||||
@ -749,7 +776,7 @@ class Import implements ShouldQueue
|
||||
|
||||
Client::reguard();
|
||||
|
||||
Client::with('contacts')->where('company_id', $this->company->id)->cursor()->each(function ($client){
|
||||
Client::withTrashed()->with('contacts')->where('company_id', $this->company->id)->cursor()->each(function ($client){
|
||||
|
||||
$contact = $client->contacts->sortByDesc('is_primary')->first();
|
||||
$contact->is_primary = true;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Jobs\Util;
|
||||
|
||||
use App\Exceptions\ClientHostedMigrationException;
|
||||
use App\Exceptions\MigrationValidatorFailed;
|
||||
use App\Exceptions\NonExistingMigrationFile;
|
||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||
@ -126,7 +127,7 @@ class StartMigration implements ShouldQueue
|
||||
App::forgetInstance('translator');
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||
} catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing | \Exception $e) {
|
||||
} catch (ClientHostedMigrationException | NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing | \Exception $e) {
|
||||
$this->company->update_products = $update_product_flag;
|
||||
$this->company->save();
|
||||
|
||||
|
@ -42,6 +42,7 @@ class MigrationFailed extends Mailable
|
||||
->from(config('mail.from.address'), config('mail.from.name'))
|
||||
->text('email.migration.failed_text')
|
||||
->view('email.migration.failed', [
|
||||
'special_message' => '',
|
||||
'logo' => $this->company->present()->logo(),
|
||||
'settings' => $this->company->settings,
|
||||
'is_system' => $this->is_system,
|
||||
|
@ -8,6 +8,8 @@
|
||||
{!! $exception->getMessage() !!}
|
||||
{!! $content !!}
|
||||
@else
|
||||
@if($special_message)
|
||||
@endif
|
||||
<p>Please contact us at contact@invoiceninja.com for more information on this error.</p>
|
||||
@endif
|
||||
</pre>
|
||||
|
@ -91,7 +91,7 @@ class PurchaseOrderTest extends TestCase
|
||||
|
||||
$data = [
|
||||
'ids' =>[$this->purchase_order->hashed_id],
|
||||
'action' => 'email',
|
||||
'action' => 'download',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
|
Loading…
x
Reference in New Issue
Block a user