Skip to content

Commit

Permalink
Fix creating folders as root children.
Browse files Browse the repository at this point in the history
  • Loading branch information
BS-jiriceska committed Jul 22, 2024
1 parent 26c8906 commit 62521db
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,31 @@ public WebPageFolderService(
}
}

if (lastExistingFolderIndex == maxFoldersIndex || currentFolder is null)
if (lastExistingFolderIndex == maxFoldersIndex)
{
// Folder is created or invalid path provided.
// Folder is already created.
return currentFolder;
}

int websiteChannelId = await websiteChannelProvider.GetWebsiteChannelId(websiteChannelName, cancellationToken);
var webPageManager = webPageManagerFactory.Create(websiteChannelId, UserInfoProvider.AdministratorUser.UserID);
int currentFolderId = currentFolder.WebPageItemID;
// if null, then current folder is root.
int? currentFolderId = currentFolder?.WebPageItemID;
// Create any necessary folders starting from the first non-existing folder
for (int i = lastExistingFolderIndex + 1; i < folders.Length; i++)
{
string folderToCreate = folders[i];

var createFolderParameters = new CreateFolderParameters(folderToCreate, languageName)
var createFolderParameters = new CreateFolderParameters(folderToCreate, languageName);
if (currentFolderId.HasValue)
{
ParentWebPageItemID = currentFolderId
};
createFolderParameters.ParentWebPageItemID = currentFolderId.Value;
}

currentFolderId = await webPageManager.CreateFolder(createFolderParameters, cancellationToken);
}

// Folder is already created
// Folder is now created
return await GetFolderByPath(folderPath, websiteChannelName);
}

Expand Down

0 comments on commit 62521db

Please sign in to comment.