Auto commit for release 'develop' on 2024-11-11

This commit is contained in:
github-actions
2024-11-11 04:10:58 +01:00
parent 22498b5804
commit 582671ca84
10 changed files with 148 additions and 141 deletions

View File

@@ -49,16 +49,16 @@ class AddTimezonesToDates extends Command
*
* @var string
*/
protected $signature = 'firefly-iii:add-timezones-to-dates';
protected $signature = 'firefly-iii:add-timezones-to-dates';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make sure all dates have a timezone.';
protected $description = 'Make sure all dates have a timezone.';
public static array $models = [
public static array $models = [
AccountBalance::class => ['date'], // done
AvailableBudget::class => ['start_date', 'end_date'], // done
Bill::class => ['date', 'end_date', 'extension_date'], // done

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/*
* ConvertDatesToUTC.php
* Copyright (c) 2024 james@firefly-iii.org.
@@ -31,12 +33,13 @@ use Illuminate\Support\Facades\Log;
class ConvertDatesToUTC extends Command
{
use ShowsFriendlyMessages;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:convert-dates-to-utc';
protected $signature = 'firefly-iii:convert-dates-to-utc';
/**
* The console command description.
@@ -69,12 +72,13 @@ class ConvertDatesToUTC extends Command
}
}
private function convertFieldtoUTC(string $model, string $field): void {
private function convertFieldtoUTC(string $model, string $field): void
{
$this->info(sprintf('Converting %s.%s to UTC', $model, $field));
$shortModel = str_replace('FireflyIII\Models\\', '', $model);
$timezoneField = sprintf('%s_tz', $field);
$items = new Collection();
$timeZone = config('app.timezone');
$items = new Collection();
$timeZone = config('app.timezone');
try {
$items = $model::where($timezoneField, $timeZone)->get();
@@ -89,12 +93,12 @@ class ConvertDatesToUTC extends Command
}
$this->friendlyInfo(sprintf('Converting field "%s" of model "%s" to UTC.', $field, $shortModel));
$items->each(
function ($item) use ($field, $timezoneField, $timeZone) {
function ($item) use ($field, $timezoneField): void {
/** @var Carbon $date */
$date = Carbon::parse($item->$field, $item->$timezoneField);
$date = Carbon::parse($item->{$field}, $item->{$timezoneField});
$date->setTimezone('UTC');
$item->$field = $date->format('Y-m-d H:i:s');
$item->$timezoneField = 'UTC';
$item->{$field} = $date->format('Y-m-d H:i:s');
$item->{$timezoneField} = 'UTC';
$item->save();
}
);