mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
PHPStorm can order methods by alphabet, who knew.
This commit is contained in:
@@ -83,85 +83,6 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
return $collection->unique();
|
||||
}
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->operators = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function fire(): void
|
||||
{
|
||||
$this->resultCount = [];
|
||||
app('log')->debug('SearchRuleEngine::fire()!');
|
||||
|
||||
// if rules and no rule groups, file each rule separately.
|
||||
if (0 !== $this->rules->count()) {
|
||||
app('log')->debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($this->rules as $rule) {
|
||||
$result = $this->fireRule($rule);
|
||||
if (true === $result && $rule->stop_processing) {
|
||||
app('log')->debug(sprintf('Rule #%d has triggered and executed, but calls to stop processing. Since not in the context of a group, do not stop.', $rule->id));
|
||||
}
|
||||
if (false === $result && $rule->stop_processing) {
|
||||
app('log')->debug(sprintf('Rule #%d has triggered and changed nothing, but calls to stop processing. Do not stop.', $rule->id));
|
||||
}
|
||||
}
|
||||
app('log')->debug('SearchRuleEngine:: done processing all rules!');
|
||||
|
||||
return;
|
||||
}
|
||||
if (0 !== $this->groups->count()) {
|
||||
app('log')->debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
|
||||
|
||||
// fire each group:
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($this->groups as $group) {
|
||||
$this->fireGroup($group);
|
||||
}
|
||||
}
|
||||
app('log')->debug('SearchRuleEngine:: done processing all rules!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of changed transactions from the previous "fire" action.
|
||||
*/
|
||||
public function getResults(): int
|
||||
{
|
||||
return count($this->resultCount);
|
||||
}
|
||||
|
||||
public function setRefreshTriggers(bool $refreshTriggers): void
|
||||
{
|
||||
$this->refreshTriggers = $refreshTriggers;
|
||||
}
|
||||
|
||||
public function setRuleGroups(Collection $ruleGroups): void
|
||||
{
|
||||
app('log')->debug(__METHOD__);
|
||||
foreach ($ruleGroups as $group) {
|
||||
if ($group instanceof RuleGroup) {
|
||||
app('log')->debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
|
||||
$this->groups->push($group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setRules(Collection $rules): void
|
||||
{
|
||||
app('log')->debug(__METHOD__);
|
||||
foreach ($rules as $rule) {
|
||||
if ($rule instanceof Rule) {
|
||||
app('log')->debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
|
||||
$this->rules->push($rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the transactions a strict rule will execute on.
|
||||
*/
|
||||
@@ -184,7 +105,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
// if the trigger needs no context, value is different:
|
||||
$needsContext = (bool) (config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type)) ?? true);
|
||||
$needsContext = (bool)(config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type)) ?? true);
|
||||
if (false === $needsContext) {
|
||||
app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger (no context): %s:true', $ruleTrigger->trigger_type));
|
||||
$searchArray[$ruleTrigger->trigger_type][] = 'true';
|
||||
@@ -257,7 +178,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$journalId = 0;
|
||||
foreach ($array as $triggerName => $values) {
|
||||
if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) {
|
||||
$journalId = (int) trim($values[0] ?? '"0"', '"'); // follows format "123".
|
||||
$journalId = (int)trim($values[0] ?? '"0"', '"'); // follows format "123".
|
||||
app('log')->debug(sprintf('Found journal ID #%d', $journalId));
|
||||
}
|
||||
}
|
||||
@@ -277,6 +198,12 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
return today(config('app.timezone'));
|
||||
}
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->operators = [];
|
||||
}
|
||||
|
||||
private function findNonStrictRule(Rule $rule): Collection
|
||||
{
|
||||
app('log')->debug(sprintf('findNonStrictRule(#%d)', $rule->id));
|
||||
@@ -368,6 +295,44 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
return $unique;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function fire(): void
|
||||
{
|
||||
$this->resultCount = [];
|
||||
app('log')->debug('SearchRuleEngine::fire()!');
|
||||
|
||||
// if rules and no rule groups, file each rule separately.
|
||||
if (0 !== $this->rules->count()) {
|
||||
app('log')->debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($this->rules as $rule) {
|
||||
$result = $this->fireRule($rule);
|
||||
if (true === $result && $rule->stop_processing) {
|
||||
app('log')->debug(sprintf('Rule #%d has triggered and executed, but calls to stop processing. Since not in the context of a group, do not stop.', $rule->id));
|
||||
}
|
||||
if (false === $result && $rule->stop_processing) {
|
||||
app('log')->debug(sprintf('Rule #%d has triggered and changed nothing, but calls to stop processing. Do not stop.', $rule->id));
|
||||
}
|
||||
}
|
||||
app('log')->debug('SearchRuleEngine:: done processing all rules!');
|
||||
|
||||
return;
|
||||
}
|
||||
if (0 !== $this->groups->count()) {
|
||||
app('log')->debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
|
||||
|
||||
// fire each group:
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($this->groups as $group) {
|
||||
$this->fireGroup($group);
|
||||
}
|
||||
}
|
||||
app('log')->debug('SearchRuleEngine:: done processing all rules!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the rule has been triggered.
|
||||
*
|
||||
@@ -532,4 +497,39 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of changed transactions from the previous "fire" action.
|
||||
*/
|
||||
public function getResults(): int
|
||||
{
|
||||
return count($this->resultCount);
|
||||
}
|
||||
|
||||
public function setRefreshTriggers(bool $refreshTriggers): void
|
||||
{
|
||||
$this->refreshTriggers = $refreshTriggers;
|
||||
}
|
||||
|
||||
public function setRuleGroups(Collection $ruleGroups): void
|
||||
{
|
||||
app('log')->debug(__METHOD__);
|
||||
foreach ($ruleGroups as $group) {
|
||||
if ($group instanceof RuleGroup) {
|
||||
app('log')->debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
|
||||
$this->groups->push($group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setRules(Collection $rules): void
|
||||
{
|
||||
app('log')->debug(__METHOD__);
|
||||
foreach ($rules as $rule) {
|
||||
if ($rule instanceof Rule) {
|
||||
app('log')->debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
|
||||
$this->rules->push($rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user