1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed corrupt Update History due to date-time notation

This commit is contained in:
Taloth Saldono 2020-06-07 23:50:39 +02:00 committed by Qstick
parent e8040a0819
commit 0dcb07f170

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,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)