mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-28 23:07:13 -04:00
New: Show previously installed version in Updates UI
Co-Authored-By: Taloth <Taloth@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Update.History
|
||||
{
|
||||
public class UpdateHistory : ModelBase
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public Version Version { get; set; }
|
||||
public UpdateHistoryEventType EventType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace NzbDrone.Core.Update.History
|
||||
{
|
||||
public enum UpdateHistoryEventType
|
||||
{
|
||||
Unknown = 0,
|
||||
Initiated = 1,
|
||||
Installed = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Update.History
|
||||
{
|
||||
public interface IUpdateHistoryRepository : IBasicRepository<UpdateHistory>
|
||||
{
|
||||
UpdateHistory LastInstalled();
|
||||
UpdateHistory PreviouslyInstalled();
|
||||
List<UpdateHistory> InstalledSince(DateTime dateTime);
|
||||
}
|
||||
|
||||
public class UpdateHistoryRepository : BasicRepository<UpdateHistory>, IUpdateHistoryRepository
|
||||
{
|
||||
public UpdateHistoryRepository(ILogDatabase logDatabase, IEventAggregator eventAggregator)
|
||||
: base(logDatabase, eventAggregator)
|
||||
{
|
||||
}
|
||||
|
||||
public UpdateHistory LastInstalled()
|
||||
{
|
||||
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
|
||||
.OrderBy(v => v.Date)
|
||||
.Take(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
public UpdateHistory PreviouslyInstalled()
|
||||
{
|
||||
var history = Query(x => x.EventType == UpdateHistoryEventType.Installed)
|
||||
.OrderBy(v => v.Date)
|
||||
.Skip(1)
|
||||
.Take(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
public List<UpdateHistory> InstalledSince(DateTime dateTime)
|
||||
{
|
||||
var history = Query(v => v.EventType == UpdateHistoryEventType.Installed && v.Date >= dateTime)
|
||||
.OrderBy(v => v.Date)
|
||||
.ToList();
|
||||
|
||||
return history;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Update.History.Events;
|
||||
|
||||
namespace NzbDrone.Core.Update.History
|
||||
{
|
||||
public interface IUpdateHistoryService
|
||||
{
|
||||
Version PreviouslyInstalled();
|
||||
List<UpdateHistory> InstalledSince(DateTime dateTime);
|
||||
}
|
||||
|
||||
public class UpdateHistoryService : IUpdateHistoryService, IHandle<ApplicationStartedEvent>, IHandleAsync<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly IUpdateHistoryRepository _repository;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private Version _prevVersion;
|
||||
|
||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator)
|
||||
{
|
||||
_repository = repository;
|
||||
_eventAggregator = eventAggregator;
|
||||
}
|
||||
|
||||
public Version PreviouslyInstalled()
|
||||
{
|
||||
var history = _repository.PreviouslyInstalled();
|
||||
|
||||
return history?.Version;
|
||||
}
|
||||
|
||||
public List<UpdateHistory> InstalledSince(DateTime dateTime)
|
||||
{
|
||||
return _repository.InstalledSince(dateTime);
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
if (BuildInfo.Version.Major == 10)
|
||||
{
|
||||
// Don't save dev versions, they change constantly
|
||||
return;
|
||||
}
|
||||
|
||||
var history = _repository.LastInstalled();
|
||||
|
||||
if (history == null || history.Version != BuildInfo.Version)
|
||||
{
|
||||
_prevVersion = history.Version;
|
||||
|
||||
_repository.Insert(new UpdateHistory
|
||||
{
|
||||
Date = DateTime.UtcNow,
|
||||
Version = BuildInfo.Version,
|
||||
EventType = UpdateHistoryEventType.Installed
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(ApplicationStartedEvent message)
|
||||
{
|
||||
if (_prevVersion != null)
|
||||
{
|
||||
_eventAggregator.PublishEvent(new UpdateInstalledEvent(_prevVersion, BuildInfo.Version));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user