mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-10 05:11:25 +00:00
Add a bunch of debug #11247
This commit is contained in:
@@ -174,7 +174,7 @@ class EditController extends Controller
|
|||||||
public function update(RecurrenceFormRequest $request, Recurrence $recurrence)
|
public function update(RecurrenceFormRequest $request, Recurrence $recurrence)
|
||||||
{
|
{
|
||||||
$data = $request->getAll();
|
$data = $request->getAll();
|
||||||
$this->repository->update($recurrence, $data);
|
$recurrence = $this->repository->update($recurrence, $data);
|
||||||
|
|
||||||
$request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title]));
|
$request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title]));
|
||||||
Log::channel('audit')->info(sprintf('Updated recurrence #%d.', $recurrence->id), $data);
|
Log::channel('audit')->info(sprintf('Updated recurrence #%d.', $recurrence->id), $data);
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use function Safe\json_decode;
|
use function Safe\json_decode;
|
||||||
|
|
||||||
class RecurringEnrichment implements EnrichmentInterface
|
class RecurringEnrichment implements EnrichmentInterface
|
||||||
@@ -70,6 +69,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
private array $notes = [];
|
private array $notes = [];
|
||||||
private readonly TransactionCurrency $primaryCurrency;
|
private readonly TransactionCurrency $primaryCurrency;
|
||||||
private array $recurrenceIds = [];
|
private array $recurrenceIds = [];
|
||||||
|
private array $recurrenceByTransaction = [];
|
||||||
private array $repetitions = [];
|
private array $repetitions = [];
|
||||||
private array $sourceAccountIds = [];
|
private array $sourceAccountIds = [];
|
||||||
private array $transactions = [];
|
private array $transactions = [];
|
||||||
@@ -84,6 +84,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
public function enrich(Collection $collection): Collection
|
public function enrich(Collection $collection): Collection
|
||||||
{
|
{
|
||||||
|
Log::debug(__METHOD__);
|
||||||
$this->collection = $collection;
|
$this->collection = $collection;
|
||||||
$this->collectIds();
|
$this->collectIds();
|
||||||
$this->collectRepetitions();
|
$this->collectRepetitions();
|
||||||
@@ -194,6 +195,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$id = (int)$account->id;
|
$id = (int)$account->id;
|
||||||
$this->accounts[$id] = $account;
|
$this->accounts[$id] = $account;
|
||||||
|
Log::debug(sprintf('Collected account #%d', $id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,6 +281,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
foreach ($currencies as $currency) {
|
foreach ($currencies as $currency) {
|
||||||
$id = (int)$currency->id;
|
$id = (int)$currency->id;
|
||||||
$this->currencies[$id] = $currency;
|
$this->currencies[$id] = $currency;
|
||||||
|
Log::debug(sprintf('Collected currency #%d', $id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,18 +290,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
/** @var Recurrence $recurrence */
|
/** @var Recurrence $recurrence */
|
||||||
foreach ($this->collection as $recurrence) {
|
foreach ($this->collection as $recurrence) {
|
||||||
$id = (int)$recurrence->id;
|
$id = (int)$recurrence->id;
|
||||||
// $typeId = (int)$recurrence->transaction_type_id;
|
|
||||||
$this->ids[] = $id;
|
$this->ids[] = $id;
|
||||||
// $this->transactionTypeIds[$id] = $typeId;
|
Log::debug(sprintf('Collected recurrence id #%d', $id));
|
||||||
}
|
}
|
||||||
$this->ids = array_unique($this->ids);
|
$this->ids = array_unique($this->ids);
|
||||||
|
Log::debug('Final array:', $this->ids);
|
||||||
// collect transaction types.
|
|
||||||
// $transactionTypes = TransactionType::whereIn('id', array_unique($this->transactionTypeIds))->get();
|
|
||||||
// foreach ($transactionTypes as $transactionType) {
|
|
||||||
// $id = (int)$transactionType->id;
|
|
||||||
// $this->transactionTypes[$id] = TransactionTypeEnum::from($transactionType->type);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function collectNotes(): void
|
private function collectNotes(): void
|
||||||
@@ -306,10 +302,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
$notes = Note::query()->whereIn('noteable_id', $this->ids)
|
$notes = Note::query()->whereIn('noteable_id', $this->ids)
|
||||||
->whereNotNull('notes.text')
|
->whereNotNull('notes.text')
|
||||||
->where('notes.text', '!=', '')
|
->where('notes.text', '!=', '')
|
||||||
->where('noteable_type', Recurrence::class)->get(['notes.noteable_id', 'notes.text'])->toArray()
|
->where('noteable_type', Recurrence::class)->get(['notes.id', 'notes.noteable_id', 'notes.text'])->toArray();
|
||||||
;
|
|
||||||
foreach ($notes as $note) {
|
foreach ($notes as $note) {
|
||||||
$this->notes[(int)$note['noteable_id']] = (string)$note['text'];
|
$notableId = (int)$note['noteable_id'];
|
||||||
|
$this->notes[$notableId] = (string)$note['text'];
|
||||||
|
Log::debug(sprintf('Collected note #%d for recurrence #%d', $note['id'], $notableId));
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('Enrich with %d note(s)', count($this->notes)));
|
Log::debug(sprintf('Enrich with %d note(s)', count($this->notes)));
|
||||||
}
|
}
|
||||||
@@ -343,9 +340,10 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
foreach ($set as $repetition) {
|
foreach ($set as $repetition) {
|
||||||
$recurrence = $this->collection->filter(fn(Recurrence $item): bool => (int)$item->id === (int)$repetition->recurrence_id)->first();
|
$recurrence = $this->collection->filter(fn(Recurrence $item): bool => (int)$item->id === (int)$repetition->recurrence_id)->first();
|
||||||
$fromDate = clone($recurrence->latest_date ?? $recurrence->first_date);
|
$fromDate = clone($recurrence->latest_date ?? $recurrence->first_date);
|
||||||
$id = (int)$repetition->recurrence_id;
|
$recurrenceId = (int)$repetition->recurrence_id;
|
||||||
$repId = (int)$repetition->id;
|
$repId = (int)$repetition->id;
|
||||||
$this->repetitions[$id] ??= [];
|
$this->repetitions[$recurrenceId] ??= [];
|
||||||
|
Log::debug(sprintf('Collected repetition #%d of recurrence #%d.', $repId, $recurrenceId));
|
||||||
|
|
||||||
// get the (future) occurrences for this specific type of repetition:
|
// get the (future) occurrences for this specific type of repetition:
|
||||||
$amount = 'daily' === $repetition->repetition_type ? 9 : 5;
|
$amount = 'daily' === $repetition->repetition_type ? 9 : 5;
|
||||||
@@ -356,7 +354,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
foreach ($set as $carbon) {
|
foreach ($set as $carbon) {
|
||||||
$occurrences[] = $carbon->toAtomString();
|
$occurrences[] = $carbon->toAtomString();
|
||||||
}
|
}
|
||||||
$this->repetitions[$id][$repId] = [
|
$this->repetitions[$recurrenceId][$repId] = [
|
||||||
'id' => (string)$repId,
|
'id' => (string)$repId,
|
||||||
'created_at' => $repetition->created_at->toAtomString(),
|
'created_at' => $repetition->created_at->toAtomString(),
|
||||||
'updated_at' => $repetition->updated_at->toAtomString(),
|
'updated_at' => $repetition->updated_at->toAtomString(),
|
||||||
@@ -373,8 +371,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
private function collectTransactionMetaData(): void
|
private function collectTransactionMetaData(): void
|
||||||
{
|
{
|
||||||
$ids = array_keys($this->transactions);
|
$rtIds = [];
|
||||||
$meta = RecurrenceTransactionMeta::whereNull('deleted_at')->whereIn('rt_id', $ids)->get();
|
foreach ($this->ids as $recurrenceId) {
|
||||||
|
$rtIds = array_merge($rtIds, array_keys($this->transactions[$recurrenceId]));
|
||||||
|
}
|
||||||
|
$meta = RecurrenceTransactionMeta::whereNull('deleted_at')->whereIn('rt_id', $rtIds)->get();
|
||||||
// other meta-data to be collected:
|
// other meta-data to be collected:
|
||||||
$billIds = [];
|
$billIds = [];
|
||||||
$piggyBankIds = [];
|
$piggyBankIds = [];
|
||||||
@@ -386,10 +387,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
$transactionId = (int)$entry->rt_id;
|
$transactionId = (int)$entry->rt_id;
|
||||||
|
|
||||||
// this should refer to another array, were rtIds can be used to find the recurrence.
|
// this should refer to another array, were rtIds can be used to find the recurrence.
|
||||||
$recurrenceId = $this->recurrenceIds[$transactionId] ?? 0;
|
$recurrenceId = $this->recurrenceByTransaction[$transactionId] ?? 0;
|
||||||
|
Log::debug(sprintf('Collecting meta data entry #%d for recurrence transaction #%d, for recurrence #%d ', $id, $transactionId, $recurrenceId));
|
||||||
$name = (string)($entry->name ?? '');
|
$name = (string)($entry->name ?? '');
|
||||||
if (0 === $recurrenceId) {
|
if (0 === $recurrenceId) {
|
||||||
Log::error(sprintf('Could not find recurrence ID for recurrence transaction ID %d', $transactionId));
|
Log::error(sprintf('Could not find recurrence ID for recurrence transaction ID #%d', $transactionId));
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -487,16 +489,16 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
|
|
||||||
/** @var RecurrenceTransaction $transaction */
|
/** @var RecurrenceTransaction $transaction */
|
||||||
foreach ($set as $transaction) {
|
foreach ($set as $transaction) {
|
||||||
$id = (int)$transaction->recurrence_id;
|
$recurrenceId = (int)$transaction->recurrence_id;
|
||||||
$transactionId = (int)$transaction->id;
|
$transactionId = (int)$transaction->id;
|
||||||
$this->recurrenceIds[$transactionId] = $id;
|
$this->recurrenceByTransaction[$transactionId] = $recurrenceId;
|
||||||
$this->transactions[$id] ??= [];
|
$this->transactions[$recurrenceId] ??= [];
|
||||||
$amount = $transaction->amount;
|
$amount = $transaction->amount;
|
||||||
$foreignAmount = $transaction->foreign_amount;
|
$foreignAmount = $transaction->foreign_amount;
|
||||||
|
Log::debug(sprintf('Collected transaction #%d of recurrence #%d', $transactionId, $recurrenceId));
|
||||||
|
|
||||||
$this->transactions[$id][$transactionId] = [
|
$this->transactions[$recurrenceId][$transactionId] = [
|
||||||
'id' => (string)$transactionId,
|
'id' => (string)$transactionId,
|
||||||
// 'recurrence_id' => $id,
|
|
||||||
'transaction_currency_id' => (int)$transaction->transaction_currency_id,
|
'transaction_currency_id' => (int)$transaction->transaction_currency_id,
|
||||||
'foreign_currency_id' => null === $transaction->foreign_currency_id ? null : (int)$transaction->foreign_currency_id,
|
'foreign_currency_id' => null === $transaction->foreign_currency_id ? null : (int)$transaction->foreign_currency_id,
|
||||||
'source_id' => (int)$transaction->source_id,
|
'source_id' => (int)$transaction->source_id,
|
||||||
@@ -518,7 +520,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
|||||||
'subscription_name' => null,
|
'subscription_name' => null,
|
||||||
|
|
||||||
];
|
];
|
||||||
// collect all kinds of meta data to be collected later.
|
// collect all kinds of meta-data to be collected later.
|
||||||
$this->currencyIds[$transactionId] = (int)$transaction->transaction_currency_id;
|
$this->currencyIds[$transactionId] = (int)$transaction->transaction_currency_id;
|
||||||
$this->sourceAccountIds[$transactionId] = (int)$transaction->source_id;
|
$this->sourceAccountIds[$transactionId] = (int)$transaction->source_id;
|
||||||
$this->destinationAccountIds[$transactionId] = (int)$transaction->destination_id;
|
$this->destinationAccountIds[$transactionId] = (int)$transaction->destination_id;
|
||||||
|
|||||||
Reference in New Issue
Block a user