Remove journal collector.

This commit is contained in:
James Cole 2016-05-01 09:52:58 +02:00
parent c66df3cb2c
commit b80db054e2
5 changed files with 53 additions and 77 deletions

View File

@ -10,12 +10,11 @@ declare(strict_types = 1);
namespace FireflyIII\Export;
use Auth;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Export\Entry\Entry;
use FireflyIII\Models\ExportJob;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalCollector;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Collection;
use Log;
@ -91,10 +90,10 @@ class Processor
*/
public function collectJournals(): bool
{
$args = [$this->accounts, Auth::user(), $this->settings['startDate'], $this->settings['endDate']];
/** @var JournalCollector $journalCollector */
$journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args);
$this->journals = $journalCollector->collect();
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$this->journals = $repository->getJournalsInRange($this->accounts, $this->settings['startDate'], $this->settings['endDate']);
Log::debug(
'Collected ' .
$this->journals->count() . ' journals (between ' .

View File

@ -4,6 +4,7 @@ namespace FireflyIII\Jobs;
use Carbon\Carbon;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Rules\Processor;
use FireflyIII\User;
use Illuminate\Contracts\Queue\ShouldQueue;
@ -143,10 +144,10 @@ class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
*/
protected function collectJournals()
{
$args = [$this->accounts, $this->user, $this->startDate, $this->endDate];
$journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args);
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
return $journalCollector->collect();
return $repository->getJournalsInRange($this->accounts, $this->startDate, $this->endDate);
}
/**

View File

@ -1,67 +0,0 @@
<?php
declare(strict_types = 1);
/**
* JournalCollector.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Repositories\Journal;
use Carbon\Carbon;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
* Class JournalCollector
*
* @package FireflyIII\Export\Collector
*/
class JournalCollector
{
/** @var Collection */
private $accounts;
/** @var Carbon */
private $end;
/** @var Carbon */
private $start;
/** @var User */
private $user;
/**
* JournalCollector constructor.
*
* @param Collection $accounts
* @param User $user
* @param Carbon $start
* @param Carbon $end
*/
public function __construct(Collection $accounts, User $user, Carbon $start, Carbon $end)
{
$this->accounts = $accounts;
$this->user = $user;
$this->start = $start;
$this->end = $end;
}
/**
* @deprecated
* @return Collection
*/
public function collect(): Collection
{
// get all the journals:
$ids = $this->accounts->pluck('id')->toArray();
return $this->user->transactionjournals()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->whereIn('transactions.account_id', $ids)
->before($this->end)
->after($this->start)
->orderBy('transaction_journals.date')
->get(['transaction_journals.*']);
}
}

View File

@ -15,6 +15,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
@ -134,6 +135,36 @@ class JournalRepository implements JournalRepositoryInterface
return $journals;
}
/**
* Returns a collection of ALL journals, given a specific account and a date range.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
public function getJournalsInRange(Collection $accounts, Carbon $start, Carbon $end): Collection
{
$query = $this->user->transactionJournals()->expanded();
$query->before($end);
$query->after($start);
if ($accounts->count() > 0) {
$ids = $accounts->pluck('id')->toArray();
$query->where(
function (Builder $q) use ($ids) {
$q->whereIn('destination.account_id', $ids);
$q->orWhereIn('source.account_id', $ids);
}
);
}
$set = $query->get(TransactionJournal::queryFields());
return $set;
}
/**
* @param array $data
*

View File

@ -6,7 +6,6 @@ namespace FireflyIII\Repositories\Journal;
use Carbon\Carbon;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@ -55,6 +54,8 @@ interface JournalRepositoryInterface
public function getAmountBefore(TransactionJournal $journal, Transaction $transaction): string;
/**
* Returns a page of a specific type(s) of journal.
*
* @param array $types
* @param int $page
* @param int $pageSize
@ -63,6 +64,17 @@ interface JournalRepositoryInterface
*/
public function getJournals(array $types, int $page, int $pageSize = 50): LengthAwarePaginator;
/**
* Returns a collection of ALL journals, given a specific account and a date range.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return Collection
*/
public function getJournalsInRange(Collection $accounts, Carbon $start, Carbon $end): Collection;
/**
* @param array $data
*