diff --git a/CHANGELOG.md b/CHANGELOG.md index c9b916f82..d69c0b998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [2.27.1806.0] +### Added + +### Changed + +### Deprecated + +### Contributors + +## [2.26.1805.1] +### Added + +- Added -Timeout option to Add-PnPApp +- Added -CollapseSpecification option to Submit-PnPSearchQuery +- Added -InSiteHierarchy to Get-PnPField to search for fields in the site collection + +### Changed +- Fix for issue where using Add-PnPFile and setting Created and Modified did not update values + ## [2.26.1805.0] ### Added - Added Enable-PnPPowerShellTelemetry, Disable-PnPPowerShellTelemetry, Get-PnPPowershellTelemetryEnabled diff --git a/Commands/Apps/AddApp.cs b/Commands/Apps/AddApp.cs index 47079f99e..1f2aeedcc 100644 --- a/Commands/Apps/AddApp.cs +++ b/Commands/Apps/AddApp.cs @@ -41,6 +41,9 @@ public class AddApp : PnPCmdlet [Parameter(Mandatory = false, HelpMessage = "Overwrites the existing app package if it already exists")] public SwitchParameter Overwrite; + [Parameter(Mandatory = false, HelpMessage = "Specifies the timeout in seconds. Defaults to 200.")] + public int Timeout = 200; + protected override void ExecuteCmdlet() { if (!System.IO.Path.IsPathRooted(Path)) @@ -54,7 +57,7 @@ protected override void ExecuteCmdlet() var manager = new AppManager(ClientContext); - var result = manager.Add(bytes, fileInfo.Name, Overwrite, Scope); + var result = manager.Add(bytes, fileInfo.Name, Overwrite, Scope, timeoutSeconds: Timeout); try { diff --git a/Commands/Base/PnPCmdlet.cs b/Commands/Base/PnPCmdlet.cs index 132ecf003..61c2fecd4 100644 --- a/Commands/Base/PnPCmdlet.cs +++ b/Commands/Base/PnPCmdlet.cs @@ -115,13 +115,8 @@ protected override void ProcessRecord() } catch (Exception ex) { - if (SPOnlineConnection.CurrentConnection.TelemetryClient != null) - { - SPOnlineConnection.CurrentConnection.TelemetryClient.TrackException(ex); - } SPOnlineConnection.CurrentConnection.RestoreCachedContext(SPOnlineConnection.CurrentConnection.Url); WriteError(new ErrorRecord(ex, "EXCEPTION", ErrorCategory.WriteError, null)); - SPOnlineConnection.CurrentConnection.TelemetryClient.Flush(); } } diff --git a/Commands/Enums/ListItemUpdateType.cs b/Commands/Enums/ListItemUpdateType.cs new file mode 100644 index 000000000..1048e5b2b --- /dev/null +++ b/Commands/Enums/ListItemUpdateType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharePointPnP.PowerShell.Commands.Enums +{ + public enum ListItemUpdateType + { + Update, + SystemUpdate, + UpdateOverwriteVersion + } +} diff --git a/Commands/Fields/GetField.cs b/Commands/Fields/GetField.cs index 353794558..c4133c14d 100644 --- a/Commands/Fields/GetField.cs +++ b/Commands/Fields/GetField.cs @@ -32,6 +32,9 @@ public class GetField : PnPWebRetrievalsCmdlet [Parameter(Mandatory = false, HelpMessage = "Filter to the specified group")] public string Group; + [Parameter(Mandatory = false, ValueFromPipeline = false, HelpMessage = "Search site hierarchy for fields")] + public SwitchParameter InSiteHierarchy; + protected override void ExecuteCmdlet() { if (List != null) @@ -67,8 +70,10 @@ protected override void ExecuteCmdlet() { if (!string.IsNullOrEmpty(Group)) { - WriteObject(fieldCollection.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)),true); - } else { + WriteObject(fieldCollection.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)), true); + } + else + { WriteObject(fieldCollection, true); } } @@ -81,15 +86,36 @@ protected override void ExecuteCmdlet() { if (Identity.Id == Guid.Empty && string.IsNullOrEmpty(Identity.Name)) { - ClientContext.Load(SelectedWeb.Fields, fc => fc.IncludeWithDefaultProperties(RetrievalExpressions)); + if (InSiteHierarchy.IsPresent) + { + ClientContext.Load(SelectedWeb.AvailableFields, fc => fc.IncludeWithDefaultProperties(RetrievalExpressions)); + } + else + { + ClientContext.Load(SelectedWeb.Fields, fc => fc.IncludeWithDefaultProperties(RetrievalExpressions)); + } ClientContext.ExecuteQueryRetry(); if (!string.IsNullOrEmpty(Group)) { - WriteObject(SelectedWeb.Fields.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)), true); + if (InSiteHierarchy.IsPresent) + { + WriteObject(SelectedWeb.AvailableFields.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)).OrderBy(f => f.Title), true); + } + else + { + WriteObject(SelectedWeb.Fields.Where(f => f.Group.Equals(Group, StringComparison.InvariantCultureIgnoreCase)).OrderBy(f => f.Title), true); + } } else { - WriteObject(SelectedWeb.Fields, true); + if (InSiteHierarchy.IsPresent) + { + WriteObject(SelectedWeb.AvailableFields.OrderBy(f => f.Title), true); + } + else + { + WriteObject(SelectedWeb.Fields.OrderBy(f => f.Title), true); + } } } else @@ -97,11 +123,25 @@ protected override void ExecuteCmdlet() Field field = null; if (Identity.Id != Guid.Empty) { - field = SelectedWeb.Fields.GetById(Identity.Id); + if (InSiteHierarchy.IsPresent) + { + field = SelectedWeb.AvailableFields.GetById(Identity.Id); + } + else + { + field = SelectedWeb.Fields.GetById(Identity.Id); + } } else if (!string.IsNullOrEmpty(Identity.Name)) { - field = SelectedWeb.Fields.GetByInternalNameOrTitle(Identity.Name); + if (InSiteHierarchy.IsPresent) + { + field = SelectedWeb.AvailableFields.GetByInternalNameOrTitle(Identity.Name); + } + else + { + field = SelectedWeb.Fields.GetByInternalNameOrTitle(Identity.Name); + } } ClientContext.Load(field, RetrievalExpressions); ClientContext.ExecuteQueryRetry(); diff --git a/Commands/Files/AddFile.cs b/Commands/Files/AddFile.cs index d5ba6fa61..341eb459c 100644 --- a/Commands/Files/AddFile.cs +++ b/Commands/Files/AddFile.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using Microsoft.SharePoint.Client.Taxonomy; using SharePointPnP.PowerShell.Commands.Utilities; +using SharePointPnP.PowerShell.Commands.Enums; namespace SharePointPnP.PowerShell.Commands.Files { @@ -187,7 +188,7 @@ protected override void ExecuteCmdlet() { var item = file.ListItemAllFields; - ListItemHelper.UpdateListItem(item, Values, true, + ListItemHelper.UpdateListItem(item, Values, ListItemUpdateType.UpdateOverwriteVersion, (warning) => { WriteWarning(warning); @@ -201,7 +202,11 @@ protected override void ExecuteCmdlet() { var item = file.ListItemAllFields; item["ContentTypeId"] = targetContentType.Id.StringValue; +#if !ONPREMISES + item.UpdateOverwriteVersion(); +#else item.Update(); +#endif ClientContext.ExecuteQueryRetry(); } @@ -214,7 +219,8 @@ protected override void ExecuteCmdlet() if (Approve) SelectedWeb.ApproveFile(fileUrl, ApproveComment); - + ClientContext.Load(file); + ClientContext.ExecuteQueryRetry(); WriteObject(file); } } diff --git a/Commands/Lists/AddListItem.cs b/Commands/Lists/AddListItem.cs index 1de88b40a..265432ddf 100644 --- a/Commands/Lists/AddListItem.cs +++ b/Commands/Lists/AddListItem.cs @@ -8,6 +8,7 @@ using OfficeDevPnP.Core.Utilities; using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Enums; using SharePointPnP.PowerShell.Commands.Taxonomy; using SharePointPnP.PowerShell.Commands.Utilities; @@ -120,7 +121,7 @@ protected override void ExecuteCmdlet() if (Values != null) { - item = ListItemHelper.UpdateListItem(item, Values, false, + item = ListItemHelper.UpdateListItem(item, Values, ListItemUpdateType.Update, (warning) => { WriteWarning(warning); diff --git a/Commands/Lists/SetListItem.cs b/Commands/Lists/SetListItem.cs index 5c250db11..cbe534426 100644 --- a/Commands/Lists/SetListItem.cs +++ b/Commands/Lists/SetListItem.cs @@ -7,6 +7,7 @@ using Microsoft.SharePoint.Client.Taxonomy; using SharePointPnP.PowerShell.CmdletHelpAttributes; using SharePointPnP.PowerShell.Commands.Base.PipeBinds; +using SharePointPnP.PowerShell.Commands.Enums; using SharePointPnP.PowerShell.Commands.Utilities; // IMPORTANT: If you make changes to this cmdlet, also make the similar/same changes to the Add-PnPListItem Cmdlet @@ -108,7 +109,12 @@ protected override void ExecuteCmdlet() if (Values != null) { #if !ONPREMISES - item = ListItemHelper.UpdateListItem(item, Values, SystemUpdate, (warning) => + var updateType = ListItemUpdateType.Update; + if(SystemUpdate.IsPresent) + { + updateType = ListItemUpdateType.SystemUpdate; + } + item = ListItemHelper.UpdateListItem(item, Values, updateType, (warning) => { WriteWarning(warning); }, @@ -118,7 +124,7 @@ protected override void ExecuteCmdlet() } ); #else - item = ListItemHelper.UpdateListItem(item, Values, false, (warning) => + item = ListItemHelper.UpdateListItem(item, Values, ListItemUpdateType.Update, (warning) => { WriteWarning(warning); }, diff --git a/Commands/Properties/AssemblyInfo.cs b/Commands/Properties/AssemblyInfo.cs index 55a74e000..9ac024878 100644 --- a/Commands/Properties/AssemblyInfo.cs +++ b/Commands/Properties/AssemblyInfo.cs @@ -44,6 +44,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.26.1805.0")] -[assembly: AssemblyFileVersion("2.26.1805.0")] +[assembly: AssemblyVersion("2.26.1805.1")] +[assembly: AssemblyFileVersion("2.26.1805.1")] [assembly: InternalsVisibleTo("SharePointPnP.PowerShell.Tests")] \ No newline at end of file diff --git a/Commands/Provisioning/ApplyProvisioningTemplate.cs b/Commands/Provisioning/ApplyProvisioningTemplate.cs index 00cb0d691..0a3057542 100644 --- a/Commands/Provisioning/ApplyProvisioningTemplate.cs +++ b/Commands/Provisioning/ApplyProvisioningTemplate.cs @@ -11,6 +11,7 @@ using System.Linq; using OfficeDevPnP.Core.Framework.Provisioning.Providers; using SharePointPnP.PowerShell.Commands.Components; +using System.Collections.Generic; namespace SharePointPnP.PowerShell.Commands.Provisioning { @@ -119,7 +120,7 @@ protected override void ExecuteCmdlet() { Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path); } - if(!System.IO.File.Exists(Path)) + if (!System.IO.File.Exists(Path)) { throw new FileNotFoundException($"File not found"); } @@ -278,30 +279,45 @@ protected override void ExecuteCmdlet() WriteProgress(progressRecord); }; + var warningsShown = new List(); + applyingInformation.MessagesDelegate = (message, type) => { switch (type) { case ProvisioningMessageType.Warning: - { - WriteWarning(message); - break; - } + { + if (!warningsShown.Contains(message)) + { + WriteWarning(message); + warningsShown.Add(message); + } + break; + } case ProvisioningMessageType.Progress: - { - var activity = message; - if (message.IndexOf("|") > -1) { - var messageSplitted = message.Split('|'); - if (messageSplitted.Length == 4) + var activity = message; + if (message.IndexOf("|") > -1) { - var current = double.Parse(messageSplitted[2]); - var total = double.Parse(messageSplitted[3]); - subProgressRecord.RecordType = ProgressRecordType.Processing; - subProgressRecord.Activity = messageSplitted[0]; - subProgressRecord.StatusDescription = messageSplitted[1]; - subProgressRecord.PercentComplete = Convert.ToInt32((100/total)*current); - WriteProgress(subProgressRecord); + var messageSplitted = message.Split('|'); + if (messageSplitted.Length == 4) + { + var current = double.Parse(messageSplitted[2]); + var total = double.Parse(messageSplitted[3]); + subProgressRecord.RecordType = ProgressRecordType.Processing; + subProgressRecord.Activity = messageSplitted[0]; + subProgressRecord.StatusDescription = messageSplitted[1]; + subProgressRecord.PercentComplete = Convert.ToInt32((100 / total) * current); + WriteProgress(subProgressRecord); + } + else + { + subProgressRecord.Activity = "Processing"; + subProgressRecord.RecordType = ProgressRecordType.Processing; + subProgressRecord.StatusDescription = activity; + subProgressRecord.PercentComplete = 0; + WriteProgress(subProgressRecord); + } } else { @@ -311,23 +327,14 @@ protected override void ExecuteCmdlet() subProgressRecord.PercentComplete = 0; WriteProgress(subProgressRecord); } + break; } - else - { - subProgressRecord.Activity = "Processing"; - subProgressRecord.RecordType = ProgressRecordType.Processing; - subProgressRecord.StatusDescription = activity; - subProgressRecord.PercentComplete = 0; - WriteProgress(subProgressRecord); - } - break; - } case ProvisioningMessageType.Completed: - { + { - WriteProgress(new ProgressRecord(1, message, " ") {RecordType = ProgressRecordType.Completed}); - break; - } + WriteProgress(new ProgressRecord(1, message, " ") { RecordType = ProgressRecordType.Completed }); + break; + } } }; diff --git a/Commands/Search/SubmitSearchQuery.cs b/Commands/Search/SubmitSearchQuery.cs index ef9f744d7..ab160cbe7 100644 --- a/Commands/Search/SubmitSearchQuery.cs +++ b/Commands/Search/SubmitSearchQuery.cs @@ -74,6 +74,9 @@ public class SubmitSearchQuery : PnPWebCmdlet [Parameter(Mandatory = false, HelpMessage = "Specifies the name of the client which issued the query.", ParameterSetName = ParameterAttribute.AllParameterSets)] public string ClientType = "ContentSearchLow"; + [Parameter(Mandatory = false, HelpMessage = "Limit the number of items per the collapse specification. See https://docs.microsoft.com/en-us/sharepoint/dev/general-development/customizing-search-results-in-sharepoint#collapse-similar-search-results-using-the-collapsespecification-property for more information.", ParameterSetName = ParameterAttribute.AllParameterSets)] + public string CollapseSpecification; + [Parameter(Mandatory = false, HelpMessage = "The keyword query’s hidden constraints.", ParameterSetName = ParameterAttribute.AllParameterSets)] public string HiddenConstraints; @@ -217,6 +220,7 @@ private KeywordQuery CreateKeywordQuery() if (MyInvocation.BoundParameters.ContainsKey("SourceId")) keywordQuery.SourceId = SourceId; if (MyInvocation.BoundParameters.ContainsKey("ProcessBestBets")) keywordQuery.ProcessBestBets = ProcessBestBets; if (MyInvocation.BoundParameters.ContainsKey("ProcessPersonalFavorites")) keywordQuery.ProcessPersonalFavorites = ProcessPersonalFavorites; + if (MyInvocation.BoundParameters.ContainsKey("CollapseSpecification")) keywordQuery.CollapseSpecification = CollapseSpecification; if (SortList != null) { diff --git a/Commands/SharePointPnP.PowerShell.Commands.csproj b/Commands/SharePointPnP.PowerShell.Commands.csproj index b76d3f88e..99923a7c7 100644 --- a/Commands/SharePointPnP.PowerShell.Commands.csproj +++ b/Commands/SharePointPnP.PowerShell.Commands.csproj @@ -464,6 +464,7 @@ + diff --git a/Commands/Utilities/ListItemHelper.cs b/Commands/Utilities/ListItemHelper.cs index 315199a89..5551be336 100644 --- a/Commands/Utilities/ListItemHelper.cs +++ b/Commands/Utilities/ListItemHelper.cs @@ -1,5 +1,6 @@ using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Taxonomy; +using SharePointPnP.PowerShell.Commands.Enums; using System; using System.Collections; using System.Collections.Generic; @@ -30,7 +31,7 @@ public FieldUpdateValue(string key, object value, string fieldTypeString) } } - public static ListItem UpdateListItem(ListItem item, Hashtable valuesToSet, bool systemUpdate, Action warningCallback, Action terminatingError) + public static ListItem UpdateListItem(ListItem item, Hashtable valuesToSet, ListItemUpdateType updateType, Action warningCallback, Action terminatingError) { var itemValues = new List(); @@ -253,13 +254,23 @@ public static ListItem UpdateListItem(ListItem item, Hashtable valuesToSet, bool } } #if !ONPREMISES - if (systemUpdate) + switch(updateType) { - item.SystemUpdate(); - } - else - { - item.Update(); + case ListItemUpdateType.Update: + { + item.Update(); + break; + } + case ListItemUpdateType.SystemUpdate: + { + item.SystemUpdate(); + break; + } + case ListItemUpdateType.UpdateOverwriteVersion: + { + item.UpdateOverwriteVersion(); + break; + } } #else item.Update();