mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Grab rules properly.
This commit is contained in:
parent
46ee2a0568
commit
cf4d7cfeef
@ -15,7 +15,6 @@ use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Rules\Processor;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Log;
|
||||
|
||||
@ -49,17 +48,15 @@ class FireRulesForStore
|
||||
// get all the user's rule groups, with the rules, order by 'order'.
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$groups = $user->ruleGroups()->with(
|
||||
[
|
||||
'rules' => function (HasMany $query) {
|
||||
$query->hasTrigger('user_action', 'store-journal');
|
||||
}
|
||||
]
|
||||
)->orderBy('order', 'ASC')->get();
|
||||
$groups = $user->ruleGroups()->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
$rules = $group->rules;
|
||||
$rules = $group->rules()
|
||||
->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||
->where('rule_triggers.trigger_type', 'user_action')
|
||||
->where('rule_triggers.trigger_value', 'store-journal')
|
||||
->get(['rules.*']);
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
Log::debug('Now handling rule #' . $rule->id);
|
||||
|
@ -66,23 +66,4 @@ class Rule extends Model
|
||||
return $this->hasMany('FireflyIII\Models\RuleTrigger');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
* @param $triggerType
|
||||
* @param null $triggerValue
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeHasTrigger(Builder $query, $triggerType, $triggerValue = null)
|
||||
{
|
||||
$query->leftJoin('rule_triggers', 'rules.id', '=', 'rule_triggers.rule_id');
|
||||
$query->where('rule_triggers.trigger_type', $triggerType);
|
||||
if (!is_null($triggerValue)) {
|
||||
$query->where('rule_triggers.trigger_value', $triggerValue);
|
||||
}
|
||||
return $query;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user