From 4ebb6de52079cdf2d6fa7d3a7064c6e89ab888c3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 19 May 2020 11:18:58 +0200 Subject: [PATCH] Reset rule order on index. #3376 --- app/Http/Controllers/Rule/IndexController.php | 1 + app/Repositories/RuleGroup/RuleGroupRepository.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Rule/IndexController.php b/app/Http/Controllers/Rule/IndexController.php index 0233337bc4..0ed7cfa29c 100644 --- a/app/Http/Controllers/Rule/IndexController.php +++ b/app/Http/Controllers/Rule/IndexController.php @@ -91,6 +91,7 @@ class IndexController extends Controller $user = auth()->user(); $this->createDefaultRuleGroup(); $this->createDefaultRule(); + $this->ruleGroupRepos->resetRuleGroupOrder(); $ruleGroups = $this->ruleGroupRepos->getRuleGroupsWithRules($user); return view('rules.index', compact('ruleGroups')); diff --git a/app/Repositories/RuleGroup/RuleGroupRepository.php b/app/Repositories/RuleGroup/RuleGroupRepository.php index 70da98cd32..a7bca56d6c 100644 --- a/app/Repositories/RuleGroup/RuleGroupRepository.php +++ b/app/Repositories/RuleGroup/RuleGroupRepository.php @@ -56,7 +56,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * @param RuleGroup|null $moveTo * * @return bool @@ -98,6 +98,10 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface foreach ($set as $entry) { $entry->order = $count; $entry->save(); + + // also update rules in group. + $this->resetRulesInGroupOrder($entry); + ++$count; } @@ -114,6 +118,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface $ruleGroup->rules()->whereNotNull('deleted_at')->update(['order' => 0]); $set = $ruleGroup->rules() + ->orderBy('active','DESC') ->orderBy('order', 'ASC') ->orderBy('updated_at', 'DESC') ->get(); @@ -328,7 +333,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface /** * @param RuleGroup $ruleGroup - * @param array $data + * @param array $data * * @return RuleGroup */ @@ -353,4 +358,5 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface { return $this->user->ruleGroups()->where('title', $title)->first(); } -} + +} \ No newline at end of file