mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 00:41:34 -06:00
77 lines
1.9 KiB
PHP
77 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* FireRulesForStore.php
|
|
* Copyright (C) 2016 Sander Dorigo
|
|
*
|
|
* This software may be modified and distributed under the terms
|
|
* of the MIT license. See the LICENSE file for details.
|
|
*/
|
|
|
|
namespace FireflyIII\Handlers\Events;
|
|
|
|
|
|
use FireflyIII\Events\TransactionJournalStored;
|
|
use FireflyIII\Models\Rule;
|
|
use FireflyIII\Models\RuleGroup;
|
|
use FireflyIII\Rules\TriggerProcessor;
|
|
use FireflyIII\User;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Log;
|
|
|
|
/**
|
|
* Class FireRulesForStore
|
|
*
|
|
* @package FireflyIII\Handlers\Events
|
|
*/
|
|
class FireRulesForStore
|
|
{
|
|
/**
|
|
* Create the event handler.
|
|
*
|
|
* @codeCoverageIgnore
|
|
*
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Connect a new transaction journal to any related piggy banks.
|
|
*
|
|
* @param TransactionJournalStored $event
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function handle(TransactionJournalStored $event)
|
|
{
|
|
// 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();
|
|
//
|
|
/** @var RuleGroup $group */
|
|
foreach ($groups as $group) {
|
|
$rules = $group->rules;
|
|
/** @var Rule $rule */
|
|
foreach ($rules as $rule) {
|
|
Log::debug('Now handling rule #' . $rule->id);
|
|
$processor = new TriggerProcessor($rule, $event->journal);
|
|
|
|
// get some return out of this?
|
|
$processor->handle();
|
|
|
|
}
|
|
}
|
|
Log::debug('FireRulesForStore!');
|
|
echo 'done handling rules.';
|
|
exit;
|
|
}
|
|
} |