mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 08:51:12 -06:00
Cleaned up the Processor. This completely breaks everything @ roberthorlings has built but stay with me.
This commit is contained in:
parent
2bd2f5a5aa
commit
8024ad123e
@ -62,11 +62,10 @@ class FireRulesForStore
|
||||
->get(['rules.*']);
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
Log::debug('Now handling rule #' . $rule->id . ' (' . $rule->title . ')');
|
||||
$processor = new Processor($rule, $event->journal);
|
||||
|
||||
// get some return out of this?
|
||||
$processor->handle();
|
||||
Log::debug('Now handling rule #' . $rule->id . ' (' . $rule->title . ')');
|
||||
$processor = Processor::make($rule);
|
||||
$processor->handleTransactionJournal($event->journal);
|
||||
|
||||
if ($rule->stop_processing) {
|
||||
break;
|
||||
|
@ -60,10 +60,10 @@ class FireRulesForUpdate
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
Log::debug('Now handling rule #' . $rule->id . ' (' . $rule->title . ')');
|
||||
$processor = new Processor($rule, $event->journal);
|
||||
|
||||
// get some return out of this?
|
||||
$processor->handle();
|
||||
Log::debug('Now handling rule #' . $rule->id . ' (' . $rule->title . ')');
|
||||
$processor = Processor::make($rule);
|
||||
$processor->handleTransactionJournal($event->journal);
|
||||
|
||||
if ($rule->stop_processing) {
|
||||
break;
|
||||
|
@ -18,6 +18,7 @@ use FireflyIII\Rules\Actions\ActionFactory;
|
||||
use FireflyIII\Rules\Actions\ActionInterface;
|
||||
use FireflyIII\Rules\Triggers\TriggerFactory;
|
||||
use FireflyIII\Rules\Triggers\TriggerInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@ -27,57 +28,45 @@ use Log;
|
||||
*/
|
||||
class Processor
|
||||
{
|
||||
/** @var Collection */
|
||||
private $actions;
|
||||
/** @var TransactionJournal */
|
||||
protected $journal;
|
||||
private $journal;
|
||||
/** @var Rule */
|
||||
protected $rule;
|
||||
private $rule;
|
||||
/** @var Collection */
|
||||
private $triggers;
|
||||
|
||||
/**
|
||||
* Processor constructor.
|
||||
*
|
||||
* @param Rule $rule
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
public function __construct(Rule $rule, TransactionJournal $journal)
|
||||
private function __construct()
|
||||
{
|
||||
$this->rule = $rule;
|
||||
$this->journal = $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function getJournal()
|
||||
{
|
||||
return $this->journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
public function setJournal($journal)
|
||||
{
|
||||
$this->journal = $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Rule
|
||||
*/
|
||||
public function getRule()
|
||||
{
|
||||
return $this->rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return Processor
|
||||
*/
|
||||
public function setRule($rule)
|
||||
public static function make(Rule $rule)
|
||||
{
|
||||
$this->rule = $rule;
|
||||
$self = new self;
|
||||
$self->rule = $rule;
|
||||
$self->triggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
|
||||
$self->actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
public function handleTransactionJournal(TransactionJournal $journal)
|
||||
{
|
||||
$this->journal = $journal;
|
||||
// get all triggers:
|
||||
$triggered = $this->triggered();
|
||||
if ($triggered) {
|
||||
@ -87,30 +76,10 @@ class Processor
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current transaction is triggered by the current rule
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isTriggered()
|
||||
{
|
||||
return $this->triggered();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current transaction is triggered by the list of given triggers
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isTriggeredBy(array $triggers)
|
||||
{
|
||||
return $this->triggeredBy($triggers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function actions()
|
||||
private function actions()
|
||||
{
|
||||
/**
|
||||
* @var int $index
|
||||
@ -129,28 +98,18 @@ class Processor
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current transaction is triggered by the current rule
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function triggered()
|
||||
{
|
||||
return $this->triggeredBy($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check whether the current transaction would be triggered
|
||||
* by the given list of triggers
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function triggeredBy($triggers)
|
||||
private function triggered()
|
||||
{
|
||||
$foundTriggers = 0;
|
||||
$hitTriggers = 0;
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
foreach ($this->triggers as $trigger) {
|
||||
$foundTriggers++;
|
||||
|
||||
/** @var TriggerInterface $triggerClass */
|
||||
|
Loading…
Reference in New Issue
Block a user