diff --git a/src/ImmichToSlideshow/Controllers/AssetsController.cs b/src/ImmichToSlideshow/Controllers/AssetsController.cs index 568a977..55fd4d0 100644 --- a/src/ImmichToSlideshow/Controllers/AssetsController.cs +++ b/src/ImmichToSlideshow/Controllers/AssetsController.cs @@ -47,4 +47,8 @@ public class AssetsController(AssetService assetService) : ControllerBase { public IActionResult SetDigiKam4ArchiveImmich(Guid ownerId) => Ok(_AssetService.SetDigiKam4ArchiveImmich(ownerId)); + [HttpGet("update-assets-set-local-date-time-for-three-and-seven")] + public IActionResult UpdateAssetsSetLocalDateTimeForThreeAndSeven() => + Ok(_AssetService.UpdateAssetsSetLocalDateTimeForThreeAndSeven()); + } \ No newline at end of file diff --git a/src/ImmichToSlideshow/Services/AssetService.cs b/src/ImmichToSlideshow/Services/AssetService.cs index ec9a162..9cd047e 100644 --- a/src/ImmichToSlideshow/Services/AssetService.cs +++ b/src/ImmichToSlideshow/Services/AssetService.cs @@ -242,4 +242,13 @@ public class AssetService(ILogger logger, AppSettings appSettings) { return results?.AsReadOnly(); } + public ReadOnlyCollection? UpdateAssetsSetLocalDateTimeForThreeAndSeven() { + ReadOnlyCollection? results; + NpgsqlParameter[] npgsqlParameters = []; + string commandText = CommandText.UpdateAssetsSetLocalDateTimeForThreeAndSeven(_Settings.LowestVersionHistory); + int? result = ExecuteNonQuery(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly()); + results = result is null ? null : new([result.Value]); + return results?.AsReadOnly(); + } + } \ No newline at end of file diff --git a/src/ImmichToSlideshow/Services/CommandText.cs b/src/ImmichToSlideshow/Services/CommandText.cs index 485255b..af84293 100644 --- a/src/ImmichToSlideshow/Services/CommandText.cs +++ b/src/ImmichToSlideshow/Services/CommandText.cs @@ -174,4 +174,22 @@ internal static class CommandText { return string.Join(Environment.NewLine, results); } // cSpell:enable + internal static string UpdateAssetsSetLocalDateTimeForThreeAndSeven(float lowestVersionHistory) { // cSpell:disable + List results = []; + if (lowestVersionHistory <= 1.129) { + results.Add(" UPDATE assets "); + } else { + results.Add(" UPDATE public.asset "); + } + results.AddRange([ + " SET \"localDateTime\" = TIMESTAMPTZ(\"localDateTime\") - INTERVAL '100 years' ", + " WHERE \"localDateTime\" > TIMESTAMPTZ '1990-01-01 00:00:00-00' ", + " AND ( ", + " \"deviceAssetId\" like '%3.%' ", + " OR \"deviceAssetId\" like '%7.%' ", + " ); ", + ]); + return string.Join(Environment.NewLine, results); + } // cSpell:enable + } \ No newline at end of file