mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Merge branch 'develop' into 5.8-dev
# Conflicts: # app/Http/Requests/RuleFormRequest.php
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* RuleFormRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -69,19 +70,48 @@ class RuleFormRequest extends FormRequest
|
||||
foreach ($triggerData as $trigger) {
|
||||
$stopProcessing = $trigger['stop_processing'] ?? '0';
|
||||
$prohibited = $trigger['prohibited'] ?? '0';
|
||||
$set = [
|
||||
$set = [
|
||||
'type' => $trigger['type'] ?? 'invalid',
|
||||
'value' => $trigger['value'] ?? '',
|
||||
'stop_processing' => 1 === (int) $stopProcessing,
|
||||
'prohibited' => 1 === (int) $prohibited,
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
'prohibited' => 1 === (int)$prohibited,
|
||||
];
|
||||
$return[] = $set;
|
||||
$set = self::replaceAmountTrigger($set);
|
||||
$return[] = $set;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
@@ -95,7 +125,7 @@ class RuleFormRequest extends FormRequest
|
||||
$return[] = [
|
||||
'type' => $action['type'] ?? 'invalid',
|
||||
'value' => $action['value'] ?? '',
|
||||
'stop_processing' => 1 === (int) $stopProcessing,
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -126,9 +156,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',
|
||||
];
|
||||
@@ -137,7 +167,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;
|
||||
|
Reference in New Issue
Block a user