mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
Refactor method that only counts.
This commit is contained in:
@@ -282,9 +282,9 @@ class CreateRecurringTransactions implements ShouldQueue
|
|||||||
Log::debug(sprintf('%s IS today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
|
Log::debug(sprintf('%s IS today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
|
||||||
|
|
||||||
// count created journals on THIS day.
|
// count created journals on THIS day.
|
||||||
$created = $this->repository->getJournals($recurrence, $date, $date);
|
$journalCount = $this->repository->getJournalCount($recurrence, $date, $date);
|
||||||
if ($created->count() > 0) {
|
if ($journalCount > 0) {
|
||||||
Log::info(sprintf('Already created %d journal(s) for date %s', $created->count(), $date->format('Y-m-d')));
|
Log::info(sprintf('Already created %d journal(s) for date %s', $journalCount, $date->format('Y-m-d')));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,8 +419,8 @@ class CreateRecurringTransactions implements ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
// has repeated X times.
|
// has repeated X times.
|
||||||
$journals = $this->repository->getJournals($recurrence, null, null);
|
$journalCount = $this->repository->getJournalCount($recurrence, null, null);
|
||||||
if (0 !== $recurrence->repetitions && $journals->count() >= $recurrence->repetitions) {
|
if (0 !== $recurrence->repetitions && $journalCount >= $recurrence->repetitions) {
|
||||||
Log::info(sprintf('Recurrence #%d has run %d times, so will run no longer.', $recurrence->id, $recurrence->repetitions));
|
Log::info(sprintf('Recurrence #%d has run %d times, so will run no longer.', $recurrence->id, $recurrence->repetitions));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@@ -145,9 +145,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
|||||||
* @param Carbon|null $start
|
* @param Carbon|null $start
|
||||||
* @param Carbon|null $end
|
* @param Carbon|null $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getJournals(Recurrence $recurrence, Carbon $start = null, Carbon $end = null): Collection
|
public function getJournalCount(Recurrence $recurrence, Carbon $start = null, Carbon $end = null): int
|
||||||
{
|
{
|
||||||
$query = TransactionJournal
|
$query = TransactionJournal
|
||||||
::leftJoin('journal_meta', 'journal_meta.transaction_journal_id', '=', 'transaction_journals.id')
|
::leftJoin('journal_meta', 'journal_meta.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
@@ -162,7 +162,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
|||||||
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
|
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query->get(['transaction_journals.*']);
|
return $query->get(['transaction_journals.*'])->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -79,15 +79,15 @@ interface RecurringRepositoryInterface
|
|||||||
public function getCategory(RecurrenceTransaction $recTransaction): ?string;
|
public function getCategory(RecurrenceTransaction $recTransaction): ?string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the journals created for this recurrence, possibly limited by time.
|
* Returns the count of journals created for this recurrence, possibly limited by time.
|
||||||
*
|
*
|
||||||
* @param Recurrence $recurrence
|
* @param Recurrence $recurrence
|
||||||
* @param Carbon|null $start
|
* @param Carbon|null $start
|
||||||
* @param Carbon|null $end
|
* @param Carbon|null $end
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getJournals(Recurrence $recurrence, Carbon $start = null, Carbon $end = null): Collection;
|
public function getJournalCount(Recurrence $recurrence, Carbon $start = null, Carbon $end = null): int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the notes.
|
* Get the notes.
|
||||||
|
Reference in New Issue
Block a user