mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 00:41:34 -06:00
Rules will now fire for a store-action. And fail.
This commit is contained in:
parent
98b272383f
commit
0dc74d9d14
@ -15,6 +15,7 @@ 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;
|
||||
|
||||
@ -48,7 +49,13 @@ 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')->hasTrigger('user_action','store-journal')->orderBy('order', 'ASC')->get();
|
||||
$groups = $user->ruleGroups()->with(
|
||||
[
|
||||
'rules' => function (HasMany $query) {
|
||||
$query->hasTrigger('user_action', 'store-journal');
|
||||
}
|
||||
]
|
||||
)->orderBy('order', 'ASC')->get();
|
||||
//
|
||||
/** @var RuleGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
@ -63,7 +70,7 @@ class FireRulesForStore
|
||||
}
|
||||
}
|
||||
Log::debug('FireRulesForStore!');
|
||||
echo 'handle';
|
||||
echo 'done handling rules.';
|
||||
exit;
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Crypt;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
@ -34,7 +34,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class Rule extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
@ -67,5 +66,23 @@ 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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class Processor
|
||||
$type = $trigger->trigger_type;
|
||||
$class = $this->triggerTypes[$type];
|
||||
if (!class_exists($class)) {
|
||||
throw new Exception('Could not instantiate class for rule trigger type "' . $type . '".');
|
||||
abort(500, 'Could not instantiate class for rule trigger type "' . $type . '" ('.$class.').');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user