Fixed corrupt Update History due to date-time notation

This commit is contained in:
Taloth Saldono 2020-06-07 23:50:39 +02:00
parent 6a51f081ac
commit e66b28fb87
2 changed files with 43 additions and 22 deletions

View File

@ -18,14 +18,6 @@ namespace NzbDrone.Core.Datastore.Migration
.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
});
}
}
}

View File

@ -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,25 +18,43 @@ namespace NzbDrone.Core.Update.History
{
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()
{
try
{
var history = _repository.PreviouslyInstalled();
return history?.Version;
}
catch (Exception ex)
{
_logger.Warn(ex, "Failed to determine previously installed version");
return null;
}
}
public List<UpdateHistory> InstalledSince(DateTime 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,11 +64,21 @@ namespace NzbDrone.Core.Update.History
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;
_prevVersion = history?.Version;
_repository.Insert(new UpdateHistory
{