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

Added support for disabling loading all site collection term groups #1069

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -49,6 +49,7 @@ public Dictionary<String, String> AccessTokens

[JsonPropertyName("parameters")]
public Dictionary<string, string> Parameters { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Defines Tenant Extraction Settings
/// </summary>
Expand All @@ -73,24 +74,32 @@ public Dictionary<String, String> AccessTokens
[JsonPropertyName("extensibility")]
public Extensibility.ApplyExtensibilityConfiguration Extensibility { get; set; } = new Extensibility.ApplyExtensibilityConfiguration();

/// <summary>
/// Specifies whether to also load site collection term groups when initializing the <see cref="TokenParser"/>. If
/// <c>false</c>, only normal term groups will be loaded. This does not affect loading the site collection term group
/// when one of the <c>sitecollectionterm</c> tokens was found.
/// </summary>
[JsonPropertyName("loadSiteCollectionTermGroups")]
public bool LoadSiteCollectionTermGroups { get; set; } = true;

public ProvisioningTemplateApplyingInformation ToApplyingInformation()
{
var ai = new ProvisioningTemplateApplyingInformation
{
ApplyConfiguration = this
ApplyConfiguration = this,
ProvisionContentTypesToSubWebs = this.ContentTypes.ProvisionContentTypesToSubWebs,
OverwriteSystemPropertyBagValues = this.PropertyBag.OverwriteSystemValues,
IgnoreDuplicateDataRowErrors = this.Lists.IgnoreDuplicateDataRowErrors,
ClearNavigation = this.Navigation.ClearNavigation,
ProvisionFieldsToSubWebs = this.Fields.ProvisionFieldsToSubWebs,
LoadSiteCollectionTermGroups = LoadSiteCollectionTermGroups
};

if (this.AccessTokens != null && this.AccessTokens.Any())
{
ai.AccessTokens = this.AccessTokens;
}

ai.ProvisionContentTypesToSubWebs = this.ContentTypes.ProvisionContentTypesToSubWebs;
ai.OverwriteSystemPropertyBagValues = this.PropertyBag.OverwriteSystemValues;
ai.IgnoreDuplicateDataRowErrors = this.Lists.IgnoreDuplicateDataRowErrors;
ai.ClearNavigation = this.Navigation.ClearNavigation;
ai.ProvisionFieldsToSubWebs = this.Fields.ProvisionFieldsToSubWebs;

if (Handlers.Any())
{
ai.HandlersToProcess = Model.Handlers.None;
Expand Down Expand Up @@ -178,12 +187,13 @@ public static ApplyConfiguration FromApplyingInformation(ProvisioningTemplateApp
config.ContentTypes.ProvisionContentTypesToSubWebs = information.ProvisionContentTypesToSubWebs;
config.Fields.ProvisionFieldsToSubWebs = information.ProvisionFieldsToSubWebs;
config.SiteProvisionedDelegate = information.SiteProvisionedDelegate;
config.LoadSiteCollectionTermGroups = information.LoadSiteCollectionTermGroups;

return config;
}

public static ApplyConfiguration FromString(string input)
{

return JsonSerializer.Deserialize<ApplyConfiguration>(input);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplat
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ComposedLooks_ExtractObjects_Creating_SharePointConnector);
// Let's create a SharePoint connector since our files anyhow are in SharePoint at this moment
TokenParser parser = new TokenParser(web, template);
var parser = new TokenParser(web, template, new ProvisioningTemplateApplyingInformation { LoadSiteCollectionTermGroups = creationInfo.LoadSiteCollectionTermGroups });
DownLoadFile(spConnector, spConnectorRoot, creationInfo.FileConnector, web.Url, parser.ParseString(composedLook.BackgroundFile), scope);
DownLoadFile(spConnector, spConnectorRoot, creationInfo.FileConnector, web.Url, parser.ParseString(composedLook.ColorFile), scope);
DownLoadFile(spConnector, spConnectorRoot, creationInfo.FileConnector, web.Url, parser.ParseString(composedLook.FontFile), scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public override TokenParser ProvisionObjects(Tenant tenant, Model.ProvisioningHi
//}
//else
//{
// siteTokenParser.Rebase(web, provisioningTemplate);
// siteTokenParser.Rebase(web, provisioningTemplate, provisioningTemplateApplyingInformation);
//}
WriteMessage($"Applying Template", ProvisioningMessageType.Progress);
new SiteToTemplateConversion().ApplyRemoteTemplate(web, provisioningTemplate, provisioningTemplateApplyingInformation, true, siteTokenParser);
Expand Down Expand Up @@ -871,7 +871,7 @@ private TokenParser ApplySubSiteTemplates(ProvisioningHierarchy hierarchy, Token
provisioningTemplate.Connector = hierarchy.Connector;
if (tokenParser == null)
{
tokenParser = new TokenParser(subweb, provisioningTemplate);
tokenParser = new TokenParser(subweb, provisioningTemplate, provisioningTemplateApplyingInformation);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Microsoft.Online.SharePoint.TenantAdministration;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using PnP.Framework.Diagnostics;
using PnP.Framework.Provisioning.Model;
using PnP.Framework.Provisioning.Model.Configuration;
using PnP.Framework.Provisioning.ObjectHandlers.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using Term = Microsoft.SharePoint.Client.Taxonomy.Term;
using TermGroup = Microsoft.SharePoint.Client.Taxonomy.TermGroup;

namespace PnP.Framework.Provisioning.ObjectHandlers
{
Expand All @@ -25,26 +26,46 @@ public override TokenParser ProvisionObjects(Tenant tenant, Model.ProvisioningHi
{
foreach (var sequence in hierarchy.Sequences)
{

this.reusedTerms = new List<TermGroupHelper.ReusedTerm>();

var context = tenant.Context as ClientContext;

TaxonomySession taxSession = TaxonomySession.GetTaxonomySession(context);
TermStore termStore = null;
TermStore termStore;
IEnumerable<TermGroup> termGroups;

try
{
termStore = taxSession.GetDefaultKeywordsTermStore();
context.Load(termStore,
ts => ts.Languages,
ts => ts.DefaultLanguage,
ts => ts.Groups.Include(
tg => tg.Name,
tg => tg.Id,
tg => tg.TermSets.Include(
tset => tset.Name,
tset => tset.Id)));
context.Load(termStore, ts => ts.Languages, ts => ts.DefaultLanguage);

if (configuration.LoadSiteCollectionTermGroups)
{
termGroups = termStore.Groups;

context.Load(
termStore.Groups,
groups => groups.Include(
group => group.Name,
group => group.Id,
group => group.TermSets.Include(
termSet => termSet.Name,
termSet => termSet.Id)
));
}
else
{
termGroups = context.LoadQuery(termStore
.Groups
.Where(group => !group.IsSiteCollectionGroup)
.Include(
group => group.Name,
group => group.Id,
group => group.TermSets.Include(
termSet => termSet.Name,
termSet => termSet.Id)));
}

context.ExecuteQueryRetry();
}
catch (ServerException)
Expand All @@ -56,7 +77,7 @@ public override TokenParser ProvisionObjects(Tenant tenant, Model.ProvisioningHi

foreach (var modelTermGroup in sequence.TermStore.TermGroups)
{
this.reusedTerms.AddRange(TermGroupHelper.ProcessGroup(context, taxSession, termStore, modelTermGroup, null, parser, scope));
this.reusedTerms.AddRange(TermGroupHelper.ProcessGroup(context, taxSession, termStore, termGroups, modelTermGroup, null, parser, scope));
}

foreach (var reusedTerm in this.reusedTerms)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using PnP.Framework.Diagnostics;
using PnP.Framework.Provisioning.ObjectHandlers.TokenDefinitions;
using PnP.Framework.Provisioning.ObjectHandlers.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PnP.Framework.Provisioning.ObjectHandlers
{
Expand All @@ -24,22 +23,44 @@ public override TokenParser ProvisionObjects(Web web, Model.ProvisioningTemplate
this.reusedTerms = new List<TermGroupHelper.ReusedTerm>();

TaxonomySession taxSession = TaxonomySession.GetTaxonomySession(web.Context);
TermStore termStore = null;
TermGroup siteCollectionTermGroup = null;
TermStore termStore;
TermGroup siteCollectionTermGroup;
IEnumerable<TermGroup> termGroups;

try
{
termStore = taxSession.GetDefaultKeywordsTermStore();
web.Context.Load(termStore,
ts => ts.Languages,
ts => ts.DefaultLanguage,
ts => ts.Groups.Include(
tg => tg.Name,
tg => tg.Id,
tg => tg.TermSets.Include(
tset => tset.Name,
tset => tset.Id)));

web.Context.Load(termStore, ts => ts.Languages, ts => ts.DefaultLanguage);
siteCollectionTermGroup = termStore.GetSiteCollectionGroup((web.Context as ClientContext).Site, false);

if (applyingInformation.LoadSiteCollectionTermGroups)
{
termGroups = termStore.Groups;

web.Context.Load(
termStore.Groups,
groups => groups.Include(
group => group.Name,
group => group.Id,
group => group.TermSets.Include(
termSet => termSet.Name,
termSet => termSet.Id)
));
}
else
{
termGroups = web.Context.LoadQuery(termStore
.Groups
.Where(group => !group.IsSiteCollectionGroup)
.Include(
group => group.Name,
group => group.Id,
group => group.TermSets.Include(
termSet => termSet.Name,
termSet => termSet.Id)));
}

web.Context.Load(siteCollectionTermGroup);
web.Context.ExecuteQueryRetry();
}
Expand All @@ -52,12 +73,9 @@ public override TokenParser ProvisionObjects(Web web, Model.ProvisioningTemplate
return parser;
}

SiteCollectionTermGroupNameToken siteCollectionTermGroupNameToken =
new SiteCollectionTermGroupNameToken(web);

foreach (var modelTermGroup in template.TermGroups)
{
this.reusedTerms.AddRange(TermGroupHelper.ProcessGroup(web.Context as ClientContext, taxSession, termStore, modelTermGroup, siteCollectionTermGroup, parser, scope));
this.reusedTerms.AddRange(TermGroupHelper.ProcessGroup(web.Context as ClientContext, taxSession, termStore, termGroups, modelTermGroup, siteCollectionTermGroup, parser, scope));
}

foreach (var reusedTerm in this.reusedTerms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ public partial class ProvisioningTemplateApplyingInformation
{
private Handlers handlersToProcess = Handlers.All;
private List<ExtensibilityHandler> extensibilityHandlers = new List<ExtensibilityHandler>();
private Dictionary<String, String> _accessTokens;

public ProvisioningProgressDelegate ProgressDelegate { get; set; }

public ProvisioningMessagesDelegate MessagesDelegate { get; set; }

public ProvisioningSiteProvisionedDelegate SiteProvisionedDelegate { get; set; }

internal ApplyConfiguration ApplyConfiguration { get; set; }

/// <summary>
/// If true then persists template information
/// </summary>
public bool PersistTemplateInfo { get; set; } = true;

/// <summary>
/// If true, system propertybag entries that start with _, vti_, dlc_ etc. will be overwritten if overwrite = true on the PropertyBagEntry. If not true those keys will be skipped, regardless of the overwrite property of the entry.
/// </summary>
Expand All @@ -53,6 +58,7 @@ public partial class ProvisioningTemplateApplyingInformation
/// If true, existing navigation nodes of the site (where applicable) will be cleared out before applying the navigation nodes from the template (if any). This setting will override any settings made in the template.
/// </summary>
public bool ClearNavigation { get; set; }

/// <summary>
/// If true then duplicate id errors when the same importing datarows simply generate a warning don't stop the engine. Reason for this is being able to apply the same template multiple times (Delta handling)
/// without that failing cause the same record is being added twice
Expand All @@ -69,6 +75,13 @@ public partial class ProvisioningTemplateApplyingInformation
/// </summary>
public bool ProvisionFieldsToSubWebs { get; set; }

/// <summary>
/// Specifies whether to also load site collection term groups when initializing the <see cref="TokenParser"/>. If
/// <c>false</c>, only normal term groups will be loaded. This does not affect loading the site collection term group
/// when one of the <c>sitecollectionterm</c> tokens was found.
/// </summary>
public bool LoadSiteCollectionTermGroups { get; set; } = true;

/// <summary>
/// Lists of Handlers to process
/// </summary>
Expand Down Expand Up @@ -100,8 +113,6 @@ public List<ExtensibilityHandler> ExtensibilityHandlers
}
}

private Dictionary<String, String> _accessTokens;

/// <summary>
/// Allows to provide a dictionary of custom OAuth access tokens
/// when working across different URLs during provisioning and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ public bool IncludeHiddenLists
/// </remarks>
public List<String> ListsToExtract { get; set; } = new List<String>();

/// <summary>
/// Specifies whether to also load site collection term groups when initializing the <see cref="TokenParser"/>. If
/// <c>false</c>, only normal term groups will be loaded. This does not affect loading the site collection term group
/// when one of the <c>sitecollectionterm</c> tokens was found.
/// </summary>
public bool LoadSiteCollectionTermGroups { get; set; } = true;

/// <summary>
/// List which contains information about resource tokens used and/or created during the extraction of a template.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ internal void ApplyTenantTemplate(Tenant tenant, PnP.Framework.Provisioning.Mode

int step = 2;

TokenParser sequenceTokenParser = new TokenParser(tenant, hierarchy);
TokenParser sequenceTokenParser = new TokenParser(tenant, hierarchy, new ProvisioningTemplateApplyingInformation { LoadSiteCollectionTermGroups = configuration.LoadSiteCollectionTermGroups });

CallWebHooks(hierarchy.Templates.FirstOrDefault(), sequenceTokenParser,
ProvisioningTemplateWebhookKind.ProvisioningStarted);
Expand Down Expand Up @@ -414,7 +414,7 @@ internal void ApplyRemoteTemplate(Web web, ProvisioningTemplate template, Provis
progressDelegate?.Invoke("Initializing engine", 1, count); // handlers + initializing message)
if (tokenParser == null)
{
tokenParser = new TokenParser(web, template);
tokenParser = new TokenParser(web, template, provisioningInfo);
}
if (provisioningInfo.HandlersToProcess.HasFlag(Handlers.ExtensibilityProviders))
{
Expand Down
Loading
Loading