pass current server version into installation manager to get update list

pull/702/head
Luke Pulverenti 11 years ago
parent 5d837309e4
commit 1c7c71075a

@ -132,7 +132,7 @@ namespace MediaBrowser.Api
if (request.PackageType == PackageType.UserInstalled || request.PackageType == PackageType.All)
{
result.AddRange(_installationManager.GetAvailablePluginUpdates(false, CancellationToken.None).Result.ToList());
result.AddRange(_installationManager.GetAvailablePluginUpdates(_appHost.ApplicationVersion, false, CancellationToken.None).Result.ToList());
}
else if (request.PackageType == PackageType.System || request.PackageType == PackageType.All)
@ -194,7 +194,7 @@ namespace MediaBrowser.Api
public void Post(InstallPackage request)
{
var package = string.IsNullOrEmpty(request.Version) ?
_installationManager.GetLatestCompatibleVersion(request.Name, request.UpdateClass).Result :
_installationManager.GetLatestCompatibleVersion(request.Name, _appHost.ApplicationVersion, request.UpdateClass).Result :
_installationManager.GetPackage(request.Name, request.UpdateClass, Version.Parse(request.Version)).Result;
if (package == null)

@ -225,9 +225,9 @@ namespace MediaBrowser.Common.Implementations.Updates
/// Determines whether [is package version up to date] [the specified package version info].
/// </summary>
/// <param name="packageVersionInfo">The package version info.</param>
/// <param name="applicationVersion">The application version.</param>
/// <param name="currentServerVersion">The current server version.</param>
/// <returns><c>true</c> if [is package version up to date] [the specified package version info]; otherwise, <c>false</c>.</returns>
private bool IsPackageVersionUpToDate(PackageVersionInfo packageVersionInfo, Version applicationVersion)
private bool IsPackageVersionUpToDate(PackageVersionInfo packageVersionInfo, Version currentServerVersion)
{
if (string.IsNullOrEmpty(packageVersionInfo.requiredVersionStr))
{
@ -236,7 +236,7 @@ namespace MediaBrowser.Common.Implementations.Updates
Version requiredVersion;
return Version.TryParse(packageVersionInfo.requiredVersionStr, out requiredVersion) && applicationVersion >= requiredVersion;
return Version.TryParse(packageVersionInfo.requiredVersionStr, out requiredVersion) && currentServerVersion >= requiredVersion;
}
/// <summary>
@ -264,13 +264,14 @@ namespace MediaBrowser.Common.Implementations.Updates
/// Gets the latest compatible version.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param>
/// <returns>Task{PackageVersionInfo}.</returns>
public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, PackageVersionClass classification = PackageVersionClass.Release)
public async Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
{
var packages = await GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
return GetLatestCompatibleVersion(packages, name, classification);
return GetLatestCompatibleVersion(packages, name, currentServerVersion, classification);
}
/// <summary>
@ -278,9 +279,10 @@ namespace MediaBrowser.Common.Implementations.Updates
/// </summary>
/// <param name="availablePackages">The available packages.</param>
/// <param name="name">The name.</param>
/// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param>
/// <returns>PackageVersionInfo.</returns>
public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, PackageVersionClass classification = PackageVersionClass.Release)
public PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release)
{
var package = availablePackages.FirstOrDefault(p => p.name.Equals(name, StringComparison.OrdinalIgnoreCase));
@ -291,23 +293,20 @@ namespace MediaBrowser.Common.Implementations.Updates
return package.versions
.OrderByDescending(v => v.version)
.FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, _applicationHost.ApplicationVersion));
.FirstOrDefault(v => v.classification <= classification && IsPackageVersionUpToDate(v, currentServerVersion));
}
/// <summary>
/// Gets the available plugin updates.
/// </summary>
/// <param name="currentServerVersion">The current server version.</param>
/// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>
public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken)
public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(Version currentServerVersion, bool withAutoUpdateEnabled, CancellationToken cancellationToken)
{
var catalog = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
return FilterCatalog(catalog, withAutoUpdateEnabled);
}
protected IEnumerable<PackageVersionInfo> FilterCatalog(IEnumerable<PackageInfo> catalog, bool withAutoUpdateEnabled)
{
var plugins = _applicationHost.Plugins.ToList();
if (withAutoUpdateEnabled)
@ -320,7 +319,7 @@ namespace MediaBrowser.Common.Implementations.Updates
// Figure out what needs to be installed
var packages = plugins.Select(p =>
{
var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, p.Configuration.UpdateClass);
var latestPluginInfo = GetLatestCompatibleVersion(catalog, p.Name, currentServerVersion, p.Configuration.UpdateClass);
return latestPluginInfo != null && latestPluginInfo.version != null && latestPluginInfo.version > p.Version ? latestPluginInfo : null;

@ -76,26 +76,29 @@ namespace MediaBrowser.Common.Updates
/// Gets the latest compatible version.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param>
/// <returns>Task{PackageVersionInfo}.</returns>
Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, PackageVersionClass classification = PackageVersionClass.Release);
Task<PackageVersionInfo> GetLatestCompatibleVersion(string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release);
/// <summary>
/// Gets the latest compatible version.
/// </summary>
/// <param name="availablePackages">The available packages.</param>
/// <param name="name">The name.</param>
/// <param name="currentServerVersion">The current server version.</param>
/// <param name="classification">The classification.</param>
/// <returns>PackageVersionInfo.</returns>
PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, PackageVersionClass classification = PackageVersionClass.Release);
PackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, Version currentServerVersion, PackageVersionClass classification = PackageVersionClass.Release);
/// <summary>
/// Gets the available plugin updates.
/// </summary>
/// <param name="currentServerVersion">The current server version.</param>
/// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>
Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken);
Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(Version currentServerVersion, bool withAutoUpdateEnabled, CancellationToken cancellationToken);
/// <summary>
/// Installs the package.

@ -1004,7 +1004,7 @@ namespace MediaBrowser.Controller.Entities
throw new ArgumentNullException();
}
var list = new List<BaseItem>(10000);
var list = new List<BaseItem>(_children.Count);
AddRecursiveChildrenInternal(user, includeLinkedChildren, list);

@ -1,4 +1,5 @@
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Common;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
@ -23,15 +24,13 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
private readonly IInstallationManager _installationManager;
/// <summary>
/// Initializes a new instance of the <see cref="PluginUpdateTask" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="installationManager">The installation manager.</param>
public PluginUpdateTask(ILogger logger, IInstallationManager installationManager)
private readonly IApplicationHost _appHost;
public PluginUpdateTask(ILogger logger, IInstallationManager installationManager, IApplicationHost appHost)
{
_logger = logger;
_installationManager = installationManager;
_appHost = appHost;
}
/// <summary>
@ -60,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
progress.Report(0);
var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(true, cancellationToken).ConfigureAwait(false)).ToList();
var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(_appHost.ApplicationVersion, true, cancellationToken).ConfigureAwait(false)).ToList();
progress.Report(10);

@ -60,7 +60,6 @@ using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace MediaBrowser.ServerApplication
{
@ -708,7 +707,7 @@ namespace MediaBrowser.ServerApplication
{
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ApplicationVersion, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :
new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false };

Loading…
Cancel
Save