mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Removed a lot of references to the old collector.
This commit is contained in:
@@ -25,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
@@ -41,8 +40,6 @@ use Illuminate\Support\Collection;
|
||||
/**
|
||||
*
|
||||
* Class ApplyRules
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ApplyRules extends Command
|
||||
{
|
||||
@@ -176,96 +173,6 @@ class ApplyRules extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $rules
|
||||
* @param Collection $transactions
|
||||
* @param bool $breakProcessing
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function applyRuleSelection(Collection $rules, Collection $transactions, bool $breakProcessing): void
|
||||
{
|
||||
$bar = $this->output->createProgressBar($rules->count() * $transactions->count());
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
/** @var Processor $processor */
|
||||
$processor = app(Processor::class);
|
||||
$processor->make($rule, true);
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
/** @noinspection DisconnectedForeachInstructionInspection */
|
||||
$bar->advance();
|
||||
$result = $processor->handleTransaction($transaction);
|
||||
if (true === $result) {
|
||||
$this->results->push($transaction);
|
||||
}
|
||||
}
|
||||
if (true === $rule->stop_processing && true === $breakProcessing) {
|
||||
$this->line('');
|
||||
$this->line(sprintf('Rule #%d ("%s") says to stop processing.', $rule->id, $rule->title));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function grabAllRules(): void
|
||||
{
|
||||
if (true === $this->option('all_rules')) {
|
||||
/** @var RuleRepositoryInterface $ruleRepos */
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$ruleRepos->setUser($this->getUser());
|
||||
$this->rules = $ruleRepos->getAll();
|
||||
|
||||
// reset rule groups.
|
||||
$this->ruleGroups = new Collection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function parseDates(): void
|
||||
{
|
||||
// parse start date.
|
||||
$startDate = Carbon::now()->startOfMonth();
|
||||
$startString = $this->option('start_date');
|
||||
if (null === $startString) {
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$repository->setUser($this->getUser());
|
||||
$first = $repository->firstNull();
|
||||
if (null !== $first) {
|
||||
$startDate = $first->date;
|
||||
}
|
||||
}
|
||||
if (null !== $startString && '' !== $startString) {
|
||||
$startDate = Carbon::createFromFormat('Y-m-d', $startString);
|
||||
}
|
||||
|
||||
// parse end date
|
||||
$endDate = Carbon::now();
|
||||
$endString = $this->option('end_date');
|
||||
if (null !== $endString && '' !== $endString) {
|
||||
$endDate = Carbon::createFromFormat('Y-m-d', $endString);
|
||||
}
|
||||
|
||||
if ($startDate > $endDate) {
|
||||
[$endDate, $startDate] = [$startDate, $endDate];
|
||||
}
|
||||
|
||||
$this->startDate = $startDate;
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
@@ -417,5 +324,95 @@ class ApplyRules extends Command
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function grabAllRules(): void
|
||||
{
|
||||
if (true === $this->option('all_rules')) {
|
||||
/** @var RuleRepositoryInterface $ruleRepos */
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$ruleRepos->setUser($this->getUser());
|
||||
$this->rules = $ruleRepos->getAll();
|
||||
|
||||
// reset rule groups.
|
||||
$this->ruleGroups = new Collection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function parseDates(): void
|
||||
{
|
||||
// parse start date.
|
||||
$startDate = Carbon::now()->startOfMonth();
|
||||
$startString = $this->option('start_date');
|
||||
if (null === $startString) {
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$repository->setUser($this->getUser());
|
||||
$first = $repository->firstNull();
|
||||
if (null !== $first) {
|
||||
$startDate = $first->date;
|
||||
}
|
||||
}
|
||||
if (null !== $startString && '' !== $startString) {
|
||||
$startDate = Carbon::createFromFormat('Y-m-d', $startString);
|
||||
}
|
||||
|
||||
// parse end date
|
||||
$endDate = Carbon::now();
|
||||
$endString = $this->option('end_date');
|
||||
if (null !== $endString && '' !== $endString) {
|
||||
$endDate = Carbon::createFromFormat('Y-m-d', $endString);
|
||||
}
|
||||
|
||||
if ($startDate > $endDate) {
|
||||
[$endDate, $startDate] = [$startDate, $endDate];
|
||||
}
|
||||
|
||||
$this->startDate = $startDate;
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $rules
|
||||
* @param Collection $transactions
|
||||
* @param bool $breakProcessing
|
||||
*
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
private function applyRuleSelection(Collection $rules, Collection $transactions, bool $breakProcessing): void
|
||||
{
|
||||
$bar = $this->output->createProgressBar($rules->count() * $transactions->count());
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
/** @var Processor $processor */
|
||||
$processor = app(Processor::class);
|
||||
$processor->make($rule, true);
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
/** @noinspection DisconnectedForeachInstructionInspection */
|
||||
$bar->advance();
|
||||
$result = $processor->handleTransaction($transaction);
|
||||
if (true === $result) {
|
||||
$this->results->push($transaction);
|
||||
}
|
||||
}
|
||||
if (true === $rule->stop_processing && true === $breakProcessing) {
|
||||
$this->line('');
|
||||
$this->line(sprintf('Rule #%d ("%s") says to stop processing.', $rule->id, $rule->title));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -152,7 +152,7 @@ class ApplyRules extends Command
|
||||
$this->line(sprintf('Will apply %d rules to %d transactions.', $count, count($journals)));
|
||||
|
||||
// start looping.
|
||||
$bar = $this->output->createProgressBar(count($journals) * $count);
|
||||
$bar = $this->output->createProgressBar(count($journals));
|
||||
Log::debug(sprintf('Now looping %d transactions.', count($journals)));
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
@@ -168,7 +168,7 @@ class ApplyRules extends Command
|
||||
$processor = app(Processor::class);
|
||||
$processor->make($rule, true);
|
||||
$ruleTriggered = $processor->handleJournalArray($journal);
|
||||
$bar->advance();
|
||||
|
||||
if ($ruleTriggered) {
|
||||
$groupTriggered = true;
|
||||
}
|
||||
@@ -187,6 +187,7 @@ class ApplyRules extends Command
|
||||
}
|
||||
}
|
||||
Log::debug('Done with all rules for this group + done with journal.');
|
||||
$bar->advance();
|
||||
}
|
||||
$this->line('');
|
||||
$this->line('Done!');
|
||||
|
Reference in New Issue
Block a user