mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 16:00:13 +00:00
Smarter (faster) way of updating timezone info.
This commit is contained in:
@@ -94,24 +94,21 @@ class AddTimezonesToDates extends Command
|
|||||||
{
|
{
|
||||||
$shortModel = str_replace('FireflyIII\Models\\', '', $model);
|
$shortModel = str_replace('FireflyIII\Models\\', '', $model);
|
||||||
$timezoneField = sprintf('%s_tz', $field);
|
$timezoneField = sprintf('%s_tz', $field);
|
||||||
$items = new Collection();
|
$count = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$items = $model::whereNull($timezoneField)->get();
|
$count = $model::whereNull($timezoneField)->count();
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
$this->friendlyError(sprintf('Cannot add timezone information to field "%s" of model "%s". Field does not exist.', $field, $shortModel));
|
$this->friendlyError(sprintf('Cannot add timezone information to field "%s" of model "%s". Field does not exist.', $field, $shortModel));
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
if (0 === $items->count()) {
|
if (0 === $count) {
|
||||||
$this->friendlyPositive(sprintf('Timezone information is present in field "%s" of model "%s".', $field, $shortModel));
|
$this->friendlyPositive(sprintf('Timezone information is present in field "%s" of model "%s".', $field, $shortModel));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->friendlyInfo(sprintf('Adding timezone information to field "%s" of model "%s".', $field, $shortModel));
|
$this->friendlyInfo(sprintf('Adding timezone information to field "%s" of model "%s".', $field, $shortModel));
|
||||||
|
|
||||||
foreach ($items as $item) {
|
$model::whereNull($timezoneField)->update([$timezoneField => config('app.timezone')]);
|
||||||
$item->{$timezoneField} = config('app.timezone');
|
|
||||||
$item->saveQuietly();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user