From fd988917a668ccf7621bf08ef1b4aca7caf48f2d Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Sun, 12 Feb 2023 09:20:46 +0200 Subject: [PATCH 1/3] Fix #2495 - changed default checkin to minor version and added parameter --- CHANGELOG.md | 1 + documentation/Add-PnPFile.md | 20 +++++++++++++++++--- src/Commands/Files/AddFile.cs | 10 +++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfaef8277..8f3a28555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-IsVivaConnectionsDefaultStartForCompanyPortalSiteEnabled` parameter to `Get-PnPHomeSite` which returns information on whether Viva Connections landing experience is set to the SharePoint home site. [#2779](https://github.com/pnp/powershell/pull/2779) - Added `-VivaConnectionsDefaultStart` parameter to `Set-PnPHomeSite` which sets the home site to the provided site collection url and keeps the Viva Connections landing experience to the SharePoint home site. [#2779](https://github.com/pnp/powershell/pull/2779) - Added `-LargeList` parameter to `Remove-PnPList` cmdlet which improves the list recycling experience for Lists containing huge number of items. [#2778](https://github.com/pnp/powershell/pull/2778) +- Added `-CheckinType` parameter to `Add-PnPFile` cmdlet which provides the option to specify the checkin type for a file. The default value is set to `MinorCheckIn`. ### Changed diff --git a/documentation/Add-PnPFile.md b/documentation/Add-PnPFile.md index 19d9b20ee..c6af74948 100644 --- a/documentation/Add-PnPFile.md +++ b/documentation/Add-PnPFile.md @@ -16,21 +16,21 @@ Uploads a file to Web ### Upload file ```powershell -Add-PnPFile -Path -Folder [-NewFileName ] [-Checkout] [-CheckInComment ] +Add-PnPFile -Path -Folder [-NewFileName ] [-Checkout] [-CheckInComment ] [-CheckinType ] [-Approve] [-ApproveComment ] [-Publish] [-PublishComment ] [-UseWebDav] [-Values ] [-ContentType ] [-Connection ] [] ``` ### Upload file from stream ```powershell -Add-PnPFile -Folder -FileName -Stream [-Checkout] [-CheckInComment ] +Add-PnPFile -Folder -FileName -Stream [-Checkout] [-CheckInComment ] [-CheckinType ] [-Approve] [-ApproveComment ] [-Publish] [-PublishComment ] [-UseWebDav] [-Values ] [-ContentType ] [-Connection ] [] ``` ### Create or update file from text ```powershell -Add-PnPFile -Folder -FileName -Content [-Checkout] [-CheckInComment ] +Add-PnPFile -Folder -FileName -Content [-Checkout] [-CheckInComment ] [-CheckinType ] [-Approve] [-ApproveComment ] [-Publish] [-PublishComment ] [-UseWebDav] [-Values ] [-ContentType ] [-Connection ] [] ``` @@ -140,6 +140,20 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -CheckinType +Specifies the type of check-in for a file. + +```yaml +Type: Enum (Microsoft.SharePoint.Client.CheckinType) +Parameter Sets: (All) + +Required: False +Position: Named +Default value: MinorCheckIn +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Checkout If versioning is enabled, this will check out the file first if it exists, upload the file, then check it in again diff --git a/src/Commands/Files/AddFile.cs b/src/Commands/Files/AddFile.cs index 54c393ae4..061aa662c 100644 --- a/src/Commands/Files/AddFile.cs +++ b/src/Commands/Files/AddFile.cs @@ -45,6 +45,9 @@ public class AddFile : PnPWebCmdlet [Parameter(Mandatory = false)] public string CheckInComment = string.Empty; + [Parameter(Mandatory = false)] + public CheckinType CheckinType = CheckinType.MinorCheckIn; + [Parameter(Mandatory = false)] public SwitchParameter Approve; @@ -117,7 +120,7 @@ protected override void ExecuteCmdlet() { // Swallow exception, file does not exist } } - + Microsoft.SharePoint.Client.File file; switch (ParameterSetName) { @@ -161,9 +164,10 @@ protected override void ExecuteCmdlet() { item.UpdateOverwriteVersion(); } + if (Checkout) { - CurrentWeb.CheckInFile(fileUrl, CheckinType.MajorCheckIn, CheckInComment); + CurrentWeb.CheckInFile(fileUrl, CheckinType, CheckInComment); } if (Publish) @@ -197,7 +201,7 @@ protected override void ExecuteCmdlet() private Folder EnsureFolder() { // First try to get the folder if it exists already. This avoids an Access Denied exception if the current user doesn't have Full Control access at Web level - CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl); + CurrentWeb.EnsureProperty(w => w.ServerRelativeUrl); Folder folder = null; try From ea8d8fc8f3df5092b6777f2a06de4514e8b7679c Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Wed, 15 Feb 2023 13:25:16 +0100 Subject: [PATCH 2/3] Added PR reference --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f088457df..f8ef48e3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-IsVivaConnectionsDefaultStartForCompanyPortalSiteEnabled` parameter to `Get-PnPHomeSite` which returns information on whether Viva Connections landing experience is set to the SharePoint home site. [#2779](https://github.com/pnp/powershell/pull/2779) - Added `-VivaConnectionsDefaultStart` parameter to `Set-PnPHomeSite` which sets the home site to the provided site collection url and keeps the Viva Connections landing experience to the SharePoint home site. [#2779](https://github.com/pnp/powershell/pull/2779) - Added `-LargeList` parameter to `Remove-PnPList` cmdlet which improves the list recycling experience for Lists containing huge number of items. [#2778](https://github.com/pnp/powershell/pull/2778) -- Added `-CheckinType` parameter to `Add-PnPFile` cmdlet which provides the option to specify the checkin type for a file. The default value is set to `MinorCheckIn`. +- Added `-CheckinType` parameter to `Add-PnPFile` cmdlet which provides the option to specify the checkin type for a file. The default value is set to `MinorCheckIn`. [#2806](https://github.com/pnp/powershell/pull/2806) - Added `-ApplicationId` as alias for `-ClientId` in `Connect-PnPOnline` and `Request-PnPAccessToken` cmdlets. ### Changed From 0f63d1af2226c75c9130dbd875259cd901ca81c9 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Wed, 15 Feb 2023 13:27:09 +0100 Subject: [PATCH 3/3] Added extra notice about the changed behavior of the cmdlet --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8ef48e3b..7840b84d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Properties of `Get-PnPAzureADServicePrincipal` are now all typed instead of some of them returning unparsed JSON fragments. [#2717](https://github.com/pnp/powershell/pull/2717) - Marked `Get-PnPSubscribeSharePointNewsDigest` and `Set-PnPSubscribeSharePointNewsDigest` as obsolete as the implementation behind these features has been changed in SharePoint Online causing them no longer to work. At present, there's no alternative for this that we can call into thus we will have to remove these in a future version. [#2720](https://github.com/pnp/powershell/pull/2720) - Changed `Add-PnPTeamsChannel` to no longer require an `-OwnerUPN` to be provided when specifying `-ChannelType Standard` [#2786](https://github.com/pnp/powershell/pull/2786) +- Changed `Add-PnPFile` by default to upload a file as a draft with a minor version now instead of publishing it as a major version. `-CheckinType MajorCheckIn` can be used to still upload the file as a major published version [#2806](https://github.com/pnp/powershell/pull/2806) ### Removed