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

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

Loading…
Cancel
Save