Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added -CollapseSpecification option to Submit-PnPSearchQuery

### Changed
- Fix for issue where using Add-PnPFile and setting Created and Modified did not update values

### Deprecated

Expand Down
5 changes: 0 additions & 5 deletions Commands/Base/PnPCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
15 changes: 15 additions & 0 deletions Commands/Enums/ListItemUpdateType.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
10 changes: 8 additions & 2 deletions Commands/Files/AddFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

Expand All @@ -214,7 +219,8 @@ protected override void ExecuteCmdlet()

if (Approve)
SelectedWeb.ApproveFile(fileUrl, ApproveComment);

ClientContext.Load(file);
ClientContext.ExecuteQueryRetry();
WriteObject(file);
}
}
Expand Down
3 changes: 2 additions & 1 deletion Commands/Lists/AddListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions Commands/Lists/SetListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
},
Expand All @@ -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);
},
Expand Down
1 change: 1 addition & 0 deletions Commands/SharePointPnP.PowerShell.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@
<Compile Include="Base\PipeBinds\SitePipeBind.cs" />
<Compile Include="Base\PipeBinds\TenantSiteScriptPipeBind.cs" />
<Compile Include="Base\PipeBinds\TenantSiteDesignPipeBind.cs" />
<Compile Include="Enums\ListItemUpdateType.cs" />
<Compile Include="Enums\StorageEntityScope.cs" />
<Compile Include="Model\ServicePrincipalPermissionGrant.cs" />
<Compile Include="Navigation\GetNavigationNode.cs" />
Expand Down
25 changes: 18 additions & 7 deletions Commands/Utilities/ListItemHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,7 +31,7 @@ public FieldUpdateValue(string key, object value, string fieldTypeString)
}
}

public static ListItem UpdateListItem(ListItem item, Hashtable valuesToSet, bool systemUpdate, Action<string> warningCallback, Action<string, string> terminatingError)
public static ListItem UpdateListItem(ListItem item, Hashtable valuesToSet, ListItemUpdateType updateType, Action<string> warningCallback, Action<string, string> terminatingError)
{
var itemValues = new List<FieldUpdateValue>();

Expand Down Expand Up @@ -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();
Expand Down