mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -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\Analytics\MigrationFailure;
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
|
use App\Exceptions\ClientHostedMigrationException;
|
||||||
use App\Exceptions\MigrationValidatorFailed;
|
use App\Exceptions\MigrationValidatorFailed;
|
||||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||||
use App\Exceptions\ResourceDependencyMissing;
|
use App\Exceptions\ResourceDependencyMissing;
|
||||||
@ -582,18 +583,44 @@ class Import implements ShouldQueue
|
|||||||
$validator = null;
|
$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
|
* @param array $data
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function processUsers(array $data): void
|
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();
|
User::unguard();
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'*.first_name' => ['string'],
|
'*.first_name' => ['string'],
|
||||||
'*.last_name' => ['string'],
|
'*.last_name' => ['string'],
|
||||||
//'*.email' => ['distinct'],
|
|
||||||
'*.email' => ['distinct', 'email', new ValidUserForCompany()],
|
'*.email' => ['distinct', 'email', new ValidUserForCompany()],
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -749,7 +776,7 @@ class Import implements ShouldQueue
|
|||||||
|
|
||||||
Client::reguard();
|
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 = $client->contacts->sortByDesc('is_primary')->first();
|
||||||
$contact->is_primary = true;
|
$contact->is_primary = true;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Util;
|
namespace App\Jobs\Util;
|
||||||
|
|
||||||
|
use App\Exceptions\ClientHostedMigrationException;
|
||||||
use App\Exceptions\MigrationValidatorFailed;
|
use App\Exceptions\MigrationValidatorFailed;
|
||||||
use App\Exceptions\NonExistingMigrationFile;
|
use App\Exceptions\NonExistingMigrationFile;
|
||||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||||
@ -126,7 +127,7 @@ class StartMigration implements ShouldQueue
|
|||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
$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->update_products = $update_product_flag;
|
||||||
$this->company->save();
|
$this->company->save();
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ class MigrationFailed extends Mailable
|
|||||||
->from(config('mail.from.address'), config('mail.from.name'))
|
->from(config('mail.from.address'), config('mail.from.name'))
|
||||||
->text('email.migration.failed_text')
|
->text('email.migration.failed_text')
|
||||||
->view('email.migration.failed', [
|
->view('email.migration.failed', [
|
||||||
|
'special_message' => '',
|
||||||
'logo' => $this->company->present()->logo(),
|
'logo' => $this->company->present()->logo(),
|
||||||
'settings' => $this->company->settings,
|
'settings' => $this->company->settings,
|
||||||
'is_system' => $this->is_system,
|
'is_system' => $this->is_system,
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
{!! $exception->getMessage() !!}
|
{!! $exception->getMessage() !!}
|
||||||
{!! $content !!}
|
{!! $content !!}
|
||||||
@else
|
@else
|
||||||
|
@if($special_message)
|
||||||
|
@endif
|
||||||
<p>Please contact us at contact@invoiceninja.com for more information on this error.</p>
|
<p>Please contact us at contact@invoiceninja.com for more information on this error.</p>
|
||||||
@endif
|
@endif
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -91,7 +91,7 @@ class PurchaseOrderTest extends TestCase
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'ids' =>[$this->purchase_order->hashed_id],
|
'ids' =>[$this->purchase_order->hashed_id],
|
||||||
'action' => 'email',
|
'action' => 'download',
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user