mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 11:04:37 -04:00
Send e-mail when migration has completed (#3573)
- New completed.blade.php - Apply php-cs-fixer on Import.php
This commit is contained in:
parent
ceb82ad275
commit
f9567e8227
@ -19,6 +19,7 @@ use App\Http\ValidationRules\ValidCompanyGatewayFeesAndLimitsRule;
|
||||
use App\Http\ValidationRules\ValidUserForCompany;
|
||||
use App\Jobs\Company\CreateCompanyToken;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\MigrationCompleted;
|
||||
use App\Mail\MigrationFailed;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientGatewayToken;
|
||||
@ -135,23 +136,23 @@ class Import implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
foreach ($this->data as $key => $resource) {
|
||||
|
||||
if (! in_array($key, $this->available_imports)) {
|
||||
//throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration.");
|
||||
\Log::error("cannot migrate {$key} yet....");
|
||||
info("Resource {$key} is not available for migration.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = sprintf("process%s", Str::ucfirst(Str::camel($key)));
|
||||
$method = sprintf('process%s', Str::ucfirst(Str::camel($key)));
|
||||
|
||||
\Log::error("Importing {$key}");
|
||||
info("Importing {$key}");
|
||||
|
||||
$this->{$method}($resource);
|
||||
|
||||
}
|
||||
|
||||
Mail::to($this->user)->send(new MigrationCompleted());
|
||||
|
||||
info('Completed🚀🚀🚀🚀🚀 at '.now());
|
||||
}
|
||||
|
||||
@ -170,7 +171,6 @@ class Import implements ShouldQueue
|
||||
$validator = Validator::make($data, $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
throw new MigrationValidatorFailed(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
@ -186,13 +186,10 @@ class Import implements ShouldQueue
|
||||
|
||||
private function transformCompanyData(array $data): array
|
||||
{
|
||||
|
||||
$company_settings = CompanySettings::defaults();
|
||||
|
||||
if (array_key_exists('settings', $data)) {
|
||||
|
||||
foreach ($data['settings'] as $key => $value) {
|
||||
|
||||
if ($key == 'invoice_design_id' || $key == 'quote_design_id' || $key == 'credit_design_id') {
|
||||
$value = $this->encodePrimaryKey($value);
|
||||
}
|
||||
@ -201,17 +198,13 @@ class Import implements ShouldQueue
|
||||
$value = -1;
|
||||
}
|
||||
|
||||
|
||||
$company_settings->{$key} = $value;
|
||||
|
||||
}
|
||||
|
||||
$data['settings'] = $company_settings;
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -423,8 +416,9 @@ class Import implements ShouldQueue
|
||||
|
||||
unset($modified['id']);
|
||||
|
||||
if(array_key_exists('invitations', $modified))
|
||||
if (array_key_exists('invitations', $modified)) {
|
||||
unset($modified['invitations']);
|
||||
}
|
||||
|
||||
$invoice = $invoice_repository->save(
|
||||
$modified,
|
||||
@ -471,8 +465,9 @@ class Import implements ShouldQueue
|
||||
|
||||
unset($modified['id']);
|
||||
|
||||
if(array_key_exists('invitations', $modified))
|
||||
if (array_key_exists('invitations', $modified)) {
|
||||
unset($modified['invitations']);
|
||||
}
|
||||
|
||||
$credit = $credit_repository->save(
|
||||
$modified,
|
||||
@ -520,8 +515,9 @@ class Import implements ShouldQueue
|
||||
|
||||
unset($modified['id']);
|
||||
|
||||
if(array_key_exists('invitations', $modified))
|
||||
if (array_key_exists('invitations', $modified)) {
|
||||
unset($modified['invitations']);
|
||||
}
|
||||
|
||||
$invoice = $quote_repository->save(
|
||||
$modified,
|
||||
@ -590,7 +586,7 @@ class Import implements ShouldQueue
|
||||
"payments_{$old_user_key}" => [
|
||||
'old' => $old_user_key,
|
||||
'new' => $payment->id,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -600,7 +596,7 @@ class Import implements ShouldQueue
|
||||
private function processDocuments(array $data): void
|
||||
{
|
||||
Document::unguard();
|
||||
/** No validators since data provided by database is already valid. */
|
||||
/* No validators since data provided by database is already valid. */
|
||||
|
||||
foreach ($data as $resource) {
|
||||
$modified = $resource;
|
||||
@ -613,7 +609,7 @@ class Import implements ShouldQueue
|
||||
throw new ResourceDependencyMissing('Processing documents failed, because of missing dependency - expenses.');
|
||||
}
|
||||
|
||||
/** Remove because of polymorphic joins. */
|
||||
/* Remove because of polymorphic joins. */
|
||||
unset($modified['invoice_id']);
|
||||
unset($modified['expense_id']);
|
||||
|
||||
@ -641,7 +637,7 @@ class Import implements ShouldQueue
|
||||
"documents_{$old_user_key}" => [
|
||||
'old' => $resource['id'],
|
||||
'new' => $document->id,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -687,7 +683,7 @@ class Import implements ShouldQueue
|
||||
"company_gateways_{$old_user_key}" => [
|
||||
'old' => $resource['id'],
|
||||
'new' => $company_gateway->id,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -714,7 +710,7 @@ class Import implements ShouldQueue
|
||||
"client_gateway_tokens_{$old_user_key}" => [
|
||||
'old' => $resource['id'],
|
||||
'new' => $cgt->id,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -767,7 +763,7 @@ class Import implements ShouldQueue
|
||||
}
|
||||
|
||||
/**
|
||||
* Process & handle user_id
|
||||
* Process & handle user_id.
|
||||
*
|
||||
* @param array $resource
|
||||
* @return int|mixed
|
||||
@ -786,10 +782,9 @@ class Import implements ShouldQueue
|
||||
return $this->transformId('users', $resource['user_id']);
|
||||
}
|
||||
|
||||
|
||||
public function failed($exception = null)
|
||||
{
|
||||
\Log::error("the job failed");
|
||||
\Log::error(print_r($exception->getMessage(),1));
|
||||
info('the job failed');
|
||||
info(print_r($exception->getMessage(), 1));
|
||||
}
|
||||
}
|
||||
|
33
app/Mail/MigrationCompleted.php
Normal file
33
app/Mail/MigrationCompleted.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MigrationCompleted extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->view('email.migration.completed');
|
||||
}
|
||||
}
|
31
resources/views/email/migration/completed.blade.php
Normal file
31
resources/views/email/migration/completed.blade.php
Normal file
@ -0,0 +1,31 @@
|
||||
@component('email.template.master', ['design' => 'light'])
|
||||
|
||||
@slot('header')
|
||||
@component('email.components.header')
|
||||
Migration completed
|
||||
@endcomponent
|
||||
@endslot
|
||||
|
||||
@slot('greeting')
|
||||
Hello,
|
||||
@endslot
|
||||
|
||||
We're happy to inform you that migration has been completed successfully. It is ready for you to review it.
|
||||
|
||||
@component('email.components.button', ['url' => url('/')])
|
||||
Visit portal
|
||||
@endcomponent
|
||||
|
||||
|
||||
@slot('signature')
|
||||
Thank you, <br>
|
||||
Invoice Ninja
|
||||
@endslot
|
||||
|
||||
@slot('footer')
|
||||
@component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja'])
|
||||
For any info, please visit InvoiceNinja.
|
||||
@endcomponent
|
||||
@endslot
|
||||
|
||||
@endcomponent
|
Loading…
x
Reference in New Issue
Block a user