1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for imports

This commit is contained in:
David Bomba 2023-06-25 19:04:06 +10:00
parent 6b78cd7a63
commit 9363a3f7b6

View File

@ -135,6 +135,7 @@ class Import implements ShouldQueue
'recurring_expenses',
'tasks',
'documents',
'activities',
];
/**
@ -1776,6 +1777,75 @@ class Import implements ShouldQueue
$data = null;
}
private function processActivities(array $data): void
{
Activity::where('company_id', $this->company->id)->cursor()->each(function ($a){
$a->forceDelete();
});
Activity::unguard();
foreach ($data as $resource) {
$modified = $resource;
$modified['company_id'] = $this->company->id;
$modified['user_id'] = $this->processUserId($resource);
try {
if (isset($modified['client_id'])) {
$modified['client_id'] = $this->transformId('clients', $resource['client_id']);
}
if (isset($modified['invoice_id'])) {
$modified['invoice_id'] = $this->transformId('invoices', $resource['invoice_id']);
}
if (isset($modified['quote_id'])) {
$modified['quote_id'] = $this->transformId('quotes', $resource['quote_id']);
}
if (isset($modified['recurring_invoice_id'])) {
$modified['recurring_invoice_id'] = $this->transformId('recurring_invoices', $resource['recurring_invoice_id']);
}
if (isset($modified['payment_id'])) {
$modified['payment_id'] = $this->transformId('payments', $resource['payment_id']);
}
if (isset($modified['credit_id'])) {
$modified['credit_id'] = $this->transformId('credits', $resource['credit_id']);
}
if (isset($modified['expense_id'])) {
$modified['expense_id'] = $this->transformId('expenses', $resource['expense_id']);
}
if (isset($modified['task_id'])) {
$modified['task_id'] = $this->transformId('tasks', $resource['task_id']);
}
if (isset($modified['client_contact_id'])) {
$modified['client_contact_id'] = $this->transformId('client_contacts', $resource['client_contact_id']);
}
$act = Activity::make($modified);
$act->save(['timestamps' => false]);
}
catch (\Exception $e) {
nlog("could not import activity: {$e->getMessage()}");
}
}
Activity::reguard();
}
private function processExpenses(array $data) :void
{
Expense::unguard();