Skip to content

Commit

Permalink
feat: Add ExecuteQueryRetry to Admin commands for improved reliability (
Browse files Browse the repository at this point in the history
pnp#3988)

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
gautamdsheth and Gautam Sheth authored May 30, 2024
1 parent 0d8c5ba commit 1d475e7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Commands/Admin/SetHomeSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override void ExecuteCmdlet()
Tenant.RemoveTargetedSite(enumerable.First().SiteId);
AdminContext.ExecuteQueryRetry();
Tenant.AddHomeSite(HomeSiteUrl, 1, null);
AdminContext.ExecuteQuery();
AdminContext.ExecuteQueryRetry();
flag = true;
}
HomeSiteConfigurationParam configurationParam = new()
Expand Down
28 changes: 15 additions & 13 deletions src/Commands/Admin/UnlockSensitivityLabelEncryptedFile.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using Microsoft.SharePoint.Client;
using PnP.PowerShell.Commands.Base;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Files
{
[Cmdlet(VerbsCommon.Unlock, "PnPSensitivityLabelEncryptedFile")]
public class UnlockSensitivityLabelEncryptedFile : PnPAdminCmdlet
[Cmdlet(VerbsCommon.Unlock, "PnPSensitivityLabelEncryptedFile")]
public class UnlockSensitivityLabelEncryptedFile : PnPAdminCmdlet
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public string Url = string.Empty;

[Parameter(Mandatory = true)]
public string JustificationText = string.Empty;
protected override void ExecuteCmdlet()
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public string Url = string.Empty;
[Parameter(Mandatory = true)]
public string JustificationText = string.Empty;
protected override void ExecuteCmdlet()
{
// Remove URL decoding from the Url as that will not work. We will encode the + character specifically, because if that is part of the filename, it needs to stay and not be decoded.
Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B"));
// Remove URL decoding from the Url as that will not work. We will encode the + character specifically, because if that is part of the filename, it needs to stay and not be decoded.
Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B"));

Tenant.UnlockSensitivityLabelEncryptedFile(Url, JustificationText);
AdminContext.ExecuteQuery();
}
Tenant.UnlockSensitivityLabelEncryptedFile(Url, JustificationText);
AdminContext.ExecuteQueryRetry();
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/InformationManagement/ResetRetentionLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected override void ExecuteCmdlet()

WriteVerbose($"Clearing retention label on batch {rangeIndex} of items");
Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy.SetComplianceTagOnBulkItems(ClientContext, range, rootUrl + list.RootFolder.ServerRelativeUrl, string.Empty);
ClientContext.ExecuteQuery();
ClientContext.ExecuteQueryRetry();

ItemIds.RemoveRange(0, itemsToProcess);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/InformationManagement/SetRetentionLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ protected override void ExecuteCmdlet()
if (ParameterSetName == ParamSet_BulkItems)
{
PnPContext.Web.LoadAsync(i => i.Url);
list.LoadAsync(i => i.RootFolder);

list.LoadAsync(i => i.RootFolder);

var rootUrl = PnPContext.Web.Url.GetLeftPart(UriPartial.Authority);

Expand All @@ -87,7 +86,7 @@ protected override void ExecuteCmdlet()

WriteVerbose($"Setting retention label to batch {rangeIndex} of items");
Microsoft.SharePoint.Client.CompliancePolicy.SPPolicyStoreProxy.SetComplianceTagOnBulkItems(ClientContext, range, rootUrl + list.RootFolder.ServerRelativeUrl, Label);
ClientContext.ExecuteQuery();
ClientContext.ExecuteQueryRetry();
ItemIds.RemoveRange(0, itemsToProcess);
}
}
Expand Down

0 comments on commit 1d475e7

Please sign in to comment.