Allow command to be forced.

This commit is contained in:
James Cole
2025-11-23 08:44:01 +01:00
parent 21a6892601
commit 5fea35d5b1

View File

@@ -42,7 +42,6 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use function Safe\json_encode;
use function Safe\mb_regex_encoding;
@@ -56,7 +55,7 @@ class ForcesDecimalSize extends Command
use ShowsFriendlyMessages;
protected $description = 'This command resizes DECIMAL columns in MySQL or PostgreSQL and correct amounts (only MySQL).';
protected $signature = 'firefly-iii:force-decimal-size';
protected $signature = 'firefly-iii:force-decimal-size {--force}';
private string $cast;
private array $classes
= [
@@ -98,9 +97,14 @@ class ForcesDecimalSize extends Command
Log::debug('Now in ForceDecimalSize::handle()');
$this->determineDatabaseType();
$force = $this->option('force');
$question = true;
if (false === $force) {
$this->friendlyError('Running this command is dangerous and can cause data loss.');
$this->friendlyError('Please do not continue.');
$this->friendlyError('Please make sure you have a backup.');
$question = $this->confirm('Do you want to continue?');
}
if (true === $question) {
$this->correctAmounts();
$this->updateDecimals();
@@ -236,8 +240,7 @@ class ForcesDecimalSize extends Command
/** @var Builder $query */
$query = Account::leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id')
->where('account_meta.data', json_encode((string) $currency->id))
;
->where('account_meta.data', json_encode((string)$currency->id));
$query->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void {
foreach ($fields as $field) {
$q->orWhere(
@@ -349,8 +352,7 @@ class ForcesDecimalSize extends Command
DB::raw(sprintf($regularExpression, $currency->decimal_places))
);
}
})
;
});
$result = $query->get(['piggy_bank_events.*']);
if (0 === $result->count()) {
@@ -405,8 +407,7 @@ class ForcesDecimalSize extends Command
DB::raw(sprintf($regularExpression, $currency->decimal_places))
);
}
})
;
});
$result = $query->get(['piggy_bank_repetitions.*']);
if (0 === $result->count()) {
@@ -459,8 +460,7 @@ class ForcesDecimalSize extends Command
DB::raw(sprintf($regularExpression, $currency->decimal_places))
);
}
})
;
});
$result = $query->get(['piggy_banks.*']);
if (0 === $result->count()) {