Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit ee406db

Browse files
Merge pull request #1561 from erwinvanhunen/dev
Fix for issue #1550
2 parents 31e4fde + 30c31c7 commit ee406db

File tree

8 files changed

+53
-17
lines changed

8 files changed

+53
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1111
- Added -CollapseSpecification option to Submit-PnPSearchQuery
1212

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

1516
### Deprecated
1617

Commands/Base/PnPCmdlet.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,8 @@ protected override void ProcessRecord()
115115
}
116116
catch (Exception ex)
117117
{
118-
if (SPOnlineConnection.CurrentConnection.TelemetryClient != null)
119-
{
120-
SPOnlineConnection.CurrentConnection.TelemetryClient.TrackException(ex);
121-
}
122118
SPOnlineConnection.CurrentConnection.RestoreCachedContext(SPOnlineConnection.CurrentConnection.Url);
123119
WriteError(new ErrorRecord(ex, "EXCEPTION", ErrorCategory.WriteError, null));
124-
SPOnlineConnection.CurrentConnection.TelemetryClient.Flush();
125120
}
126121
}
127122

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SharePointPnP.PowerShell.Commands.Enums
8+
{
9+
public enum ListItemUpdateType
10+
{
11+
Update,
12+
SystemUpdate,
13+
UpdateOverwriteVersion
14+
}
15+
}

Commands/Files/AddFile.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Collections.Generic;
1111
using Microsoft.SharePoint.Client.Taxonomy;
1212
using SharePointPnP.PowerShell.Commands.Utilities;
13+
using SharePointPnP.PowerShell.Commands.Enums;
1314

1415
namespace SharePointPnP.PowerShell.Commands.Files
1516
{
@@ -187,7 +188,7 @@ protected override void ExecuteCmdlet()
187188
{
188189
var item = file.ListItemAllFields;
189190

190-
ListItemHelper.UpdateListItem(item, Values, true,
191+
ListItemHelper.UpdateListItem(item, Values, ListItemUpdateType.UpdateOverwriteVersion,
191192
(warning) =>
192193
{
193194
WriteWarning(warning);
@@ -201,7 +202,11 @@ protected override void ExecuteCmdlet()
201202
{
202203
var item = file.ListItemAllFields;
203204
item["ContentTypeId"] = targetContentType.Id.StringValue;
205+
#if !ONPREMISES
206+
item.UpdateOverwriteVersion();
207+
#else
204208
item.Update();
209+
#endif
205210
ClientContext.ExecuteQueryRetry();
206211
}
207212

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

215220
if (Approve)
216221
SelectedWeb.ApproveFile(fileUrl, ApproveComment);
217-
222+
ClientContext.Load(file);
223+
ClientContext.ExecuteQueryRetry();
218224
WriteObject(file);
219225
}
220226
}

Commands/Lists/AddListItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using OfficeDevPnP.Core.Utilities;
99
using SharePointPnP.PowerShell.CmdletHelpAttributes;
1010
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
11+
using SharePointPnP.PowerShell.Commands.Enums;
1112
using SharePointPnP.PowerShell.Commands.Taxonomy;
1213
using SharePointPnP.PowerShell.Commands.Utilities;
1314

@@ -120,7 +121,7 @@ protected override void ExecuteCmdlet()
120121

121122
if (Values != null)
122123
{
123-
item = ListItemHelper.UpdateListItem(item, Values, false,
124+
item = ListItemHelper.UpdateListItem(item, Values, ListItemUpdateType.Update,
124125
(warning) =>
125126
{
126127
WriteWarning(warning);

Commands/Lists/SetListItem.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.SharePoint.Client.Taxonomy;
88
using SharePointPnP.PowerShell.CmdletHelpAttributes;
99
using SharePointPnP.PowerShell.Commands.Base.PipeBinds;
10+
using SharePointPnP.PowerShell.Commands.Enums;
1011
using SharePointPnP.PowerShell.Commands.Utilities;
1112
// IMPORTANT: If you make changes to this cmdlet, also make the similar/same changes to the Add-PnPListItem Cmdlet
1213

@@ -108,7 +109,12 @@ protected override void ExecuteCmdlet()
108109
if (Values != null)
109110
{
110111
#if !ONPREMISES
111-
item = ListItemHelper.UpdateListItem(item, Values, SystemUpdate, (warning) =>
112+
var updateType = ListItemUpdateType.Update;
113+
if(SystemUpdate.IsPresent)
114+
{
115+
updateType = ListItemUpdateType.SystemUpdate;
116+
}
117+
item = ListItemHelper.UpdateListItem(item, Values, updateType, (warning) =>
112118
{
113119
WriteWarning(warning);
114120
},
@@ -118,7 +124,7 @@ protected override void ExecuteCmdlet()
118124
}
119125
);
120126
#else
121-
item = ListItemHelper.UpdateListItem(item, Values, false, (warning) =>
127+
item = ListItemHelper.UpdateListItem(item, Values, ListItemUpdateType.Update, (warning) =>
122128
{
123129
WriteWarning(warning);
124130
},

Commands/SharePointPnP.PowerShell.Commands.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@
464464
<Compile Include="Base\PipeBinds\SitePipeBind.cs" />
465465
<Compile Include="Base\PipeBinds\TenantSiteScriptPipeBind.cs" />
466466
<Compile Include="Base\PipeBinds\TenantSiteDesignPipeBind.cs" />
467+
<Compile Include="Enums\ListItemUpdateType.cs" />
467468
<Compile Include="Enums\StorageEntityScope.cs" />
468469
<Compile Include="Model\ServicePrincipalPermissionGrant.cs" />
469470
<Compile Include="Navigation\GetNavigationNode.cs" />

Commands/Utilities/ListItemHelper.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.SharePoint.Client;
22
using Microsoft.SharePoint.Client.Taxonomy;
3+
using SharePointPnP.PowerShell.Commands.Enums;
34
using System;
45
using System.Collections;
56
using System.Collections.Generic;
@@ -30,7 +31,7 @@ public FieldUpdateValue(string key, object value, string fieldTypeString)
3031
}
3132
}
3233

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

@@ -253,13 +254,23 @@ public static ListItem UpdateListItem(ListItem item, Hashtable valuesToSet, bool
253254
}
254255
}
255256
#if !ONPREMISES
256-
if (systemUpdate)
257+
switch(updateType)
257258
{
258-
item.SystemUpdate();
259-
}
260-
else
261-
{
262-
item.Update();
259+
case ListItemUpdateType.Update:
260+
{
261+
item.Update();
262+
break;
263+
}
264+
case ListItemUpdateType.SystemUpdate:
265+
{
266+
item.SystemUpdate();
267+
break;
268+
}
269+
case ListItemUpdateType.UpdateOverwriteVersion:
270+
{
271+
item.UpdateOverwriteVersion();
272+
break;
273+
}
263274
}
264275
#else
265276
item.Update();

0 commit comments

Comments
 (0)