From d53864fef1e9dab712a4d00f3bd696a16829b0a8 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 6 Apr 2017 20:35:57 +0100 Subject: [PATCH] #1264 "They may take our lives, but they'll never take our freedom!" --- Ombi.Core.Migration/Migrations/Version2200.cs | 2 +- Ombi.Core.Migration/Migrations/Version2210.cs | 134 ++++++++++++++++++ .../Ombi.Core.Migration.csproj | 1 + .../PlexRecentlyAddedNewsletter.cs | 13 +- ...cenetlyAddedLog.cs => RecentlyAddedLog.cs} | 3 + Ombi.Store/Ombi.Store.csproj | 2 +- Ombi.UI/Views/Admin/NewsletterSettings.cshtml | 2 +- appveyor.yml | 4 +- 8 files changed, 152 insertions(+), 9 deletions(-) create mode 100644 Ombi.Core.Migration/Migrations/Version2210.cs rename Ombi.Store/Models/{RecenetlyAddedLog.cs => RecentlyAddedLog.cs} (94%) diff --git a/Ombi.Core.Migration/Migrations/Version2200.cs b/Ombi.Core.Migration/Migrations/Version2200.cs index d52e1654b..588d305ed 100644 --- a/Ombi.Core.Migration/Migrations/Version2200.cs +++ b/Ombi.Core.Migration/Migrations/Version2200.cs @@ -94,7 +94,7 @@ namespace Ombi.Core.Migration.Migrations content.Add(new RecentlyAddedLog { AddedAt = DateTime.UtcNow, - ProviderId = ep.ProviderId + ProviderId = ep.RatingKey }); } diff --git a/Ombi.Core.Migration/Migrations/Version2210.cs b/Ombi.Core.Migration/Migrations/Version2210.cs new file mode 100644 index 000000000..258e4da46 --- /dev/null +++ b/Ombi.Core.Migration/Migrations/Version2210.cs @@ -0,0 +1,134 @@ +#region Copyright + +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: Version1100.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ + +#endregion + +using System; +using System.Data; +using NLog; +using Ombi.Core.SettingModels; +using Ombi.Store; +using Ombi.Store.Models; +using Ombi.Store.Models.Emby; +using Ombi.Store.Models.Plex; +using Ombi.Store.Repository; +using Quartz.Collection; + +namespace Ombi.Core.Migration.Migrations +{ + [Migration(22100, "v2.21.0.0")] + public class Version2210 : BaseMigration, IMigration + { + public Version2210(IRepository log, + IRepository content, IRepository plexEp, IRepository embyContent, IRepository embyEp) + { + Log = log; + PlexContent = content; + PlexEpisodes = plexEp; + EmbyContent = embyContent; + EmbyEpisodes = embyEp; + } + + public int Version => 22000; + private IRepository Log { get; } + private IRepository PlexContent { get; } + private IRepository PlexEpisodes { get; } + private IRepository EmbyContent { get; } + private IRepository EmbyEpisodes { get; } + + public void Start(IDbConnection con) + { + UpdateRecentlyAdded(con); + UpdateSchema(con, Version); + + } + + private void UpdateRecentlyAdded(IDbConnection con) + { + + //Delete the recently added table, lets start again + Log.DeleteAll("RecentlyAddedLog"); + + + + // Plex + var plexAllContent = PlexContent.GetAll(); + var content = new HashSet(); + foreach (var plexContent in plexAllContent) + { + if(plexContent.Type == PlexMediaType.Artist) continue; + content.Add(new RecentlyAddedLog + { + AddedAt = DateTime.UtcNow, + ProviderId = plexContent.ProviderId + }); + } + Log.BatchInsert(content, "RecentlyAddedLog"); + + var plexEpisodeses = PlexEpisodes.GetAll(); + content.Clear(); + foreach (var ep in plexEpisodeses) + { + content.Add(new RecentlyAddedLog + { + AddedAt = DateTime.UtcNow, + ProviderId = ep.RatingKey + }); + } + Log.BatchInsert(content, "RecentlyAddedLog"); + + // Emby + content.Clear(); + var embyContent = EmbyContent.GetAll(); + foreach (var plexContent in embyContent) + { + content.Add(new RecentlyAddedLog + { + AddedAt = DateTime.UtcNow, + ProviderId = plexContent.EmbyId + }); + } + Log.BatchInsert(content, "RecentlyAddedLog"); + + var embyEpisodes = EmbyEpisodes.GetAll(); + content.Clear(); + foreach (var ep in embyEpisodes) + { + content.Add(new RecentlyAddedLog + { + AddedAt = DateTime.UtcNow, + ProviderId = ep.EmbyId + }); + } + Log.BatchInsert(content, "RecentlyAddedLog"); + + + } + + + } +} diff --git a/Ombi.Core.Migration/Ombi.Core.Migration.csproj b/Ombi.Core.Migration/Ombi.Core.Migration.csproj index 06dfda84d..4c2272a03 100644 --- a/Ombi.Core.Migration/Ombi.Core.Migration.csproj +++ b/Ombi.Core.Migration/Ombi.Core.Migration.csproj @@ -69,6 +69,7 @@ + diff --git a/Ombi.Services/Jobs/RecentlyAddedNewsletter/PlexRecentlyAddedNewsletter.cs b/Ombi.Services/Jobs/RecentlyAddedNewsletter/PlexRecentlyAddedNewsletter.cs index 1f9601b07..6eda44bec 100644 --- a/Ombi.Services/Jobs/RecentlyAddedNewsletter/PlexRecentlyAddedNewsletter.cs +++ b/Ombi.Services/Jobs/RecentlyAddedNewsletter/PlexRecentlyAddedNewsletter.cs @@ -117,7 +117,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter var firstRun = !recentlyAdded.Any(); var filteredMovies = movie.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList(); - var filteredEp = episodes.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList(); + var filteredEp = episodes.Where(m => recentlyAdded.All(x => x.ProviderId != m.RatingKey)).ToList(); var filteredSeries = series.Where(x => recentlyAdded.All(c => c.ProviderId != x.ProviderId)).ToList(); var info = new List(); @@ -144,6 +144,11 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter newsletter.MovieCount = info.Count; info.Clear(); + if (test && !filteredEp.Any() && episodes.Any()) + { + // if this is a test make sure we show something + filteredEp = episodes.Take(5).ToList(); + } if (filteredEp.Any()) { var recentlyAddedModel = new List(); @@ -226,7 +231,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter { RecentlyAddedLog.Insert(new RecentlyAddedLog { - ProviderId = a.ProviderId, + ProviderId = a.RatingKey, AddedAt = DateTime.UtcNow }); } @@ -335,7 +340,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter try { - var info = TvApi.ShowLookupByTheTvDbId(int.Parse(PlexHelper.GetProviderIdFromPlexGuid(t.Metadata.Directory.Guid))); + var info = TvApi.ShowLookupByTheTvDbId(int.Parse(PlexHelper.GetProviderIdFromPlexGuid(t?.Metadata?.Directory?.Guid ?? string.Empty))); var banner = info.image?.original; if (!string.IsNullOrEmpty(banner)) @@ -370,7 +375,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter for (var i = 0; i < orderedEpisodes.Count; i++) { var ep = orderedEpisodes[i]; - if (i <= orderedEpisodes.Count - 1) + if (i < orderedEpisodes.Count - 1) { epSb.Append($"{ep.Video.FirstOrDefault().Index},"); } diff --git a/Ombi.Store/Models/RecenetlyAddedLog.cs b/Ombi.Store/Models/RecentlyAddedLog.cs similarity index 94% rename from Ombi.Store/Models/RecenetlyAddedLog.cs rename to Ombi.Store/Models/RecentlyAddedLog.cs index 4f7a75aba..f39df89bd 100644 --- a/Ombi.Store/Models/RecenetlyAddedLog.cs +++ b/Ombi.Store/Models/RecentlyAddedLog.cs @@ -34,6 +34,9 @@ namespace Ombi.Store.Models [Table("RecentlyAddedLog")] public class RecentlyAddedLog : Entity { + /// + /// This is actually a unique id for that content... + /// public string ProviderId { get; set; } public DateTime AddedAt { get; set; } } diff --git a/Ombi.Store/Ombi.Store.csproj b/Ombi.Store/Ombi.Store.csproj index 06a0b59fc..976e7fd59 100644 --- a/Ombi.Store/Ombi.Store.csproj +++ b/Ombi.Store/Ombi.Store.csproj @@ -68,7 +68,7 @@ - + diff --git a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml index 32bc10dce..e69df55f5 100644 --- a/Ombi.UI/Views/Admin/NewsletterSettings.cshtml +++ b/Ombi.UI/Views/Admin/NewsletterSettings.cshtml @@ -33,7 +33,7 @@
-
diff --git a/appveyor.yml b/appveyor.yml index 2357e7eaa..dec0cba4d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,9 +3,9 @@ configuration: Release assembly_info: patch: true file: '**\AssemblyInfo.*' - assembly_version: '2.2.0' + assembly_version: '2.2.1' assembly_file_version: '{version}' - assembly_informational_version: '2.2.0' + assembly_informational_version: '2.2.1' before_build: - cmd: appveyor-retry nuget restore build: