Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Temp fix for https://github.com/firefly-iii/firefly-iii/issues/6753
James Cole32e89155a03a
diff --git a/app/Http/Requests/RuleFormRequest.php b/app/Http/Requests/RuleFormRequest.phpindex 9ccdebb399..7f283807bc 100644--- a/app/Http/Requests/RuleFormRequest.php+++ b/app/Http/Requests/RuleFormRequest.php@@ -1,4 +1,5 @@<?php+/*** RuleFormRequest.php* Copyright (c) 2019 [email protected]@@ -66,17 +67,48 @@ class RuleFormRequest extends FormRequestif (is_array($triggerData)) {foreach ($triggerData as $trigger) {$stopProcessing = $trigger['stop_processing'] ?? '0';- $return[] = [+ $current = ['type' => $trigger['type'] ?? 'invalid','value' => $trigger['value'] ?? '',- 'stop_processing' => 1 === (int) $stopProcessing,+ 'stop_processing' => 1 === (int)$stopProcessing,];+ $current = self::replaceAmountTrigger($current);++ $return[] = $current;}}return $return;}+ /**+ * @param array $array+ * @return array+ */+ public static function replaceAmountTrigger(array $array): array+ {+ // do some sneaky search and replace.+ $amountFields = [+ 'amount_is',+ 'amount',+ 'amount_exactly',+ 'amount_less',+ 'amount_max',+ 'amount_more',+ 'amount_min',+ 'foreign_amount_is',+ 'foreign_amount',+ 'foreign_amount_less',+ 'foreign_amount_max',+ 'foreign_amount_more',+ 'foreign_amount_min',+ ];+ if (in_array($array['type'], $amountFields, true) && '0' === $array['value']) {+ $array['value'] = '0.00';+ }+ return $array;+ }+/*** @return array*/@@ -90,7 +122,7 @@ class RuleFormRequest extends FormRequest$return[] = ['type' => $action['type'] ?? 'invalid','value' => $action['value'] ?? '',- 'stop_processing' => 1 === (int) $stopProcessing,+ 'stop_processing' => 1 === (int)$stopProcessing,];}}@@ -121,9 +153,9 @@ class RuleFormRequest extends FormRequest'stop_processing' => 'boolean','rule_group_id' => 'required|belongsToUser:rule_groups','trigger' => 'required|in:store-journal,update-journal',- 'triggers.*.type' => 'required|in:' . implode(',', $validTriggers),+ 'triggers.*.type' => 'required|in:'.implode(',', $validTriggers),'triggers.*.value' => sprintf('required_if:triggers.*.type,%s|min:1|ruleTriggerValue', $contextTriggers),- 'actions.*.type' => 'required|in:' . implode(',', $validActions),+ 'actions.*.type' => 'required|in:'.implode(',', $validActions),'actions.*.value' => sprintf('required_if:actions.*.type,%s|min:0|max:255|ruleActionValue', $contextActions),'strict' => 'in:0,1',];@@ -132,7 +164,7 @@ class RuleFormRequest extends FormRequest$rule = $this->route()->parameter('rule');if (null !== $rule) {- $rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,' . $rule->id;+ $rules['title'] = 'required|between:1,100|uniqueObjectForUser:rules,title,'.$rule->id;}return $rules;diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.phpindex 13c5f972f7..da3d4b3d63 100644--- a/app/Support/Http/Controllers/RequestInformation.php+++ b/app/Support/Http/Controllers/RequestInformation.php@@ -27,6 +27,7 @@ use Carbon\Carbon;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Exceptions\ValidationException;use FireflyIII\Helpers\Help\HelpInterface;+use FireflyIII\Http\Requests\RuleFormRequest;use FireflyIII\Http\Requests\TestRuleFormRequest;use FireflyIII\Support\Binder\AccountList;use FireflyIII\User;@@ -60,7 +61,7 @@ trait RequestInformation/*** Get a list of triggers.*- * @param TestRuleFormRequest $request+ * @param TestRuleFormRequest $request** @return array*/@@ -70,14 +71,15 @@ trait RequestInformation$data = $request->get('triggers');if (is_array($data)) {foreach ($data as $triggerInfo) {- $triggers[] = [+ $current = ['type' => $triggerInfo['type'] ?? '','value' => $triggerInfo['value'] ?? '',- 'stop_processing' => 1 === (int) ($triggerInfo['stop_processing'] ?? '0'),+ 'stop_processing' => 1 === (int)($triggerInfo['stop_processing'] ?? '0'),];+ $current = RuleFormRequest::replaceAmountTrigger($current);+ $triggers[] = $current;}}-return $triggers;}@@ -127,13 +129,13 @@ trait RequestInformation*/final protected function getSpecificPageName(): string // get request info{- return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType');+ return null === RouteFacade::current()->parameter('objectType') ? '' : '_'.RouteFacade::current()->parameter('objectType');}/*** Check if date is outside session range.*- * @param Carbon $date+ * @param Carbon $date** @return bool*@@ -159,7 +161,7 @@ trait RequestInformation/*** Parses attributes from URL*- * @param array $attributes+ * @param array $attributes** @return array*/@@ -189,9 +191,9 @@ trait RequestInformation/*** Validate users new password.*- * @param User $user- * @param string $current- * @param string $new+ * @param User $user+ * @param string $current+ * @param string $new** @return bool*@@ -200,11 +202,11 @@ trait RequestInformationfinal protected function validatePassword(User $user, string $current, string $new): bool //get request info{if (!Hash::check($current, $user->password)) {- throw new ValidationException((string) trans('firefly.invalid_current_password'));+ throw new ValidationException((string)trans('firefly.invalid_current_password'));}if ($current === $new) {- throw new ValidationException((string) trans('firefly.should_change'));+ throw new ValidationException((string)trans('firefly.should_change'));}return true;@@ -213,7 +215,7 @@ trait RequestInformation/*** Get a validator for an incoming registration request.*- * @param array $data+ * @param array $data** @return ValidatorContract* @codeCoverageIgnore