1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Hopefully fix all issues with unlinked movie files.

This commit is contained in:
Leonardo Galli 2017-03-10 19:47:48 +01:00
parent db6e91cd95
commit 0db27d9029
4 changed files with 35 additions and 8 deletions

View File

@ -2,11 +2,11 @@
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupAdditionalUsers : IHousekeepingTask
public class FixWronglyMatchedMovieFiles : IHousekeepingTask
{
private readonly IMainDatabase _database;
public CleanupAdditionalUsers(IMainDatabase database)
public FixWronglyMatchedMovieFiles(IMainDatabase database)
{
_database = database;
}
@ -15,10 +15,11 @@ public void Clean()
{
var mapper = _database.GetDataMapper();
mapper.ExecuteNonQuery(@"DELETE FROM Users
WHERE ID NOT IN (
SELECT ID FROM Users
LIMIT 1)");
mapper.ExecuteNonQuery(@"UPDATE Movies
SET MovieFileId =
(Select Id FROM MovieFiles WHERE Movies.Id == MovieFiles.MovieId)
WHERE MovieFileId !=
(SELECT Id FROM MovieFiles WHERE Movies.Id == MovieFiles.MovieId)");
}
}
}

View File

@ -0,0 +1,25 @@
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class FixWronglyMatchedMovieFiles : IHousekeepingTask
{
private readonly IMainDatabase _database;
public FixWronglyMatchedMovieFiles(IMainDatabase database)
{
_database = database;
}
public void Clean()
{
var mapper = _database.GetDataMapper();
mapper.ExecuteNonQuery(@"UPDATE Movies
SET MovieFileId =
(Select Id FROM MovieFiles WHERE Movies.Id == MovieFiles.MovieId)
WHERE MovieFileId !=
(SELECT Id FROM MovieFiles WHERE Movies.Id == MovieFiles.MovieId)");
}
}
}

View File

@ -1259,6 +1259,7 @@
<Compile Include="Validation\RuleBuilderExtensions.cs" />
<Compile Include="Validation\UrlValidator.cs" />
<Compile Include="Datastore\Migration\131_make_parsed_episode_info_nullable.cs" />
<Compile Include="Housekeeping\Housekeepers\FixWronglyMatchedMovieFiles.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View File

@ -331,13 +331,13 @@ public void RemoveAddOptions(Movie movie)
public void Handle(MovieFileAddedEvent message)
{
_movieRepository.SetFileId(message.MovieFile.Id, message.MovieFile.Movie.Value.Id);
_logger.Debug("Linking [{0}] > [{1}]", message.MovieFile.RelativePath, message.MovieFile.Movie.Value);
_logger.Info("Linking [{0}] > [{1}]", message.MovieFile.RelativePath, message.MovieFile.Movie.Value);
}
public void SetFileId(Movie movie, MovieFile movieFile)
{
_movieRepository.SetFileId(movieFile.Id, movie.Id);
_logger.Debug("Linking [{0}] > [{1}]", movieFile.RelativePath, movie);
_logger.Info("Linking [{0}] > [{1}]", movieFile.RelativePath, movie);
}
public void Handle(MovieFileDeletedEvent message)