mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #2985
This commit is contained in:
parent
4b0e46af2b
commit
cd3f3fd781
@ -27,6 +27,8 @@ use DB;
|
|||||||
use FireflyIII\Factory\TagFactory;
|
use FireflyIII\Factory\TagFactory;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Models\Location;
|
use FireflyIII\Models\Location;
|
||||||
|
use FireflyIII\Models\RuleAction;
|
||||||
|
use FireflyIII\Models\RuleTrigger;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
@ -455,6 +457,7 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function update(Tag $tag, array $data): Tag
|
public function update(Tag $tag, array $data): Tag
|
||||||
{
|
{
|
||||||
|
$oldTag = $data['tag'];
|
||||||
$tag->tag = $data['tag'];
|
$tag->tag = $data['tag'];
|
||||||
$tag->date = $data['date'];
|
$tag->date = $data['date'];
|
||||||
$tag->description = $data['description'];
|
$tag->description = $data['description'];
|
||||||
@ -548,4 +551,46 @@ class TagRepository implements TagRepositoryInterface
|
|||||||
{
|
{
|
||||||
return $tag->attachments()->get();
|
return $tag->attachments()->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $oldName
|
||||||
|
* @param string $newName
|
||||||
|
*/
|
||||||
|
private function updateRuleActions(string $oldName, string $newName): void
|
||||||
|
{
|
||||||
|
$types = ['add_tag', 'remove_tag'];
|
||||||
|
$actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id')
|
||||||
|
->where('rules.user_id', $this->user->id)
|
||||||
|
->whereIn('rule_actions.action_type', $types)
|
||||||
|
->where('rule_actions.action_value', $oldName)
|
||||||
|
->get(['rule_actions.*']);
|
||||||
|
Log::debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||||
|
/** @var RuleAction $action */
|
||||||
|
foreach ($actions as $action) {
|
||||||
|
$action->action_value = $newName;
|
||||||
|
$action->save();
|
||||||
|
Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $oldName
|
||||||
|
* @param string $newName
|
||||||
|
*/
|
||||||
|
private function updateRuleTriggers(string $oldName, string $newName): void
|
||||||
|
{
|
||||||
|
$types = ['tag_is',];
|
||||||
|
$triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||||
|
->where('rules.user_id', $this->user->id)
|
||||||
|
->whereIn('rule_triggers.trigger_type', $types)
|
||||||
|
->where('rule_triggers.trigger_value', $oldName)
|
||||||
|
->get(['rule_triggers.*']);
|
||||||
|
Log::debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||||
|
/** @var RuleTrigger $trigger */
|
||||||
|
foreach ($triggers as $trigger) {
|
||||||
|
$trigger->trigger_value = $newName;
|
||||||
|
$trigger->save();
|
||||||
|
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,13 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Services\Internal\Update;
|
namespace FireflyIII\Services\Internal\Update;
|
||||||
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
|
use FireflyIII\Models\RuleAction;
|
||||||
|
use FireflyIII\Models\RuleTrigger;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CategoryUpdateService
|
* Class CategoryUpdateService
|
||||||
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class CategoryUpdateService
|
class CategoryUpdateService
|
||||||
@ -50,10 +53,57 @@ class CategoryUpdateService
|
|||||||
*/
|
*/
|
||||||
public function update(Category $category, array $data): Category
|
public function update(Category $category, array $data): Category
|
||||||
{
|
{
|
||||||
|
$oldName = $category->name;
|
||||||
$category->name = $data['name'];
|
$category->name = $data['name'];
|
||||||
$category->save();
|
$category->save();
|
||||||
|
|
||||||
|
// update triggers and actions
|
||||||
|
$this->updateRuleTriggers($oldName, $data['name']);
|
||||||
|
$this->updateRuleActions($oldName, $data['name']);
|
||||||
|
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $oldName
|
||||||
|
* @param string $newName
|
||||||
|
*/
|
||||||
|
private function updateRuleActions(string $oldName, string $newName): void
|
||||||
|
{
|
||||||
|
$types = ['set_category',];
|
||||||
|
$actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id')
|
||||||
|
->where('rules.user_id', $this->user->id)
|
||||||
|
->whereIn('rule_actions.action_type', $types)
|
||||||
|
->where('rule_actions.action_value', $oldName)
|
||||||
|
->get(['rule_actions.*']);
|
||||||
|
Log::debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||||
|
/** @var RuleAction $action */
|
||||||
|
foreach ($actions as $action) {
|
||||||
|
$action->action_value = $newName;
|
||||||
|
$action->save();
|
||||||
|
Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $oldName
|
||||||
|
* @param string $newName
|
||||||
|
*/
|
||||||
|
private function updateRuleTriggers(string $oldName, string $newName): void
|
||||||
|
{
|
||||||
|
$types = ['category_is',];
|
||||||
|
$triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id')
|
||||||
|
->where('rules.user_id', $this->user->id)
|
||||||
|
->whereIn('rule_triggers.trigger_type', $types)
|
||||||
|
->where('rule_triggers.trigger_value', $oldName)
|
||||||
|
->get(['rule_triggers.*']);
|
||||||
|
Log::debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||||
|
/** @var RuleTrigger $trigger */
|
||||||
|
foreach ($triggers as $trigger) {
|
||||||
|
$trigger->trigger_value = $newName;
|
||||||
|
$trigger->save();
|
||||||
|
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ trait ChartGeneration
|
|||||||
$cache->addProperty('chart.account.account-balance-chart');
|
$cache->addProperty('chart.account.account-balance-chart');
|
||||||
$cache->addProperty($accounts);
|
$cache->addProperty($accounts);
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
//return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
Log::debug('Regenerate chart.account.account-balance-chart from scratch.');
|
Log::debug('Regenerate chart.account.account-balance-chart from scratch.');
|
||||||
/** @var GeneratorInterface $generator */
|
/** @var GeneratorInterface $generator */
|
||||||
|
Loading…
Reference in New Issue
Block a user