mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This commit is contained in:
parent
e3ecfdfac6
commit
55a6cc5cd4
@ -43,6 +43,15 @@ class TransactionCurrencyFactory
|
||||
*/
|
||||
public function create(array $data): TransactionCurrency
|
||||
{
|
||||
// if the code already exists (deleted)
|
||||
// force delete it and then create the transaction:
|
||||
$count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count();
|
||||
if(1 === $count) {
|
||||
$old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first();
|
||||
$old->forceDelete();
|
||||
Log::warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code']));
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var TransactionCurrency $result */
|
||||
$result = TransactionCurrency::create(
|
||||
|
@ -59,9 +59,9 @@ class CurrencyFormRequest extends FormRequest
|
||||
{
|
||||
// fixed
|
||||
$rules = [
|
||||
'name' => 'required|max:48|min:1|unique:transaction_currencies,name',
|
||||
'code' => 'required|min:3|max:51|unique:transaction_currencies,code',
|
||||
'symbol' => 'required|min:1|max:51|unique:transaction_currencies,symbol',
|
||||
'name' => 'required|max:48|min:1|uniqueCurrencyName',
|
||||
'code' => 'required|min:3|max:51|uniqueCurrencyCode',
|
||||
'symbol' => 'required|min:1|max:51|uniqueCurrencySymbol',
|
||||
'decimal_places' => 'required|min:0|max:12|numeric',
|
||||
'enabled' => 'in:0,1',
|
||||
];
|
||||
|
@ -53,6 +53,48 @@ use function is_string;
|
||||
*/
|
||||
class FireflyValidator extends Validator
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencyName($attribute, $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencyCode($attribute, $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencySymbol($attribute, $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
|
||||
{
|
||||
return 0 === DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
|
Loading…
Reference in New Issue
Block a user