From e23d0bbfa1479ed21c55c5e8b97e7de74e798691 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 6 Sep 2023 06:57:27 +0300 Subject: [PATCH] Add housekeeping task to unmonitor multiple monitored editions --- .../FixMultipleMonitoredEditions.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/NzbDrone.Core/Housekeeping/Housekeepers/FixMultipleMonitoredEditions.cs diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/FixMultipleMonitoredEditions.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/FixMultipleMonitoredEditions.cs new file mode 100644 index 000000000..c613b5dd7 --- /dev/null +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/FixMultipleMonitoredEditions.cs @@ -0,0 +1,30 @@ +using Dapper; +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Core.Housekeeping.Housekeepers +{ + public class FixMultipleMonitoredEditions : IHousekeepingTask + { + private readonly IMainDatabase _database; + + public FixMultipleMonitoredEditions(IMainDatabase database) + { + _database = database; + } + + public void Clean() + { + using var mapper = _database.OpenConnection(); + + mapper.Execute(@"UPDATE ""Editions"" + SET ""Monitored"" = 0 + WHERE ""Id"" IN ( + SELECT MIN(""Id"") + FROM ""Editions"" + WHERE ""Monitored"" = 1 + GROUP BY ""BookId"" + HAVING COUNT(""BookId"") > 1 + )"); + } + } +}