diff --git a/app/Http/Controllers/Gallery/PhotoController.php b/app/Http/Controllers/Gallery/PhotoController.php index f550178a1ff..88b14cd7da4 100644 --- a/app/Http/Controllers/Gallery/PhotoController.php +++ b/app/Http/Controllers/Gallery/PhotoController.php @@ -141,13 +141,21 @@ public function update(EditPhotoRequest $request): PhotoResource $photo->tags = $request->tags(); $photo->license = $request->license()->value; - if ($request->takenAt() !== null) { - // update if required - $photo->taken_at_mod = $request->takenAt(); - } elseif ($photo->taken_at_mod !== null) { - // reset if set to null + // We only use taken_at_mod to store the original date when the user changes the date. + // If the user changes the date again, we do not update taken_at_mod. + if ($request->takenAt() !== null && $photo->taken_at_mod === null) { + // First time saving: we preserve the original date in taken_at_mod. + $photo->taken_at_mod = $photo->taken_at; + $photo->taken_at = $request->takenAt(); + } elseif ($request->takenAt() !== null && $photo->taken_at_mod !== null) { + // We already have a taken_at_mod, we only update the taken_at. + $photo->taken_at = $request->takenAt(); + } elseif ($request->takenAt() === null && $photo->taken_at_mod !== null) { + // we reset + $photo->taken_at = $photo->taken_at_mod; $photo->taken_at_mod = null; } + $photo->save(); return PhotoResource::fromModel($photo); diff --git a/app/Http/Resources/Models/PhotoResource.php b/app/Http/Resources/Models/PhotoResource.php index dc27fa83699..01520bf45d5 100644 --- a/app/Http/Resources/Models/PhotoResource.php +++ b/app/Http/Resources/Models/PhotoResource.php @@ -88,7 +88,7 @@ public function __construct(Photo $photo) $this->shutter = $photo->shutter; $this->size_variants = new SizeVariantsResouce($photo); $this->tags = $photo->tags; - $this->taken_at = ($photo->taken_at_mod ?? $photo->taken_at)?->toIso8601String(); + $this->taken_at = $photo->taken_at?->toIso8601String(); $this->taken_at_orig_tz = $photo->taken_at_orig_tz; $this->title = $photo->title; $this->type = $photo->type;