From 1beedba67d707360ec906668ee416e9af2364a4b Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 11 May 2017 14:02:49 +1000 Subject: [PATCH] Fixes U4-9887 Uses new OUR endpoint for package installation when a package has mixed formats --- .../Services/PackageRepositoryService.cs | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/OurUmbraco/Repository/Services/PackageRepositoryService.cs b/OurUmbraco/Repository/Services/PackageRepositoryService.cs index 9cb6d7cc..ed5a2c92 100644 --- a/OurUmbraco/Repository/Services/PackageRepositoryService.cs +++ b/OurUmbraco/Repository/Services/PackageRepositoryService.cs @@ -230,6 +230,8 @@ namespace OurUmbraco.Repository.Services //get the strict packages in the correct desc order var strictPackageFileVersions = GetAllStrictSupportedPackageVersions(allPackageFiles).ToArray(); + //these are ordered by package version desc + var nonStrictPackageFiles = GetNonStrictSupportedPackageVersions(allPackageFiles).ToArray(); var packageDetails = new PackageDetails(package) { @@ -259,31 +261,7 @@ namespace OurUmbraco.Repository.Services else if (currentUmbracoVersion < version75) { //if the umbraco version is < 7.5 it means that strict package formats are not supported - - //TODO: Now we have to do the opposite of below and filter out any package file versions that have strict - // umbraco dependencies applied. Anything that has 7.5 (which would be the very minimum strict dependency) we can check for - - //these are ordered by package version desc - var nonStrictPackageFiles = GetNonStrictSupportedPackageVersions(allPackageFiles).ToArray(); - - if (nonStrictPackageFiles.Length != 0) - { - //there might be a case where the 'current release file' is not the latest version found, so let's check if - //the latest release file is included in the non-strict packages and if so we'll use that, otherwise we'll use the latest - var found = nonStrictPackageFiles.FirstOrDefault(x => x.FileId == currentReleaseFile); - if (found != null) - { - //it's included in the non strict packages so use it - packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", currentReleaseFile); - packageDetails.ZipFileId = currentReleaseFile; - } - else - { - //use the latest available package version - packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", nonStrictPackageFiles[0].FileId); - packageDetails.ZipFileId = nonStrictPackageFiles[0].FileId; - } - } + AssignLatestNonStrictPackageFile(nonStrictPackageFiles, currentReleaseFile, packageDetails); } else { @@ -307,7 +285,15 @@ namespace OurUmbraco.Repository.Services //got one! so use it's id for the file download packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", found); packageDetails.ZipFileId = found; - } + } + else if (nonStrictPackageFiles.Length > 0) + { + //Here's the other case, if this package has both strict and non-strict package file versions and we didn't find one above, + //than we need to determine if the latest non-strict package file format should be used for the current version being passed in + + AssignLatestNonStrictPackageFile(nonStrictPackageFiles, currentReleaseFile, packageDetails); + } + } packageDetails.Created = content.CreateDate; @@ -315,6 +301,28 @@ namespace OurUmbraco.Repository.Services return packageDetails; } + private void AssignLatestNonStrictPackageFile(PackageVersionSupport[] nonStrictPackageFiles, int currentReleaseFile, PackageDetails packageDetails) + { + if (nonStrictPackageFiles.Length > 0) + { + //there might be a case where the 'current release file' is not the latest version found, so let's check if + //the latest release file is included in the non-strict packages and if so we'll use that, otherwise we'll use the latest + var found = nonStrictPackageFiles.FirstOrDefault(x => x.FileId == currentReleaseFile); + if (found != null) + { + //it's included in the non strict packages so use it + packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", currentReleaseFile); + packageDetails.ZipFileId = currentReleaseFile; + } + else + { + //use the latest available package version + packageDetails.ZipUrl = string.Concat(BASE_URL, "/FileDownload?id=", nonStrictPackageFiles[0].FileId); + packageDetails.ZipFileId = nonStrictPackageFiles[0].FileId; + } + } + } + private List GetPackageCompatibility(IPublishedContent content) { var service = new VersionCompatibilityService(DatabaseContext);