mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
The move!
This commit is contained in:
parent
1daf480b1b
commit
25526cc4d9
1147 changed files with 85 additions and 8524 deletions
53
Old/Ombi.Core.Migration/Migrations/BaseMigration.cs
Normal file
53
Old/Ombi.Core.Migration/Migrations/BaseMigration.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: BaseMigration.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.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using Ombi.Store;
|
||||
|
||||
namespace Ombi.Core.Migration.Migrations
|
||||
{
|
||||
public abstract class BaseMigration
|
||||
{
|
||||
protected void UpdateSchema(IDbConnection con, int version)
|
||||
{
|
||||
var migrations = MigrationRunner.GetMigrations();
|
||||
var model = migrations.Select(x => x.Value).FirstOrDefault(x => x.Version == version);
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
con.AddVersionInfo(new TableCreation.VersionInfo { Version = model.Version, Description = model.Description });
|
||||
}
|
||||
}
|
||||
|
||||
protected IEnumerable<TableCreation.VersionInfo> GetVersionInfo(IDbConnection con)
|
||||
{
|
||||
return con.GetVersionInfo();
|
||||
}
|
||||
}
|
||||
}
|
346
Old/Ombi.Core.Migration/Migrations/Version1100.cs
Normal file
346
Old/Ombi.Core.Migration/Migrations/Version1100.cs
Normal file
|
@ -0,0 +1,346 @@
|
|||
#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 System.Linq;
|
||||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Helpers.Permissions;
|
||||
using Ombi.Store;
|
||||
using Ombi.Store.Models;
|
||||
using Ombi.Store.Models.Plex;
|
||||
using Ombi.Store.Repository;
|
||||
|
||||
namespace Ombi.Core.Migration.Migrations
|
||||
{
|
||||
[Migration(11000, "v1.10.0.0")]
|
||||
public class Version1100 : BaseMigration, IMigration
|
||||
{
|
||||
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log,
|
||||
IPlexApi plexApi, ISettingsService<PlexSettings> plexService,
|
||||
IExternalUserRepository<PlexUsers> plexusers, ISettingsService<PlexRequestSettings> prSettings,
|
||||
ISettingsService<UserManagementSettings> umSettings,
|
||||
ISettingsService<ScheduledJobsSettings> sjs, IRepository<UsersToNotify> usersToNotify)
|
||||
{
|
||||
UserRepo = userRepo;
|
||||
RequestService = requestService;
|
||||
Log = log;
|
||||
PlexApi = plexApi;
|
||||
PlexSettings = plexService;
|
||||
PlexUsers = plexusers;
|
||||
PlexRequestSettings = prSettings;
|
||||
UserManagementSettings = umSettings;
|
||||
ScheduledJobSettings = sjs;
|
||||
UserNotifyRepo = usersToNotify;
|
||||
}
|
||||
|
||||
public int Version => 11000;
|
||||
|
||||
private IUserRepository UserRepo { get; }
|
||||
private IRequestService RequestService { get; }
|
||||
private ISettingsService<LogSettings> Log { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private IExternalUserRepository<PlexUsers> PlexUsers { get; }
|
||||
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
|
||||
private ISettingsService<UserManagementSettings> UserManagementSettings { get; }
|
||||
private ISettingsService<ScheduledJobsSettings> ScheduledJobSettings { get; }
|
||||
private IRepository<UsersToNotify> UserNotifyRepo { get; }
|
||||
|
||||
|
||||
private static Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public void Start(IDbConnection con)
|
||||
{
|
||||
UpdateDb(con);
|
||||
|
||||
// Update the current admin permissions set
|
||||
|
||||
PopulateDefaultUserManagementSettings();
|
||||
UpdateAdmin();
|
||||
ResetLogLevel();
|
||||
UpdatePlexUsers();
|
||||
UpdateScheduledJobs();
|
||||
MigrateUserNotifications();
|
||||
|
||||
UpdateSchema(con, Version);
|
||||
}
|
||||
|
||||
private void MigrateUserNotifications()
|
||||
{
|
||||
try
|
||||
{
|
||||
var usersToNotify = UserNotifyRepo.GetAll();
|
||||
var plexUsers = PlexUsers.GetAll().ToList();
|
||||
var users = UserRepo.GetAll().ToList();
|
||||
|
||||
if (usersToNotify == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var u in usersToNotify)
|
||||
{
|
||||
var selectedPlexUser =
|
||||
plexUsers.FirstOrDefault(
|
||||
x => x.Username.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (selectedPlexUser != null)
|
||||
{
|
||||
selectedPlexUser.Features += (int)Features.RequestAddedNotification;
|
||||
PlexUsers.Update(selectedPlexUser);
|
||||
}
|
||||
|
||||
var selectedLocalUser =
|
||||
users.FirstOrDefault(x => x.UserName.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (selectedLocalUser != null)
|
||||
{
|
||||
selectedLocalUser.Features += (int)Features.RequestAddedNotification;
|
||||
UserRepo.Update(selectedLocalUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateScheduledJobs)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScheduledJobs()
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = ScheduledJobSettings.GetSettings();
|
||||
|
||||
settings.PlexUserChecker = 24;
|
||||
settings.PlexContentCacher = 60;
|
||||
|
||||
ScheduledJobSettings.SaveSettings(settings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateScheduledJobs)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateDefaultUserManagementSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var plexRequestSettings = PlexRequestSettings.GetSettings();
|
||||
|
||||
UserManagementSettings.SaveSettings(new UserManagementSettings
|
||||
{
|
||||
AutoApproveMovies = !plexRequestSettings.RequireMovieApproval,
|
||||
RequestTvShows = plexRequestSettings.SearchForTvShows,
|
||||
RequestMusic = plexRequestSettings.SearchForMusic,
|
||||
RequestMovies = plexRequestSettings.SearchForMovies,
|
||||
AutoApproveMusic = !plexRequestSettings.RequireMusicApproval,
|
||||
AutoApproveTvShows = !plexRequestSettings.RequireTvShowApproval
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (PopulateDefaultUserMngmentSettings)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePlexUsers()
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = PlexSettings.GetSettings();
|
||||
if (string.IsNullOrEmpty(settings.PlexAuthToken) || !settings.Enable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var plexUsers = PlexApi.GetUsers(settings.PlexAuthToken);
|
||||
|
||||
if (plexUsers?.User == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var prSettings = PlexRequestSettings.GetSettings();
|
||||
|
||||
var dbUsers = PlexUsers.GetAll().ToList();
|
||||
foreach (var user in plexUsers.User)
|
||||
{
|
||||
if (dbUsers.FirstOrDefault(x => x.PlexUserId == user.Id) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int permissions = 0;
|
||||
if (prSettings.SearchForMovies)
|
||||
{
|
||||
permissions = (int)Permissions.RequestMovie;
|
||||
}
|
||||
if (prSettings.SearchForTvShows)
|
||||
{
|
||||
permissions += (int)Permissions.RequestTvShow;
|
||||
}
|
||||
if (prSettings.SearchForMusic)
|
||||
{
|
||||
permissions += (int)Permissions.RequestMusic;
|
||||
}
|
||||
if (!prSettings.RequireMovieApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveMovie;
|
||||
}
|
||||
if (!prSettings.RequireTvShowApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveTv;
|
||||
}
|
||||
if (!prSettings.RequireMusicApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveAlbum;
|
||||
}
|
||||
|
||||
// Add report Issues
|
||||
|
||||
permissions += (int)Permissions.ReportIssue;
|
||||
|
||||
var m = new PlexUsers
|
||||
{
|
||||
PlexUserId = user.Id,
|
||||
Permissions = permissions,
|
||||
Features = 0,
|
||||
UserAlias = string.Empty,
|
||||
EmailAddress = user.Email,
|
||||
Username = user.Username,
|
||||
LoginId = Guid.NewGuid().ToString()
|
||||
};
|
||||
|
||||
PlexUsers.Insert(m);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdatePlexUsers)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetLogLevel()
|
||||
{
|
||||
try
|
||||
{
|
||||
var logSettings = Log.GetSettings();
|
||||
logSettings.Level = LogLevel.Error.Ordinal;
|
||||
Log.SaveSettings(logSettings);
|
||||
|
||||
LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (ResetLogLvl)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDb(IDbConnection con)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create the two new columns
|
||||
con.AlterTable("Users", "ADD", "Permissions", true, "INTEGER");
|
||||
con.AlterTable("Users", "ADD", "Features", true, "INTEGER");
|
||||
|
||||
con.AlterTable("PlexUsers", "ADD", "Permissions", true, "INTEGER");
|
||||
con.AlterTable("PlexUsers", "ADD", "Features", true, "INTEGER");
|
||||
con.AlterTable("PlexUsers", "ADD", "Username", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexUsers", "ADD", "EmailAddress", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexUsers", "ADD", "LoginId", true, "VARCHAR(100)");
|
||||
|
||||
//https://image.tmdb.org/t/p/w150/https://image.tmdb.org/t/p/w150//aqhAqttDq7zgsTaBHtCD8wmTk6k.jpg
|
||||
|
||||
// UI = https://image.tmdb.org/t/p/w150/{{posterPath}}
|
||||
// Update old invalid posters
|
||||
var allRequests = RequestService.GetAll();
|
||||
if (allRequests == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var requestedModels = allRequests.ToList();
|
||||
foreach (var req in requestedModels)
|
||||
{
|
||||
if (string.IsNullOrEmpty(req.PosterPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (req.PosterPath.Contains("https://image.tmdb.org/t/p/w150/"))
|
||||
{
|
||||
var newImg = req.PosterPath.Replace("https://image.tmdb.org/t/p/w150/", string.Empty);
|
||||
req.PosterPath = newImg;
|
||||
}
|
||||
}
|
||||
RequestService.BatchUpdate(requestedModels);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateDb)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAdmin()
|
||||
{
|
||||
try
|
||||
{
|
||||
var users = UserRepo.GetAll().ToList();
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
user.Permissions = (int)
|
||||
(Permissions.Administrator
|
||||
| Permissions.ReportIssue
|
||||
| Permissions.RequestMusic
|
||||
| Permissions.RequestTvShow
|
||||
| Permissions.RequestMovie
|
||||
| Permissions.AutoApproveAlbum
|
||||
| Permissions.AutoApproveMovie
|
||||
| Permissions.AutoApproveTv);
|
||||
}
|
||||
|
||||
UserRepo.UpdateAll(users);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateAdmin)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
99
Old/Ombi.Core.Migration/Migrations/Version195.cs
Normal file
99
Old/Ombi.Core.Migration/Migrations/Version195.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: Version195.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 Ombi.Core.SettingModels;
|
||||
using Quartz;
|
||||
|
||||
namespace Ombi.Core.Migration.Migrations
|
||||
{
|
||||
[Migration(1950, "v1.9.5.0")]
|
||||
public class Version195 : BaseMigration, IMigration
|
||||
{
|
||||
public Version195(ISettingsService<PlexRequestSettings> plexRequestSettings, ISettingsService<NewletterSettings> news, ISettingsService<ScheduledJobsSettings> jobs)
|
||||
{
|
||||
PlexRequestSettings = plexRequestSettings;
|
||||
NewsletterSettings = news;
|
||||
Jobs = jobs;
|
||||
}
|
||||
public int Version => 1950;
|
||||
|
||||
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
|
||||
private ISettingsService<NewletterSettings> NewsletterSettings { get; }
|
||||
private ISettingsService<ScheduledJobsSettings> Jobs { get; }
|
||||
|
||||
public void Start(IDbConnection con)
|
||||
{
|
||||
UpdateApplicationSettings();
|
||||
UpdateDb(con);
|
||||
|
||||
UpdateSchema(con, Version);
|
||||
}
|
||||
|
||||
private void UpdateDb(IDbConnection con)
|
||||
{
|
||||
}
|
||||
|
||||
private void UpdateApplicationSettings()
|
||||
{
|
||||
var plex = PlexRequestSettings.GetSettings();
|
||||
|
||||
var jobSettings = Jobs.GetSettings();
|
||||
var newsLetter = NewsletterSettings.GetSettings();
|
||||
|
||||
newsLetter.SendToPlexUsers = true;
|
||||
UpdateScheduledSettings(jobSettings);
|
||||
|
||||
if (plex.SendRecentlyAddedEmail)
|
||||
{
|
||||
newsLetter.SendRecentlyAddedEmail = plex.SendRecentlyAddedEmail;
|
||||
plex.SendRecentlyAddedEmail = false;
|
||||
PlexRequestSettings.SaveSettings(plex);
|
||||
}
|
||||
|
||||
|
||||
NewsletterSettings.SaveSettings(newsLetter);
|
||||
Jobs.SaveSettings(jobSettings);
|
||||
}
|
||||
|
||||
private void UpdateScheduledSettings(ScheduledJobsSettings settings)
|
||||
{
|
||||
settings.PlexAvailabilityChecker = 60;
|
||||
settings.SickRageCacher = 60;
|
||||
settings.SonarrCacher = 60;
|
||||
settings.CouchPotatoCacher = 60;
|
||||
settings.StoreBackup = 24;
|
||||
settings.StoreCleanup = 24;
|
||||
settings.UserRequestLimitResetter = 12;
|
||||
settings.PlexEpisodeCacher = 12;
|
||||
|
||||
var cron = (Quartz.Impl.Triggers.CronTriggerImpl)CronScheduleBuilder.WeeklyOnDayAndHourAndMinute(DayOfWeek.Friday, 7, 0).Build();
|
||||
settings.RecentlyAddedCron = cron.CronExpressionString; // Weekly CRON at 7 am on Mondays
|
||||
}
|
||||
}
|
||||
}
|
133
Old/Ombi.Core.Migration/Migrations/Version2200.cs
Normal file
133
Old/Ombi.Core.Migration/Migrations/Version2200.cs
Normal file
|
@ -0,0 +1,133 @@
|
|||
#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.Plex;
|
||||
using Ombi.Store.Repository;
|
||||
using Quartz.Collection;
|
||||
|
||||
namespace Ombi.Core.Migration.Migrations
|
||||
{
|
||||
[Migration(22000, "v2.20.0.0")]
|
||||
public class Version2200 : BaseMigration, IMigration
|
||||
{
|
||||
public Version2200(ISettingsService<CustomizationSettings> custom, ISettingsService<PlexSettings> ps, IRepository<RecentlyAddedLog> log,
|
||||
IRepository<PlexContent> content, IRepository<PlexEpisodes> plexEp)
|
||||
{
|
||||
Customization = custom;
|
||||
PlexSettings = ps;
|
||||
Log = log;
|
||||
PlexContent = content;
|
||||
PlexEpisodes = plexEp;
|
||||
}
|
||||
|
||||
public int Version => 22000;
|
||||
private ISettingsService<CustomizationSettings> Customization { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private IRepository<RecentlyAddedLog> Log { get; }
|
||||
private IRepository<PlexContent> PlexContent { get; }
|
||||
private IRepository<PlexEpisodes> PlexEpisodes { get; }
|
||||
|
||||
private static Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public void Start(IDbConnection con)
|
||||
{
|
||||
UpdatePlexSettings();
|
||||
UpdateCustomSettings();
|
||||
AddNewColumns(con);
|
||||
UpdateSchema(con, Version);
|
||||
UpdateRecentlyAdded(con);
|
||||
|
||||
}
|
||||
|
||||
private void UpdateRecentlyAdded(IDbConnection con)
|
||||
{
|
||||
var allContent = PlexContent.GetAll();
|
||||
|
||||
var content = new HashSet<RecentlyAddedLog>();
|
||||
foreach (var plexContent in allContent)
|
||||
{
|
||||
content.Add(new RecentlyAddedLog
|
||||
{
|
||||
AddedAt = DateTime.UtcNow,
|
||||
ProviderId = plexContent.ProviderId
|
||||
});
|
||||
}
|
||||
|
||||
Log.BatchInsert(content, "RecentlyAddedLog");
|
||||
|
||||
var allEp = PlexEpisodes.GetAll();
|
||||
content.Clear();
|
||||
foreach (var ep in allEp)
|
||||
{
|
||||
content.Add(new RecentlyAddedLog
|
||||
{
|
||||
AddedAt = DateTime.UtcNow,
|
||||
ProviderId = ep.RatingKey
|
||||
});
|
||||
}
|
||||
|
||||
Log.BatchInsert(content, "RecentlyAddedLog");
|
||||
}
|
||||
|
||||
private void AddNewColumns(IDbConnection con)
|
||||
{
|
||||
con.AlterTable("EmbyContent", "ADD", "AddedAt", true, "VARCHAR(50)");
|
||||
con.AlterTable("EmbyEpisodes", "ADD", "AddedAt", true, "VARCHAR(50)");
|
||||
|
||||
con.AlterTable("PlexContent", "ADD", "ItemId", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexContent", "ADD", "AddedAt", true, "VARCHAR(100)");
|
||||
}
|
||||
|
||||
private void UpdatePlexSettings()
|
||||
{
|
||||
#if !DEBUG
|
||||
var s = PlexSettings.GetSettings();
|
||||
if (!string.IsNullOrEmpty(s.Ip))
|
||||
{
|
||||
s.Enable = true;
|
||||
PlexSettings.SaveSettings(s);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
private void UpdateCustomSettings()
|
||||
{
|
||||
|
||||
var settings = Customization.GetSettings();
|
||||
settings.EnableIssues = true;
|
||||
settings.EnableNetflixResults = true;
|
||||
Customization.SaveSettings(settings);
|
||||
}
|
||||
}
|
||||
}
|
134
Old/Ombi.Core.Migration/Migrations/Version2210.cs
Normal file
134
Old/Ombi.Core.Migration/Migrations/Version2210.cs
Normal file
|
@ -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<RecentlyAddedLog> log,
|
||||
IRepository<PlexContent> content, IRepository<PlexEpisodes> plexEp, IRepository<EmbyContent> embyContent, IRepository<EmbyEpisodes> embyEp)
|
||||
{
|
||||
Log = log;
|
||||
PlexContent = content;
|
||||
PlexEpisodes = plexEp;
|
||||
EmbyContent = embyContent;
|
||||
EmbyEpisodes = embyEp;
|
||||
}
|
||||
|
||||
public int Version => 22100;
|
||||
private IRepository<RecentlyAddedLog> Log { get; }
|
||||
private IRepository<PlexContent> PlexContent { get; }
|
||||
private IRepository<PlexEpisodes> PlexEpisodes { get; }
|
||||
private IRepository<EmbyContent> EmbyContent { get; }
|
||||
private IRepository<EmbyEpisodes> 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<RecentlyAddedLog>();
|
||||
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");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue