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

Support export folder default values #583

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ private ProvisioningTemplate ProcessLibraryItems(Web web,
string defaultContentTypeId)
{
var itemCount = 1;
var listDefaultColumnValues = siteList.GetDefaultColumnValues();

foreach (var item in items)
{
switch (item.FileSystemObjectType)
Expand All @@ -412,7 +414,7 @@ private ProvisioningTemplate ProcessLibraryItems(Web web,
case FileSystemObjectType.Folder:
{
//PnP:Folder
ProcessFolderRow(web, item, siteList, listInstance, queryConfig, template, scope);
ProcessFolderRow(web, item, siteList, listInstance, queryConfig, listDefaultColumnValues, template, scope);
break;
}
default:
Expand Down Expand Up @@ -705,7 +707,7 @@ private string TokenizeValue(Web web, string fieldTypeAsString, KeyValuePair<str
return value;
}

public Model.Folder ExtractFolderSettings(Web web, List siteList, string serverRelativePathToFolder, PnPMonitoredScope scope, Model.Configuration.Lists.Lists.ExtractListsQueryConfiguration queryConfig)
public Model.Folder ExtractFolderSettings(Web web, List siteList, List<Dictionary<string, string>> listDefaultValues, string serverRelativePathToFolder, PnPMonitoredScope scope, Model.Configuration.Lists.Lists.ExtractListsQueryConfiguration queryConfig)
{
Model.Folder pnpFolder = null;
try
Expand Down Expand Up @@ -806,6 +808,19 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, string serverR
}
}
}

//export PnPFolder default values
if (listDefaultValues != null)
{
var href = Uri.UnescapeDataString(spFolder.ServerRelativeUrl);
href = href.Replace(siteList.RootFolder.ServerRelativeUrl, "/").Replace("//", "/");

var defaultValues = listDefaultValues.Where(dv => dv["Path"] == href);
foreach (var defaultValue in defaultValues)
{
pnpFolder.DefaultColumnValues.Add(defaultValue["Field"], defaultValue["Value"]);
}
}
}
catch (Exception ex)
{
Expand All @@ -814,7 +829,7 @@ public Model.Folder ExtractFolderSettings(Web web, List siteList, string serverR
return pnpFolder;
}

private void ProcessFolderRow(Web web, ListItem listItem, List siteList, ListInstance listInstance, Model.Configuration.Lists.Lists.ExtractListsQueryConfiguration queryConfig, ProvisioningTemplate template, PnPMonitoredScope scope)
private void ProcessFolderRow(Web web, ListItem listItem, List siteList, ListInstance listInstance, Model.Configuration.Lists.Lists.ExtractListsQueryConfiguration queryConfig, List<Dictionary<string, string>> listDefaultValues, ProvisioningTemplate template, PnPMonitoredScope scope)
{
listItem.EnsureProperties(it => it.ParentList.RootFolder.ServerRelativeUrl);
string serverRelativeListUrl = listItem.ParentList.RootFolder.ServerRelativeUrl;
Expand All @@ -833,7 +848,7 @@ private void ProcessFolderRow(Web web, ListItem listItem, List siteList, ListIns
if (pnpFolder == null)
{
string pathToCurrentFolder = string.Format("{0}/{1}", serverRelativeListUrl, string.Join("/", folderSegments.Take(i + 1)));
pnpFolder = ExtractFolderSettings(web, siteList, pathToCurrentFolder, scope, queryConfig);
pnpFolder = ExtractFolderSettings(web, siteList, listDefaultValues, pathToCurrentFolder, scope, queryConfig);
listInstance.Folders.Add(pnpFolder);
}
}
Expand All @@ -843,7 +858,7 @@ private void ProcessFolderRow(Web web, ListItem listItem, List siteList, ListIns
if (childFolder == null)
{
string pathToCurrentFolder = string.Format("{0}/{1}", serverRelativeListUrl, string.Join("/", folderSegments.Take(i + 1)));
childFolder = ExtractFolderSettings(web, siteList, pathToCurrentFolder, scope, queryConfig);
childFolder = ExtractFolderSettings(web, siteList, listDefaultValues, pathToCurrentFolder, scope, queryConfig);
pnpFolder.Folders.Add(childFolder);
}
pnpFolder = childFolder;
Expand Down