From 8ccbe4c1e48b6352e4726536b326d5fcd1f97f44 Mon Sep 17 00:00:00 2001 From: Niels Hartvig Date: Sat, 3 Jun 2017 17:34:31 +0200 Subject: [PATCH 1/3] Adds support for keys in package content --- src/Umbraco.Core/Services/PackagingService.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index fbf3a7ee8f..874ec8d9fa 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -285,6 +285,7 @@ namespace Umbraco.Core.Services var nodeName = element.Attribute("nodeName").Value; var path = element.Attribute("path").Value; var template = element.Attribute("template").Value; + var key = element.Attribute("key") != null ? Guid.Parse(element.Attribute("key").Value) : Guid.Empty; var properties = from property in element.Elements() where property.Attribute("isDoc") == null @@ -302,6 +303,11 @@ namespace Umbraco.Core.Services SortOrder = int.Parse(sortOrder) }; + // update the Guid (for UDI support) + if (key != Guid.Empty) { + content.Key = key; + } + foreach (var property in properties) { string propertyTypeAlias = isLegacySchema ? property.Attribute("alias").Value : property.Name.LocalName; From 73bb401f816a705160fc2e890a35606782fe57a9 Mon Sep 17 00:00:00 2001 From: Niels Hartvig Date: Sat, 3 Jun 2017 18:34:09 +0200 Subject: [PATCH 2/3] Updating to TryParse to make Sir Janssen happy :-) --- src/Umbraco.Core/Services/PackagingService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index 874ec8d9fa..17bebaa881 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -285,7 +285,7 @@ namespace Umbraco.Core.Services var nodeName = element.Attribute("nodeName").Value; var path = element.Attribute("path").Value; var template = element.Attribute("template").Value; - var key = element.Attribute("key") != null ? Guid.Parse(element.Attribute("key").Value) : Guid.Empty; + var key = Guid.Empty; var properties = from property in element.Elements() where property.Attribute("isDoc") == null @@ -303,8 +303,8 @@ namespace Umbraco.Core.Services SortOrder = int.Parse(sortOrder) }; + if (Guid.TryParse(element.Attribute("key").Value, out key)) { // update the Guid (for UDI support) - if (key != Guid.Empty) { content.Key = key; } From 771935b8a565f2e1b71e927b93b675faae3c7458 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sat, 3 Jun 2017 18:36:00 +0200 Subject: [PATCH 3/3] Update PackagingService.cs --- src/Umbraco.Core/Services/PackagingService.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index 17bebaa881..41314d65c8 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -89,18 +89,18 @@ namespace Umbraco.Core.Services /// public string FetchPackageFile(Guid packageId, Version umbracoVersion, int userId) { - var packageRepo = UmbracoConfig.For.UmbracoSettings().PackageRepositories.GetDefault(); + var packageRepo = UmbracoConfig.For.UmbracoSettings().PackageRepositories.GetDefault(); using (var httpClient = new HttpClient()) using (var uow = _uowProvider.GetUnitOfWork()) - { + { //includeHidden = true because we don't care if it's hidden we want to get the file regardless var url = string.Format("{0}/{1}?version={2}&includeHidden=true&asFile=true", packageRepo.RestApiUrl, packageId, umbracoVersion.ToString(3)); byte[] bytes; - try - { - bytes = httpClient.GetByteArrayAsync(url).GetAwaiter().GetResult(); - } + try + { + bytes = httpClient.GetByteArrayAsync(url).GetAwaiter().GetResult(); + } catch (HttpRequestException ex) { throw new ConnectionException("An error occuring downloading the package from " + url, ex); @@ -109,20 +109,20 @@ namespace Umbraco.Core.Services //successfull if (bytes.Length > 0) { - var packagePath = IOHelper.MapPath(SystemDirectories.Packages); + var packagePath = IOHelper.MapPath(SystemDirectories.Packages); // Check for package directory if (Directory.Exists(packagePath) == false) Directory.CreateDirectory(packagePath); - var packageFilePath = Path.Combine(packagePath, packageId + ".umb"); + var packageFilePath = Path.Combine(packagePath, packageId + ".umb"); using (var fs1 = new FileStream(packageFilePath, FileMode.Create)) { fs1.Write(bytes, 0, bytes.Length); return "packages\\" + packageId + ".umb"; } - } + } Audit(uow, AuditType.PackagerInstall, string.Format("Package {0} fetched from {1}", packageId, packageRepo.Id), userId, -1); return null; @@ -133,7 +133,7 @@ namespace Umbraco.Core.Services { var auditRepo = _repositoryFactory.CreateAuditRepository(uow); auditRepo.AddOrUpdate(new AuditItem(objectId, message, type, userId)); - } + } #region Content @@ -303,8 +303,9 @@ namespace Umbraco.Core.Services SortOrder = int.Parse(sortOrder) }; - if (Guid.TryParse(element.Attribute("key").Value, out key)) { - // update the Guid (for UDI support) + if (Guid.TryParse(element.Attribute("key").Value, out key)) + { + // update the Guid (for UDI support) content.Key = key; }