mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 14:41:20 +00:00
Fix #2510
This commit is contained in:
@@ -74,7 +74,7 @@ class TransactionStoreRequest extends Request
|
||||
{
|
||||
$rules = [
|
||||
// basic fields for group:
|
||||
'group_title' => 'between:1,255',
|
||||
'group_title' => 'between:1,1000',
|
||||
|
||||
// transaction rules (in array for splits):
|
||||
'transactions.*.type' => 'required|in:withdrawal,deposit,transfer,opening-balance,reconciliation',
|
||||
@@ -92,7 +92,7 @@ class TransactionStoreRequest extends Request
|
||||
'transactions.*.foreign_amount' => 'numeric|more:0',
|
||||
|
||||
// description
|
||||
'transactions.*.description' => 'nullable|between:1,255',
|
||||
'transactions.*.description' => 'nullable|between:1,1000',
|
||||
|
||||
// source of transaction
|
||||
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
|
||||
@@ -149,7 +149,7 @@ class TransactionUpdateRequest extends Request
|
||||
{
|
||||
$rules = [
|
||||
// basic fields for group:
|
||||
'group_title' => 'between:1,255',
|
||||
'group_title' => 'between:1,1000',
|
||||
|
||||
// transaction rules (in array for splits):
|
||||
'transactions.*.type' => 'in:withdrawal,deposit,transfer,opening-balance,reconciliation',
|
||||
@@ -163,11 +163,11 @@ class TransactionUpdateRequest extends Request
|
||||
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
||||
|
||||
// amount
|
||||
'transactions.*.amount' => 'numeric|more:0',
|
||||
'transactions.*.amount' => 'numeric|more:0|max:100000000000',
|
||||
'transactions.*.foreign_amount' => 'numeric|gte:0',
|
||||
|
||||
// description
|
||||
'transactions.*.description' => 'nullable|between:1,255',
|
||||
'transactions.*.description' => 'nullable|between:1,1000',
|
||||
|
||||
// source of transaction
|
||||
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
|
||||
@@ -70,7 +70,8 @@ class CorrectDatabase extends Command
|
||||
'firefly-iii:delete-empty-groups',
|
||||
'firefly-iii:fix-account-types',
|
||||
'firefly-iii:rename-meta-fields',
|
||||
'firefly-iii:fix-ob-currencies'
|
||||
'firefly-iii:fix-ob-currencies',
|
||||
'firefly-iii:fix-long-descriptions'
|
||||
];
|
||||
foreach ($commands as $command) {
|
||||
$this->line(sprintf('Now executing %s', $command));
|
||||
|
||||
76
app/Console/Commands/Correction/FixLongDescriptions.php
Normal file
76
app/Console/Commands/Correction/FixLongDescriptions.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* FixLongDescriptions.php
|
||||
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Console\Commands\Correction;
|
||||
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Class FixLongDescriptions
|
||||
*/
|
||||
class FixLongDescriptions extends Command
|
||||
{
|
||||
private const MAX_LENGTH = 1000;
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fixes long descriptions in journals and groups.';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:fix-long-descriptions';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$journals = TransactionJournal::get(['id', 'description']);
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if (strlen($journal->description) > self::MAX_LENGTH) {
|
||||
$journal->description = substr($journal->description, 0, self::MAX_LENGTH);
|
||||
$journal->save();
|
||||
$this->line(sprintf('Truncated description of transaction journal #%d', $journal->id));
|
||||
}
|
||||
}
|
||||
|
||||
$groups = TransactionGroup::get(['id', 'title']);
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
if (strlen($group->title) > self::MAX_LENGTH) {
|
||||
$group->title = substr($group->title, 0, self::MAX_LENGTH);
|
||||
$group->save();
|
||||
$this->line(sprintf('Truncated description of transaction group #%d', $group->id));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ class UpgradeDatabase extends Command
|
||||
'firefly-iii:rename-account-meta',
|
||||
'firefly-iii:migrate-recurrence-meta',
|
||||
|
||||
// there are 14 verify commands.
|
||||
// there are 15 verify commands.
|
||||
'firefly-iii:fix-piggies',
|
||||
'firefly-iii:create-link-types',
|
||||
'firefly-iii:create-access-tokens',
|
||||
@@ -88,6 +88,7 @@ class UpgradeDatabase extends Command
|
||||
'firefly-iii:fix-account-types',
|
||||
'firefly-iii:rename-meta-fields',
|
||||
'firefly-iii:fix-ob-currencies',
|
||||
'firefly-iii:fix-long-descriptions',
|
||||
|
||||
// two report commands
|
||||
'firefly-iii:report-empty-objects',
|
||||
|
||||
@@ -61,7 +61,7 @@ class TransactionGroupFactory
|
||||
$title = '' === $title ? null : $title;
|
||||
|
||||
if (null !== $title) {
|
||||
$title = substr($title, 0, 255);
|
||||
$title = substr($title, 0, 1000);
|
||||
}
|
||||
|
||||
$group = new TransactionGroup;
|
||||
|
||||
@@ -287,7 +287,7 @@ class TransactionJournalFactory
|
||||
'transaction_type_id' => $type->id,
|
||||
'bill_id' => $billId,
|
||||
'transaction_currency_id' => $currency->id,
|
||||
'description' => $description,
|
||||
'description' => substr($description,0,1000),
|
||||
'date' => $carbon->format('Y-m-d H:i:s'),
|
||||
'order' => $order,
|
||||
'tag_count' => 0,
|
||||
|
||||
@@ -85,7 +85,7 @@ class InstallController extends Controller
|
||||
'firefly-iii:rename-account-meta' => [],
|
||||
'firefly-iii:migrate-recurrence-meta' => [],
|
||||
|
||||
// there are 14 verify commands.
|
||||
// there are 15 verify commands.
|
||||
'firefly-iii:fix-piggies' => [],
|
||||
'firefly-iii:create-link-types' => [],
|
||||
'firefly-iii:create-access-tokens' => [],
|
||||
@@ -100,6 +100,7 @@ class InstallController extends Controller
|
||||
'firefly-iii:fix-account-types' => [],
|
||||
'firefly-iii:rename-meta-fields' => [],
|
||||
'firefly-iii:fix-ob-currencies' => [],
|
||||
'firefly-iii:fix-long-descriptions' => [],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user