1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #5963 from turbo124/v5-develop

Better logging for company importer
This commit is contained in:
David Bomba 2021-06-08 20:41:08 +10:00 committed by GitHub
commit d9d2ccf428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 89 deletions

View File

@ -17,6 +17,9 @@ use App\Factory\ClientFactory;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceInvitationFactory;
use App\Jobs\Invoice\CreateEntityPdf;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Mail\Migration\MaxCompanies;
use App\Mail\TemplateEmail;
use App\Models\Account;
use App\Models\Client;
@ -59,26 +62,9 @@ class SendTestEmails extends Command
* @return mixed
*/
public function handle()
{
$this->sendTemplateEmails('plain');
$this->sendTemplateEmails('light');
$this->sendTemplateEmails('dark');
}
private function sendTemplateEmails($template)
{
$faker = Factory::create();
$message = [
'title' => 'Invoice XJ-3838',
'body' => '<div>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</div>',
'subject' => 'The Test Subject',
'footer' => 'Lovely Footer Texts',
];
$user = User::whereEmail('user@example.com')->first();
if (! $user) {
$account = Account::factory()->create();
$user = User::factory()->create([
@ -103,57 +89,13 @@ class SendTestEmails extends Command
//'settings' => DefaultSettings::userSettings(),
'settings' => null,
]);
} else {
$company = $user->company_users->first()->company;
$account = $company->account;
}
$client = Client::all()->first();
if (! $client) {
$client = ClientFactory::create($company->id, $user->id);
$client->save();
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'is_primary' => 1,
'send_email' => true,
'email' => $faker->safeEmail,
]);
ClientContact::factory()->create([
'user_id' => $user->id,
'client_id' => $client->id,
'company_id' => $company->id,
'send_email' => true,
'email' => $faker->safeEmail,
]);
}
$invoice = InvoiceFactory::create($company->id, $user->id);
$invoice->client_id = $client->id;
$invoice->setRelation('client', $client);
$invoice->save();
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
$ii->invoice_id = $invoice->id;
$ii->client_contact_id = $client->primary_contact()->first()->id;
$ii->save();
$invoice->setRelation('invitations', $ii);
$invoice->service()->markSent()->save();
CreateEntityPdf::dispatch($invoice->invitations()->first());
$cc_emails = [config('ninja.testvars.test_email')];
$bcc_emails = [config('ninja.testvars.test_email')];
$email_builder->setFooter($message['footer'])
->setSubject($message['subject'])
->setBody($message['body']);
$nmo = new NinjaMailerObject;
$nmo->mailable = new MaxCompanies($user->account->companies()->first());
$nmo->company = $user->account->companies()->first();
$nmo->settings = $user->account->companies()->first()->settings;
$nmo->to_user = $user;
NinjaMailerJob::dispatchNow($nmo);
}
}

View File

@ -278,7 +278,7 @@ class CompanyImport implements ShouldQueue
//perform some magic here
}
if($this->pre_flight_checks_pass === false)
if(!$this->pre_flight_checks_pass)
{
$nmo = new NinjaMailerObject;
$nmo->mailable = new CompanyImportFailure($this->company, $this->message);