diff --git a/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs b/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs index 65750a64b..625407f3c 100644 --- a/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs +++ b/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs @@ -7,12 +7,12 @@ namespace Ombi.Core.Rule.Rules.Request { public class SonarrCacheRequestRule : BaseRequestRule, IRules { - public SonarrCacheRequestRule(IOmbiContext ctx) + public SonarrCacheRequestRule(IExternalContext ctx) { _ctx = ctx; } - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; public Task Execute(BaseRequest obj) { diff --git a/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs b/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs index f9c5cd09d..03bdbe091 100644 --- a/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs @@ -34,12 +34,12 @@ namespace Ombi.Core.Rule.Rules.Search { public class SonarrCacheSearchRule : BaseSearchRule, IRules { - public SonarrCacheSearchRule(IOmbiContext ctx) + public SonarrCacheSearchRule(IExternalContext ctx) { _ctx = ctx; } - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; public Task Execute(SearchViewModel obj) { diff --git a/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs b/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs index c851afb4b..7eac05d56 100644 --- a/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs +++ b/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs @@ -10,12 +10,12 @@ namespace Ombi.Core.Rule.Rules { public class SonarrCacheRule { - public SonarrCacheRule(IOmbiContext ctx) + public SonarrCacheRule(IExternalContext ctx) { _ctx = ctx; } - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; public async Task Execute(BaseRequest obj) { diff --git a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs index 8606de371..5e9f13534 100644 --- a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs +++ b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs @@ -42,7 +42,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato public class CouchPotatoSync : ICouchPotatoSync { public CouchPotatoSync(ISettingsService cpSettings, - ICouchPotatoApi api, ILogger log, IOmbiContext ctx) + ICouchPotatoApi api, ILogger log, IExternalContext ctx) { _settings = cpSettings; _api = api; @@ -54,7 +54,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato private readonly ISettingsService _settings; private readonly ICouchPotatoApi _api; private readonly ILogger _log; - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; public async Task Start() { diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs index 2e32b6478..d19fe561a 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs @@ -20,7 +20,7 @@ namespace Ombi.Schedule.Jobs.Lidarr { public class LidarrAlbumSync : ILidarrAlbumSync { - public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IOmbiContext ctx, + public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IExternalContext ctx, IBackgroundJobClient job, ILidarrAvailabilityChecker availability) { _lidarrSettings = lidarr; @@ -35,7 +35,7 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly ISettingsService _lidarrSettings; private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; private readonly IBackgroundJobClient _job; private readonly ILidarrAvailabilityChecker _availability; diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs index ac6264e3d..4117ee44a 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs @@ -20,7 +20,7 @@ namespace Ombi.Schedule.Jobs.Lidarr { public class LidarrArtistSync : ILidarrArtistSync { - public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IOmbiContext ctx, + public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IExternalContext ctx, IBackgroundJobClient background, ILidarrAlbumSync album) { _lidarrSettings = lidarr; @@ -35,7 +35,7 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly ISettingsService _lidarrSettings; private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; private readonly IBackgroundJobClient _job; private readonly ILidarrAlbumSync _albumSync; diff --git a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs index 0aea8cdc2..5c954def8 100644 --- a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs @@ -16,7 +16,7 @@ namespace Ombi.Schedule.Jobs.Radarr { public class RadarrSync : IRadarrSync { - public RadarrSync(ISettingsService radarr, IRadarrApi radarrApi, ILogger log, IOmbiContext ctx) + public RadarrSync(ISettingsService radarr, IRadarrApi radarrApi, ILogger log, IExternalContext ctx) { RadarrSettings = radarr; RadarrApi = radarrApi; @@ -28,7 +28,7 @@ namespace Ombi.Schedule.Jobs.Radarr private ISettingsService RadarrSettings { get; } private IRadarrApi RadarrApi { get; } private ILogger Logger { get; } - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; private static readonly SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1, 1); diff --git a/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs b/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs index d2330197d..92e0c2d55 100644 --- a/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs +++ b/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; @@ -17,7 +16,7 @@ namespace Ombi.Schedule.Jobs.SickRage { public class SickRageSync : ISickRageSync { - public SickRageSync(ISettingsService s, ISickRageApi api, ILogger l, IOmbiContext ctx) + public SickRageSync(ISettingsService s, ISickRageApi api, ILogger l, IExternalContext ctx) { _settings = s; _api = api; @@ -29,7 +28,7 @@ namespace Ombi.Schedule.Jobs.SickRage private readonly ISettingsService _settings; private readonly ISickRageApi _api; private readonly ILogger _log; - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; public async Task Start() { diff --git a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs index ec5502581..e4c00c726 100644 --- a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs @@ -19,7 +19,7 @@ namespace Ombi.Schedule.Jobs.Sonarr { public class SonarrSync : ISonarrSync { - public SonarrSync(ISettingsService s, ISonarrApi api, ILogger l, IOmbiContext ctx) + public SonarrSync(ISettingsService s, ISonarrApi api, ILogger l, IExternalContext ctx) { _settings = s; _api = api; @@ -31,7 +31,7 @@ namespace Ombi.Schedule.Jobs.Sonarr private readonly ISettingsService _settings; private readonly ISonarrApi _api; private readonly ILogger _log; - private readonly IOmbiContext _ctx; + private readonly IExternalContext _ctx; public async Task Start() { diff --git a/src/Ombi.Store/Context/IOmbiContext.cs b/src/Ombi.Store/Context/IOmbiContext.cs index f21a3f0db..e34e1d648 100644 --- a/src/Ombi.Store/Context/IOmbiContext.cs +++ b/src/Ombi.Store/Context/IOmbiContext.cs @@ -12,12 +12,12 @@ namespace Ombi.Store.Context public interface IOmbiContext : IDbContext { - DbSet PlexServerContent { get; set; } - DbSet PlexEpisode { get; set; } + //DbSet PlexServerContent { get; set; } + //DbSet PlexEpisode { get; set; } DbSet Settings { get; set; } - DbSet RadarrCache { get; set; } - DbSet EmbyContent { get; set; } - DbSet EmbyEpisode { get; set; } + //DbSet RadarrCache { get; set; } + //DbSet EmbyContent { get; set; } + //DbSet EmbyEpisode { get; set; } DbSet NotificationTemplates { get; set; } DbSet ApplicationConfigurations { get; set; } DbSet Audit { get; set; } @@ -29,12 +29,12 @@ namespace Ombi.Store.Context DbSet IssueCategories { get; set; } DbSet Tokens { get; set; } DbSet SonarrCache { get; set; } - DbSet SonarrEpisodeCache { get; set; } - DbSet CouchPotatoCache { get; set; } - DbSet SickRageCache { get; set; } - DbSet LidarrArtistCache { get; set; } - DbSet LidarrAlbumCache { get; set; } - DbSet SickRageEpisodeCache { get; set; } + //DbSet SonarrEpisodeCache { get; set; } + //DbSet CouchPotatoCache { get; set; } + //DbSet SickRageCache { get; set; } + //DbSet LidarrArtistCache { get; set; } + //DbSet LidarrAlbumCache { get; set; } + //DbSet SickRageEpisodeCache { get; set; } DbSet RequestLogs { get; set; } DbSet RecentlyAddedLogs { get; set; } DbSet RequestSubscription { get; set; } diff --git a/src/Ombi.Store/Entities/PlexServerContent.cs b/src/Ombi.Store/Entities/PlexServerContent.cs index 14028cb57..eff872b60 100644 --- a/src/Ombi.Store/Entities/PlexServerContent.cs +++ b/src/Ombi.Store/Entities/PlexServerContent.cs @@ -42,11 +42,6 @@ namespace Ombi.Store.Entities public PlexMediaTypeEntity Type { get; set; } public string Url { get; set; } - - /// - /// Only used for TV Shows - /// - public virtual ICollection Seasons { get; set; } public ICollection Episodes { get; set; } @@ -67,15 +62,6 @@ namespace Ombi.Store.Entities public bool HasTheMovieDb => !string.IsNullOrEmpty(TheMovieDbId); } - [Table("PlexSeasonsContent")] - public class PlexSeasonsContent : Entity - { - public int PlexContentId { get; set; } - public int SeasonNumber { get; set; } - public int SeasonKey { get; set; } - public int ParentKey { get; set; } - } - public enum PlexMediaTypeEntity { Movie = 0, diff --git a/src/Ombi.Store/Repository/EmbyContentRepository.cs b/src/Ombi.Store/Repository/EmbyContentRepository.cs index c4377f929..4d32e8da2 100644 --- a/src/Ombi.Store/Repository/EmbyContentRepository.cs +++ b/src/Ombi.Store/Repository/EmbyContentRepository.cs @@ -35,15 +35,15 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public class EmbyContentRepository : Repository, IEmbyContentRepository + public class EmbyContentRepository : ExternalRepository, IEmbyContentRepository { - public EmbyContentRepository(IOmbiContext db):base(db) + public EmbyContentRepository(IExternalContext db):base(db) { Db = db; } - private IOmbiContext Db { get; } + private IExternalContext Db { get; } public async Task GetByImdbId(string imdbid) diff --git a/src/Ombi.Store/Repository/IPlexContentRepository.cs b/src/Ombi.Store/Repository/IPlexContentRepository.cs index 381a89fa3..7bce2e75a 100644 --- a/src/Ombi.Store/Repository/IPlexContentRepository.cs +++ b/src/Ombi.Store/Repository/IPlexContentRepository.cs @@ -7,7 +7,7 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public interface IPlexContentRepository : IRepository + public interface IPlexContentRepository : IExternalRepository { Task ContentExists(string providerId); Task Get(string providerId); diff --git a/src/Ombi.Store/Repository/PlexContentRepository.cs b/src/Ombi.Store/Repository/PlexContentRepository.cs index e452eeb7d..2c9c28d09 100644 --- a/src/Ombi.Store/Repository/PlexContentRepository.cs +++ b/src/Ombi.Store/Repository/PlexContentRepository.cs @@ -36,15 +36,15 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public class PlexServerContentRepository : Repository, IPlexContentRepository + public class PlexServerContentRepository : ExternalRepository, IPlexContentRepository { - public PlexServerContentRepository(IOmbiContext db) : base(db) + public PlexServerContentRepository(IExternalContext db) : base(db) { Db = db; } - private IOmbiContext Db { get; } + private IExternalContext Db { get; } public async Task ContentExists(string providerId) diff --git a/src/Ombi/Program.cs b/src/Ombi/Program.cs index a3d06d073..6b6b07492 100644 --- a/src/Ombi/Program.cs +++ b/src/Ombi/Program.cs @@ -143,13 +143,87 @@ namespace Ombi } // Now delete the old stuff - if(doneGlobal) + if (doneGlobal) ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE GlobalSettings"); - if(doneConfig) + if (doneConfig) ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE ApplicationConfiguration"); } + // Now migrate all the external stuff + using (var ombi = new OmbiContext()) + using (var external = new ExternalContext()) + { + try + { + + if (ombi.PlexEpisode.Any()) + { + external.PlexEpisode.AddRange(ombi.PlexEpisode.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE PlexEpisode"); + } + + if (ombi.PlexServerContent.Any()) + { + external.PlexServerContent.AddRange(ombi.PlexServerContent.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE PlexServerContent"); + } + if (ombi.EmbyEpisode.Any()) + { + external.EmbyEpisode.AddRange(ombi.EmbyEpisode.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE EmbyEpisode"); + } + + if (ombi.EmbyContent.Any()) + { + external.EmbyContent.AddRange(ombi.EmbyContent.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE EmbyContent"); + } + if (ombi.RadarrCache.Any()) + { + external.RadarrCache.AddRange(ombi.RadarrCache.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE RadarrCache"); + } + if (ombi.SonarrCache.Any()) + { + external.SonarrCache.AddRange(ombi.SonarrCache.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE SonarrCache"); + } + if (ombi.LidarrAlbumCache.Any()) + { + external.LidarrAlbumCache.AddRange(ombi.LidarrAlbumCache.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE LidarrAlbumCache"); + } + if (ombi.LidarrArtistCache.Any()) + { + external.LidarrArtistCache.AddRange(ombi.LidarrArtistCache.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE LidarrArtistCache"); + } + if (ombi.SickRageEpisodeCache.Any()) + { + external.SickRageEpisodeCache.AddRange(ombi.SickRageEpisodeCache.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE SickRageEpisodeCache"); + } + if (ombi.SickRageCache.Any()) + { + external.SickRageCache.AddRange(ombi.SickRageCache.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE SickRageCache"); + } + if (ombi.CouchPotatoCache.Any()) + { + external.CouchPotatoCache.AddRange(ombi.CouchPotatoCache.ToList()); + ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE CouchPotatoCache"); + } + + external.SaveChanges(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } private static void DeleteSchedulesDb()