Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposes the entity containers (folders) created during a package installation in the summary available from the ImportedPackageNotification. #11303

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public InstallationSummary InstallPackageData(CompiledPackage compiledPackage, i
return installationSummary;
}
}

/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
/// <param name="docTypeElements">Xml to import</param>
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IMediaType> ImportMediaTypes(IEnumerable<XElement> docTypeElements, int userId)
=> ImportMediaTypes(docTypeElements, userId, new List<EntityContainer>());
AndyButland marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
Expand Down Expand Up @@ -413,6 +423,15 @@ private TContentBase CreateContent<TContentBase, TContentTypeComposition>(string
public IReadOnlyList<IContentType> ImportDocumentType(XElement docTypeElement, int userId)
=> ImportDocumentTypes(new[] { docTypeElement }, userId, new List<EntityContainer>());

/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
/// <param name="docTypeElements">Xml to import</param>
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<IContentType> ImportDocumentTypes(IEnumerable<XElement> docTypeElements, int userId)
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, new List<EntityContainer>(), _contentTypeService);

/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
Expand All @@ -423,6 +442,17 @@ public IReadOnlyList<IContentType> ImportDocumentType(XElement docTypeElement, i
public IReadOnlyList<IContentType> ImportDocumentTypes(IEnumerable<XElement> docTypeElements, int userId, List<EntityContainer> entityContainersInstalled)
AndyButland marked this conversation as resolved.
Show resolved Hide resolved
=> ImportDocumentTypes(docTypeElements.ToList(), true, userId, entityContainersInstalled, _contentTypeService);

/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
/// <param name="unsortedDocumentTypes">Xml to import</param>
/// <param name="importStructure">Boolean indicating whether or not to import the </param>
/// <param name="userId">Optional id of the User performing the operation. Default is zero (admin).</param>
/// <returns>An enumerable list of generated ContentTypes</returns>
public IReadOnlyList<T> ImportDocumentTypes<T>(IReadOnlyCollection<XElement> unsortedDocumentTypes, bool importStructure, int userId, IContentTypeBaseService<T> service)
where T : class, IContentTypeComposition
=> ImportDocumentTypes(unsortedDocumentTypes, importStructure, userId, new List<EntityContainer>(), service);

/// <summary>
/// Imports and saves package xml as <see cref="IContentType"/>
/// </summary>
Expand Down Expand Up @@ -596,6 +626,7 @@ private Dictionary<string, int> CreateContentTypeFolderStructure(IEnumerable<XEl
var folderName = WebUtility.UrlDecode(folders[i]);
Guid? folderKey = (folderKeys.Length == folders.Length) ? folderKeys[i] : null;
current = CreateContentTypeChildFolder(folderName, folderKey ?? Guid.NewGuid(), current);
entityContainersInstalled.Add(current);
importedFolders[alias] = current.Id;
}
}
Expand Down Expand Up @@ -1012,6 +1043,15 @@ private T FindContentTypeByAlias<T>(string contentTypeAlias, IContentTypeBaseSer

#region DataTypes

/// <summary>
/// Imports and saves package xml as <see cref="IDataType"/>
/// </summary>
/// <param name="dataTypeElements">Xml to import</param>
/// <param name="userId">Optional id of the user</param>
/// <returns>An enumerable list of generated DataTypeDefinitions</returns>
public IReadOnlyList<IDataType> ImportDataTypes(IReadOnlyCollection<XElement> dataTypeElements, int userId)
=> ImportDataTypes(dataTypeElements, userId, new List<EntityContainer>());

/// <summary>
/// Imports and saves package xml as <see cref="IDataType"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ public void Can_Import_uBlogsy_ContentTypes_And_Verify_Structure()
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypes = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypes = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<ITemplate> templates = PackageDataInstallation.ImportTemplates(templateElement.Elements("Template").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);

int numberOfTemplates = (from doc in templateElement.Elements("Template") select doc).Count();
int numberOfDocTypes = (from doc in docTypeElement.Elements("DocumentType") select doc).Count();
Expand Down Expand Up @@ -142,10 +141,9 @@ public void Can_Import_Inherited_ContentTypes_And_Verify_PropertyTypes_UniqueIds
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypes = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypes = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<ITemplate> templates = PackageDataInstallation.ImportTemplates(templateElement.Elements("Template").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);

// Assert
IContentType mRBasePage = contentTypes.First(x => x.Alias == "MRBasePage");
Expand All @@ -168,10 +166,9 @@ public void Can_Import_Inherited_ContentTypes_And_Verify_PropertyGroups_And_Prop
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypes = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypes = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<ITemplate> templates = PackageDataInstallation.ImportTemplates(templateElement.Elements("Template").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);

int numberOfDocTypes = (from doc in docTypeElement.Elements("DocumentType") select doc).Count();

Expand Down Expand Up @@ -277,10 +274,9 @@ public void Can_Import_StandardMvc_ContentTypes_Package_Xml()
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<ITemplate> templates = PackageDataInstallation.ImportTemplates(templateElement.Elements("Template").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);
int numberOfDocTypes = (from doc in docTypeElement.Elements("DocumentType") select doc).Count();

// Assert
Expand Down Expand Up @@ -313,14 +309,13 @@ public void Can_Import_StandardMvc_ContentTypes_And_Templates_Xml()
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<ITemplate> templates = PackageDataInstallation.ImportTemplates(templateElement.Elements("Template").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);
int numberOfDocTypes = (from doc in docTypeElement.Elements("DocumentType") select doc).Count();

// Assert - Re-Import contenttypes doesn't throw
Assert.DoesNotThrow(() => PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled));
Assert.DoesNotThrow(() => PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0));
Assert.That(contentTypes.Count(), Is.EqualTo(numberOfDocTypes));
Assert.That(dataTypeDefinitions, Is.Not.Null);
Assert.That(dataTypeDefinitions.Any(), Is.True);
Expand All @@ -338,14 +333,13 @@ public void Can_Import_Fanoe_Starterkit_ContentTypes_And_Templates_Xml()
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<ITemplate> templates = PackageDataInstallation.ImportTemplates(templateElement.Elements("Template").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);
int numberOfDocTypes = (from doc in docTypeElement.Elements("DocumentType") select doc).Count();

// Assert - Re-Import contenttypes doesn't throw
Assert.DoesNotThrow(() => PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled));
Assert.DoesNotThrow(() => PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0));
Assert.That(contentTypes.Count(), Is.EqualTo(numberOfDocTypes));
Assert.That(dataTypeDefinitions, Is.Not.Null);
Assert.That(dataTypeDefinitions.Any(), Is.True);
Expand All @@ -364,9 +358,8 @@ public void Can_Import_Content_Package_Xml()
var packageDocument = CompiledPackageContentBase.Create(element);

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypesElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypesElement.Elements("DocumentType"), 0);
var importedContentTypes = contentTypes.ToDictionary(x => x.Alias, x => x);
IReadOnlyList<IContent> contents = PackageDataInstallation.ImportContentBase(packageDocument.Yield(), importedContentTypes, 0, ContentTypeService, ContentService);
int numberOfDocs = (from doc in element.Descendants()
Expand All @@ -392,8 +385,7 @@ public void Can_Import_Media_Package_Xml()
var packageMedia = CompiledPackageContentBase.Create(element);

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IMediaType> mediaTypes = PackageDataInstallation.ImportMediaTypes(mediaTypesElement.Elements("MediaType"), 0, entityContainersInstalled);
IReadOnlyList<IMediaType> mediaTypes = PackageDataInstallation.ImportMediaTypes(mediaTypesElement.Elements("MediaType"), 0);
var importedMediaTypes = mediaTypes.ToDictionary(x => x.Alias, x => x);
IReadOnlyList<IMedia> medias = PackageDataInstallation.ImportContentBase(packageMedia.Yield(), importedMediaTypes, 0, MediaTypeService, MediaService);
int numberOfDocs = (from doc in element.Descendants()
Expand Down Expand Up @@ -421,9 +413,8 @@ private void AssertCheckBoxListTests(string strXml)
var packageDocument = CompiledPackageContentBase.Create(element);

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypesElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IDataType> dataTypeDefinitions = PackageDataInstallation.ImportDataTypes(dataTypeElement.Elements("DataType").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypesElement.Elements("DocumentType"), 0);
var importedContentTypes = contentTypes.ToDictionary(x => x.Alias, x => x);
IReadOnlyList<IContent> contents = PackageDataInstallation.ImportContentBase(packageDocument.Yield(), importedContentTypes, 0, ContentTypeService, ContentService);
int numberOfDocs = (from doc in element.Descendants()
Expand Down Expand Up @@ -733,9 +724,8 @@ public void Can_Import_Package_With_Compositions()
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<ITemplate> templates = PackageDataInstallation.ImportTemplates(templateElement.Elements("Template").ToList(), 0);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);
int numberOfDocTypes = (from doc in docTypeElement.Elements("DocumentType") select doc).Count();

// Assert
Expand All @@ -761,8 +751,7 @@ public void Can_Import_Package_With_Compositions_Ordered()
XElement docTypeElement = xml.Descendants("DocumentTypes").First();

// Act
var entityContainersInstalled = new List<EntityContainer>();
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0, entityContainersInstalled);
IReadOnlyList<IContentType> contentTypes = PackageDataInstallation.ImportDocumentTypes(docTypeElement.Elements("DocumentType"), 0);
int numberOfDocTypes = (from doc in docTypeElement.Elements("DocumentType") select doc).Count();

// Assert
Expand Down