mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed corrupt Update History due to date-time notation
This commit is contained in:
parent
6a51f081ac
commit
e66b28fb87
@ -18,14 +18,6 @@ protected override void LogDbUpgrade()
|
||||
.WithColumn("Date").AsDateTime().NotNullable().Indexed()
|
||||
.WithColumn("Version").AsString().NotNullable()
|
||||
.WithColumn("EventType").AsInt32().NotNullable();
|
||||
|
||||
Insert.IntoTable("UpdateHistory")
|
||||
.Row(new
|
||||
{
|
||||
Date = new UtcConverter().ToDB(DateTime.UtcNow).ToString(),
|
||||
Version = BuildInfo.Version.ToString(),
|
||||
EventType = 2
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
@ -17,24 +18,42 @@ public class UpdateHistoryService : IUpdateHistoryService, IHandle<ApplicationSt
|
||||
{
|
||||
private readonly IUpdateHistoryRepository _repository;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
private Version _prevVersion;
|
||||
|
||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator)
|
||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger)
|
||||
{
|
||||
_repository = repository;
|
||||
_eventAggregator = eventAggregator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Version PreviouslyInstalled()
|
||||
{
|
||||
var history = _repository.PreviouslyInstalled();
|
||||
try
|
||||
{
|
||||
var history = _repository.PreviouslyInstalled();
|
||||
|
||||
return history?.Version;
|
||||
return history?.Version;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to determine previously installed version");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<UpdateHistory> InstalledSince(DateTime dateTime)
|
||||
{
|
||||
return _repository.InstalledSince(dateTime);
|
||||
try
|
||||
{
|
||||
return _repository.InstalledSince(dateTime);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to get list of previously installed versions");
|
||||
return new List<UpdateHistory>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
@ -45,19 +64,29 @@ public void Handle(ApplicationStartedEvent message)
|
||||
return;
|
||||
}
|
||||
|
||||
var history = _repository.LastInstalled();
|
||||
UpdateHistory history;
|
||||
try
|
||||
{
|
||||
history = _repository.LastInstalled();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Cleaning corrupted update history");
|
||||
_repository.Purge();
|
||||
history = null;
|
||||
}
|
||||
|
||||
if (history == null || history.Version != BuildInfo.Version)
|
||||
{
|
||||
_prevVersion = history.Version;
|
||||
|
||||
_repository.Insert(new UpdateHistory
|
||||
{
|
||||
Date = DateTime.UtcNow,
|
||||
Version = BuildInfo.Version,
|
||||
EventType = UpdateHistoryEventType.Installed
|
||||
});
|
||||
}
|
||||
_prevVersion = history?.Version;
|
||||
|
||||
_repository.Insert(new UpdateHistory
|
||||
{
|
||||
Date = DateTime.UtcNow,
|
||||
Version = BuildInfo.Version,
|
||||
EventType = UpdateHistoryEventType.Installed
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(ApplicationStartedEvent message)
|
||||
|
Loading…
Reference in New Issue
Block a user