mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 08:51:12 -06:00
Code reformat
This commit is contained in:
parent
61efabb3b5
commit
4d1771614a
@ -3,26 +3,24 @@
|
|||||||
namespace FireflyIII\Jobs;
|
namespace FireflyIII\Jobs;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Jobs\Job;
|
|
||||||
use FireflyIII\User;
|
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
use FireflyIII\Rules\Processor;
|
use FireflyIII\Rules\Processor;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use FireflyIII\User;
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Log;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
|
class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
|
||||||
{
|
{
|
||||||
use InteractsWithQueue, SerializesModels;
|
use InteractsWithQueue, SerializesModels;
|
||||||
|
|
||||||
/** @var RuleGroup */
|
|
||||||
private $ruleGroup;
|
|
||||||
/** @var Collection */
|
/** @var Collection */
|
||||||
private $accounts;
|
private $accounts;
|
||||||
/** @var Carbon */
|
/** @var Carbon */
|
||||||
private $endDate;
|
private $endDate;
|
||||||
|
/** @var RuleGroup */
|
||||||
|
private $ruleGroup;
|
||||||
/** @var Carbon */
|
/** @var Carbon */
|
||||||
private $startDate;
|
private $startDate;
|
||||||
/** @var User */
|
/** @var User */
|
||||||
@ -31,13 +29,80 @@ class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
|
|||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __construct(RuleGroup $ruleGroup)
|
public function __construct(RuleGroup $ruleGroup)
|
||||||
{
|
{
|
||||||
$this->ruleGroup = $ruleGroup;
|
$this->ruleGroup = $ruleGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAccounts()
|
||||||
|
{
|
||||||
|
return $this->accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param Collection $accounts
|
||||||
|
*/
|
||||||
|
public function setAccounts(Collection $accounts)
|
||||||
|
{
|
||||||
|
$this->accounts = $accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Carbon\Carbon
|
||||||
|
*/
|
||||||
|
public function getEndDate()
|
||||||
|
{
|
||||||
|
return $this->endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param Carbon $date
|
||||||
|
*/
|
||||||
|
public function setEndDate(Carbon $date)
|
||||||
|
{
|
||||||
|
$this->endDate = $date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Carbon\Carbon
|
||||||
|
*/
|
||||||
|
public function getStartDate()
|
||||||
|
{
|
||||||
|
return $this->startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param Carbon $date
|
||||||
|
*/
|
||||||
|
public function setStartDate(Carbon $date)
|
||||||
|
{
|
||||||
|
$this->startDate = $date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
|
public function getUser()
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function setUser(User $user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
@ -52,7 +117,7 @@ class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
|
|||||||
$processors = $this->collectProcessors();
|
$processors = $this->collectProcessors();
|
||||||
|
|
||||||
// Execute the rules for each transaction
|
// Execute the rules for each transaction
|
||||||
foreach($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
/** @var Processor $processor */
|
/** @var Processor $processor */
|
||||||
foreach ($processors as $processor) {
|
foreach ($processors as $processor) {
|
||||||
$processor->handleTransactionJournal($journal);
|
$processor->handleTransactionJournal($journal);
|
||||||
@ -67,20 +132,24 @@ class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect all journals that should be processed
|
* Collect all journals that should be processed
|
||||||
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
protected function collectJournals()
|
protected function collectJournals()
|
||||||
{
|
{
|
||||||
$args = [$this->accounts, $this->user, $this->startDate, $this->endDate];
|
$args = [$this->accounts, $this->user, $this->startDate, $this->endDate];
|
||||||
$journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args);
|
$journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args);
|
||||||
|
|
||||||
return $journalCollector->collect();
|
return $journalCollector->collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects a list of rule processors, one for each rule within the rule group
|
* Collects a list of rule processors, one for each rule within the rule group
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function collectProcessors() {
|
protected function collectProcessors()
|
||||||
|
{
|
||||||
// Find all rules belonging to this rulegroup
|
// Find all rules belonging to this rulegroup
|
||||||
$rules = $this->ruleGroup->rules()
|
$rules = $this->ruleGroup->rules()
|
||||||
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
|
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||||
@ -90,69 +159,11 @@ class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
|
|||||||
->get(['rules.*']);
|
->get(['rules.*']);
|
||||||
|
|
||||||
// Create a list of processors for these rules
|
// Create a list of processors for these rules
|
||||||
return array_map( function( $rule ) {
|
return array_map(
|
||||||
|
function ($rule) {
|
||||||
return Processor::make($rule);
|
return Processor::make($rule);
|
||||||
}, $rules->all());
|
}, $rules->all()
|
||||||
}
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return User
|
|
||||||
*/
|
|
||||||
public function getUser() {
|
|
||||||
return $this->user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param User $user
|
|
||||||
*/
|
|
||||||
public function setUser(User $user) {
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAccounts() {
|
|
||||||
return $this->accounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param Carbon $user
|
|
||||||
*/
|
|
||||||
public function setAccounts(Collection $accounts) {
|
|
||||||
$this->accounts = $accounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Carbon\Carbon
|
|
||||||
*/
|
|
||||||
public function getStartDate() {
|
|
||||||
return $this->startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param Carbon $date
|
|
||||||
*/
|
|
||||||
public function setStartDate(Carbon $date) {
|
|
||||||
$this->startDate = $date;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Carbon\Carbon
|
|
||||||
*/
|
|
||||||
public function getEndDate() {
|
|
||||||
return $this->endDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param Carbon $date
|
|
||||||
*/
|
|
||||||
public function setEndDate(Carbon $date) {
|
|
||||||
$this->endDate = $date;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@ use FireflyIII\Models\Rule;
|
|||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
use FireflyIII\Models\RuleTrigger;
|
use FireflyIII\Models\RuleTrigger;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Rules\Factory\ActionFactory;
|
|
||||||
use FireflyIII\Rules\Actions\ActionInterface;
|
use FireflyIII\Rules\Actions\ActionInterface;
|
||||||
use FireflyIII\Rules\Triggers\AbstractTrigger;
|
use FireflyIII\Rules\Factory\ActionFactory;
|
||||||
use FireflyIII\Rules\Factory\TriggerFactory;
|
use FireflyIII\Rules\Factory\TriggerFactory;
|
||||||
|
use FireflyIII\Rules\Triggers\AbstractTrigger;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@ -113,6 +113,14 @@ final class Processor
|
|||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return \FireflyIII\Models\Rule
|
||||||
|
*/
|
||||||
|
public function getRule()
|
||||||
|
{
|
||||||
|
return $this->rule;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will scan the given transaction journal and check if it matches the triggers found in the Processor
|
* This method will scan the given transaction journal and check if it matches the triggers found in the Processor
|
||||||
@ -140,14 +148,6 @@ final class Processor
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return \FireflyIII\Models\Rule
|
|
||||||
*/
|
|
||||||
public function getRule() {
|
|
||||||
return $this->rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user