Skip to content

Commit

Permalink
Merged main into feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperweber committed May 8, 2023
2 parents 6836341 + 0053290 commit 8490a10
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public IComponentBuilder Populate(int parentFolderId)
{
Alias = Alias,
Name = Name,
IsElement = true
IsElement = true,
Icon = "icon-item-arrangement"
};

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public class DocumentTypeBuilder : IDocumentTypeBuilder
private readonly UmbracoMigrationConfiguration _umbracoMigrationConfiguration;
private readonly IEnumerable<string> _contentTypeAliasList;
private const string PagesFolderName = "Migrated Page Types";
private const string CompositionsFolderName = "Compositions";
private const string CompositionsFolderName = "Migrated Compositions";
private const string ComponentsFolderName = "Migrated Components";
private const string DataTypeFolderName = "Migrated Data Types";
private const string BlockListName = "BlockList.Custom";
private readonly EnterspeedConfiguration _enterspeedConfiguration;

Expand Down Expand Up @@ -65,9 +66,10 @@ public void BuildDocTypes(Schemas schemas)
{
try
{
var pagesFolder = GetOrCreateFolder(PagesFolderName);
var componentsFolder = GetOrCreateFolder(ComponentsFolderName);
var compositionsFolder = GetOrCreateFolder(CompositionsFolderName);
var pagesFolder = GetOrCreateDocumentTypeFolder(PagesFolderName);
var componentsFolder = GetOrCreateDocumentTypeFolder(ComponentsFolderName);
var compositionsFolder = GetOrCreateDocumentTypeFolder(CompositionsFolderName);
var dataTypeFolder = GetOrCreateDataTypeFolder(DataTypeFolderName);

// Build components
foreach (var componentAlias in _enterspeedConfiguration.ComponentPropertyTypeKeys)
Expand All @@ -77,7 +79,7 @@ public void BuildDocTypes(Schemas schemas)

// TODO: Assumption. This needs to be handled in a different way.
// Create block list data type, and add config with all element types
CreateBlockListDataType();
CreateBlockListDataType(dataTypeFolder);

// Create pages
foreach (var page in schemas.Pages)
Expand All @@ -92,10 +94,10 @@ public void BuildDocTypes(Schemas schemas)
}
}

private void CreateBlockListDataType()
private void CreateBlockListDataType(IEntity dataTypeFolder)
{
// Create data type
var dataType = new DataType(_blockListPropertyEditor, _configurationEditorJsonSerializer)
var dataType = new DataType(_blockListPropertyEditor, _configurationEditorJsonSerializer, dataTypeFolder.Id)
{
Name = BlockListName
};
Expand Down Expand Up @@ -149,7 +151,8 @@ private ContentType BuildNewPageDocType(Schema page, IEntity pagesFolder)
Alias = page.MetaSchema.SourceEntityAlias.ToFirstLowerInvariant(),
Name = page.MetaSchema.SourceEntityName.ToUmbracoName(),
AllowedAsRoot = string.Equals(page.MetaSchema.SourceEntityAlias, _umbracoMigrationConfiguration.RootDocType,
StringComparison.InvariantCultureIgnoreCase)
StringComparison.InvariantCultureIgnoreCase),
Icon = "icon-item-arrangement"
};

return newPageDocumentType;
Expand All @@ -161,7 +164,8 @@ private IContentType CreateComposition(IEntity compositionsFolder, EnterspeedPro
{
Alias = enterspeedProperty.Alias,
Name = enterspeedProperty.Name.ToFirstUpper(),
IsElement = true
IsElement = true,
Icon = "icon-item-arrangement"
};

return composition;
Expand Down Expand Up @@ -272,7 +276,7 @@ private void AddProperties(EnterspeedPropertyType enterspeedProperty, IContentTy
}
}

private EntityContainer GetOrCreateFolder(string folderName)
private EntityContainer GetOrCreateDocumentTypeFolder(string folderName)
{
var createContainerAttempt = _contentTypeService.CreateContainer(-1, Guid.NewGuid(), folderName);
if (createContainerAttempt.Success)
Expand All @@ -290,6 +294,24 @@ private EntityContainer GetOrCreateFolder(string folderName)
return existingContainer;
}

private EntityContainer GetOrCreateDataTypeFolder(string folderName)
{
var createContainerAttempt = _dataTypeService.CreateContainer(-1, Guid.NewGuid(), folderName);
if (createContainerAttempt.Success)
{
var containerSaved = _dataTypeService.SaveContainer(createContainerAttempt.Result.Entity);
if (containerSaved.Success)
{
return createContainerAttempt.Result.Entity;
}

_logger.LogError(containerSaved.Exception, $"Something went wrong when saving folder {folderName}");
}

var existingContainer = _dataTypeService.GetContainers(folderName, 1).FirstOrDefault();
return existingContainer;
}

private static JsonValueKind GetValueKindOfFirstElementInArray(EnterspeedPropertyType enterspeedProperty)
{
var valueKind = JsonValueKind.Undefined;
Expand Down

0 comments on commit 8490a10

Please sign in to comment.