Fixed the exception that sometimes makes ombi fallover.

pull/2814/head
TidusJar 6 years ago
parent 619ea4dbc4
commit a6b733e954

@ -47,49 +47,47 @@ namespace Ombi
instance.StoragePath = storagePath ?? string.Empty; instance.StoragePath = storagePath ?? string.Empty;
// Check if we need to migrate the settings // Check if we need to migrate the settings
CheckAndMigrate(); CheckAndMigrate();
using (var ctx = new SettingsContext()) var ctx = new SettingsContext();
var config = ctx.ApplicationConfigurations.ToList();
var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url);
var dbBaseUrl = config.FirstOrDefault(x => x.Type == ConfigurationTypes.BaseUrl);
if (url == null)
{ {
var config = ctx.ApplicationConfigurations.ToList(); url = new ApplicationConfiguration
var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url);
var dbBaseUrl = config.FirstOrDefault(x => x.Type == ConfigurationTypes.BaseUrl);
if (url == null)
{ {
url = new ApplicationConfiguration Type = ConfigurationTypes.Url,
{ Value = "http://*:5000"
Type = ConfigurationTypes.Url, };
Value = "http://*:5000"
};
ctx.ApplicationConfigurations.Add(url); ctx.ApplicationConfigurations.Add(url);
ctx.SaveChanges(); ctx.SaveChanges();
urlValue = url.Value; urlValue = url.Value;
} }
if (!url.Value.Equals(host)) if (!url.Value.Equals(host))
{ {
url.Value = UrlArgs; url.Value = UrlArgs;
ctx.SaveChanges(); ctx.SaveChanges();
urlValue = url.Value; urlValue = url.Value;
} }
if (dbBaseUrl == null) if (dbBaseUrl == null)
{
if (baseUrl.HasValue() && baseUrl.StartsWith("/"))
{ {
if (baseUrl.HasValue() && baseUrl.StartsWith("/")) dbBaseUrl = new ApplicationConfiguration
{ {
dbBaseUrl = new ApplicationConfiguration Type = ConfigurationTypes.BaseUrl,
{ Value = baseUrl
Type = ConfigurationTypes.BaseUrl, };
Value = baseUrl ctx.ApplicationConfigurations.Add(dbBaseUrl);
};
ctx.ApplicationConfigurations.Add(dbBaseUrl);
ctx.SaveChanges();
}
}
else if (baseUrl.HasValue() && !baseUrl.Equals(dbBaseUrl.Value))
{
dbBaseUrl.Value = baseUrl;
ctx.SaveChanges(); ctx.SaveChanges();
} }
} }
else if (baseUrl.HasValue() && !baseUrl.Equals(dbBaseUrl.Value))
{
dbBaseUrl.Value = baseUrl;
ctx.SaveChanges();
}
DeleteSchedulesDb(); DeleteSchedulesDb();
@ -111,124 +109,118 @@ namespace Ombi
{ {
var doneGlobal = false; var doneGlobal = false;
var doneConfig = false; var doneConfig = false;
using (var ombi = new OmbiContext()) var ombi = new OmbiContext();
using (var settings = new SettingsContext()) var settings = new SettingsContext();
try
{ {
try if (ombi.Settings.Any())
{ {
if (ombi.Settings.Any()) // OK migrate it!
{ var allSettings = ombi.Settings.ToList();
// OK migrate it! settings.Settings.AddRange(allSettings);
var allSettings = ombi.Settings.ToList(); doneGlobal = true;
settings.Settings.AddRange(allSettings); }
doneGlobal = true;
}
// Check for any application settings // Check for any application settings
if (ombi.ApplicationConfigurations.Any()) if (ombi.ApplicationConfigurations.Any())
{
// OK migrate it!
var allSettings = ombi.ApplicationConfigurations.ToList();
settings.ApplicationConfigurations.AddRange(allSettings);
doneConfig = true;
}
settings.SaveChanges();
}
catch (Exception e)
{ {
Console.WriteLine(e); // OK migrate it!
throw; var allSettings = ombi.ApplicationConfigurations.ToList();
settings.ApplicationConfigurations.AddRange(allSettings);
doneConfig = true;
} }
// Now delete the old stuff settings.SaveChanges();
if (doneGlobal) }
ombi.Database.ExecuteSqlCommand("DELETE FROM GlobalSettings"); catch (Exception e)
if (doneConfig) {
ombi.Database.ExecuteSqlCommand("DELETE FROM ApplicationConfiguration"); Console.WriteLine(e);
throw;
} }
// Now delete the old stuff
if (doneGlobal)
ombi.Database.ExecuteSqlCommand("DELETE FROM GlobalSettings");
if (doneConfig)
ombi.Database.ExecuteSqlCommand("DELETE FROM ApplicationConfiguration");
// Now migrate all the external stuff // Now migrate all the external stuff
using (var ombi = new OmbiContext()) var external = new ExternalContext();
using (var external = new ExternalContext())
try
{ {
try if (ombi.PlexEpisode.Any())
{ {
external.PlexEpisode.AddRange(ombi.PlexEpisode.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM PlexEpisode");
}
if (ombi.PlexEpisode.Any()) if (ombi.PlexSeasonsContent.Any())
{ {
external.PlexEpisode.AddRange(ombi.PlexEpisode.ToList()); external.PlexSeasonsContent.AddRange(ombi.PlexSeasonsContent.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM PlexEpisode"); ombi.Database.ExecuteSqlCommand("DELETE FROM PlexSeasonsContent");
} }
if (ombi.PlexServerContent.Any())
if (ombi.PlexSeasonsContent.Any()) {
{ external.PlexServerContent.AddRange(ombi.PlexServerContent.ToList());
external.PlexSeasonsContent.AddRange(ombi.PlexSeasonsContent.ToList()); ombi.Database.ExecuteSqlCommand("DELETE FROM PlexServerContent");
ombi.Database.ExecuteSqlCommand("DELETE FROM PlexSeasonsContent"); }
} if (ombi.EmbyEpisode.Any())
if (ombi.PlexServerContent.Any()) {
{ external.EmbyEpisode.AddRange(ombi.EmbyEpisode.ToList());
external.PlexServerContent.AddRange(ombi.PlexServerContent.ToList()); ombi.Database.ExecuteSqlCommand("DELETE FROM EmbyEpisode");
ombi.Database.ExecuteSqlCommand("DELETE FROM PlexServerContent"); }
}
if (ombi.EmbyEpisode.Any())
{
external.EmbyEpisode.AddRange(ombi.EmbyEpisode.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM EmbyEpisode");
}
if (ombi.EmbyContent.Any())
{
external.EmbyContent.AddRange(ombi.EmbyContent.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM EmbyContent");
}
if (ombi.RadarrCache.Any())
{
external.RadarrCache.AddRange(ombi.RadarrCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM RadarrCache");
}
if (ombi.SonarrCache.Any())
{
external.SonarrCache.AddRange(ombi.SonarrCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM SonarrCache");
}
if (ombi.LidarrAlbumCache.Any())
{
external.LidarrAlbumCache.AddRange(ombi.LidarrAlbumCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM LidarrAlbumCache");
}
if (ombi.LidarrArtistCache.Any())
{
external.LidarrArtistCache.AddRange(ombi.LidarrArtistCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM LidarrArtistCache");
}
if (ombi.SickRageEpisodeCache.Any())
{
external.SickRageEpisodeCache.AddRange(ombi.SickRageEpisodeCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM SickRageEpisodeCache");
}
if (ombi.SickRageCache.Any())
{
external.SickRageCache.AddRange(ombi.SickRageCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM SickRageCache");
}
if (ombi.CouchPotatoCache.Any())
{
external.CouchPotatoCache.AddRange(ombi.CouchPotatoCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM CouchPotatoCache");
}
external.SaveChanges(); if (ombi.EmbyContent.Any())
{
external.EmbyContent.AddRange(ombi.EmbyContent.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM EmbyContent");
} }
catch (Exception e) if (ombi.RadarrCache.Any())
{ {
Console.WriteLine(e); external.RadarrCache.AddRange(ombi.RadarrCache.ToList());
throw; ombi.Database.ExecuteSqlCommand("DELETE FROM RadarrCache");
}
if (ombi.SonarrCache.Any())
{
external.SonarrCache.AddRange(ombi.SonarrCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM SonarrCache");
}
if (ombi.LidarrAlbumCache.Any())
{
external.LidarrAlbumCache.AddRange(ombi.LidarrAlbumCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM LidarrAlbumCache");
}
if (ombi.LidarrArtistCache.Any())
{
external.LidarrArtistCache.AddRange(ombi.LidarrArtistCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM LidarrArtistCache");
}
if (ombi.SickRageEpisodeCache.Any())
{
external.SickRageEpisodeCache.AddRange(ombi.SickRageEpisodeCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM SickRageEpisodeCache");
}
if (ombi.SickRageCache.Any())
{
external.SickRageCache.AddRange(ombi.SickRageCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM SickRageCache");
}
if (ombi.CouchPotatoCache.Any())
{
external.CouchPotatoCache.AddRange(ombi.CouchPotatoCache.ToList());
ombi.Database.ExecuteSqlCommand("DELETE FROM CouchPotatoCache");
} }
}
external.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
} }
private static void DeleteSchedulesDb() private static void DeleteSchedulesDb()

@ -209,7 +209,7 @@ namespace Ombi
app.UseHangfireDashboard(settings.BaseUrl.HasValue() ? $"{settings.BaseUrl}/hangfire" : "/hangfire", app.UseHangfireDashboard(settings.BaseUrl.HasValue() ? $"{settings.BaseUrl}/hangfire" : "/hangfire",
new DashboardOptions new DashboardOptions
{ {
Authorization = new[] {new HangfireAuthorizationFilter()} Authorization = new[] { new HangfireAuthorizationFilter() }
}); });
} }
@ -237,15 +237,12 @@ namespace Ombi
app.UseMiddleware<ApiKeyMiddlewear>(); app.UseMiddleware<ApiKeyMiddlewear>();
app.UseCors("MyPolicy"); app.UseCors("MyPolicy");
//app.ApiKeyMiddlewear(app.ApplicationServices);
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => app.UseSwaggerUI(c =>
{ {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
}); });
app.UseMvc(routes => app.UseMvc(routes =>
{ {
routes.MapRoute( routes.MapRoute(
@ -256,8 +253,6 @@ namespace Ombi
name: "spa-fallback", name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" }); defaults: new { controller = "Home", action = "Index" });
}); });
ombiService.Dispose();
} }
} }

Loading…
Cancel
Save