mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #4587 from turbo124/v5-develop
Migrate invitations from V4
This commit is contained in:
commit
c2867c7cb6
@ -35,6 +35,8 @@ class UserWasRestored
|
||||
|
||||
public $event_vars;
|
||||
|
||||
public $fromDeleted;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
@ -42,11 +44,12 @@ class UserWasRestored
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(User $user, Company $company, array $event_vars)
|
||||
public function __construct(User $user, bool $fromDeleted, Company $company, array $event_vars)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
$this->fromDeleted = $fromDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -459,6 +459,24 @@ class Import implements ShouldQueue
|
||||
$saveable_contacts['contacts'] = $modified_contacts;
|
||||
|
||||
$contact_repository->save($saveable_contacts, $client);
|
||||
|
||||
//link contact ids
|
||||
$client->fresh();
|
||||
$new_contacts = $client->contacts;
|
||||
|
||||
foreach($resource['contacts'] as $key => $old_contact)
|
||||
{
|
||||
$contact_match = $new_contacts->where('contact_key', $old_contact['contact_key'])->first();
|
||||
|
||||
if($contact_match)
|
||||
{
|
||||
$this->ids['client_contacts']['client_contacts_'.$old_contact['id']] = [
|
||||
'old' => $old_contact['id'],
|
||||
'new' => $contact_match->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$key = "clients_{$resource['id']}";
|
||||
@ -611,6 +629,16 @@ class Import implements ShouldQueue
|
||||
|
||||
unset($modified['id']);
|
||||
|
||||
foreach($resource['invitations'] as $key => $invite)
|
||||
{
|
||||
|
||||
$resource['invitations'][$key]['client_contact_id'] = $this->transformId('client_contacts', $invite['client_contact_id']);
|
||||
$resource['invitations'][$key]['user_id'] = $modified['user_id'];
|
||||
$resource['invitations'][$key]['company_id'] = $this->company->id;
|
||||
unset($resource['invitations'][$key]['recurring_invoice_id']);
|
||||
|
||||
}
|
||||
|
||||
$invoice = $invoice_repository->save(
|
||||
$modified,
|
||||
RecurringInvoiceFactory::create($this->company->id, $modified['user_id'])
|
||||
@ -661,6 +689,18 @@ class Import implements ShouldQueue
|
||||
|
||||
unset($modified['id']);
|
||||
|
||||
foreach($resource['invitations'] as $key => $invite)
|
||||
{
|
||||
$resource['invitations'][$key]['client_contact_id'] = $this->transformId('client_contacts', $invite['client_contact_id']);
|
||||
$resource['invitations'][$key]['user_id'] = $modified['user_id'];
|
||||
$resource['invitations'][$key]['company_id'] = $this->company->id;
|
||||
unset($resource['invitations'][$key]['invoice_id']);
|
||||
|
||||
nlog("find a match for " . $invite['client_contact_id'] . " " .$resource['invitations'][$key]['client_contact_id']);
|
||||
}
|
||||
|
||||
$modified['invitations'] = $resource['invitations'];
|
||||
|
||||
$invoice = $invoice_repository->save(
|
||||
$modified,
|
||||
InvoiceFactory::create($this->company->id, $modified['user_id'])
|
||||
@ -811,11 +851,6 @@ class Import implements ShouldQueue
|
||||
//$modified['invoice_id'] = $this->transformId('invoices', $resource['invoice_id']);
|
||||
$modified['company_id'] = $this->company->id;
|
||||
|
||||
// nlog($resource);
|
||||
// nlog($resource['company_gateway_id']);
|
||||
// nlog(strlen($resource['company_gateway_id']));
|
||||
|
||||
|
||||
//unset($modified['invoices']);
|
||||
unset($modified['invoice_id']);
|
||||
|
||||
|
@ -16,8 +16,10 @@ use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Repositories\BaseRepository;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\SavesDocuments;
|
||||
@ -86,10 +88,25 @@ class InvoiceMigrationRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
|
||||
InvoiceInvitation::unguard();
|
||||
RecurringInvoiceInvitation::unguard();
|
||||
|
||||
foreach($data['invitations'] as $invitation)
|
||||
{
|
||||
nlog($invitation);
|
||||
|
||||
$new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id);
|
||||
$new_invitation->{$lcfirst_resource_id} = $model->id;
|
||||
$new_invitation->fill($invitation);
|
||||
$new_invitation->save();
|
||||
}
|
||||
|
||||
InvoiceInvitation::reguard();
|
||||
RecurringInvoiceInvitation::reguard();
|
||||
/*
|
||||
if (isset($data['invitations'])) {
|
||||
$invitations = collect($data['invitations']);
|
||||
|
||||
/* Get array of Keys which have been removed from the invitations array and soft delete each invitation */
|
||||
$model->invitations->pluck('key')->diff($invitations->pluck('key'))->each(function ($invitation) use ($resource) {
|
||||
$this->getInvitation($invitation, $resource)->delete();
|
||||
});
|
||||
@ -114,7 +131,7 @@ class InvoiceMigrationRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
$model->load('invitations');
|
||||
|
||||
/* If no invitations have been created, this is our fail safe to maintain state*/
|
||||
|
Loading…
Reference in New Issue
Block a user