Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add housekeeping task to unmonitor multiple monitored editions
- Loading branch information
1 parent
765a2aa
commit e23d0bb
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/NzbDrone.Core/Housekeeping/Housekeepers/FixMultipleMonitoredEditions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
)"); | ||
} | ||
} | ||
} |