-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1597 from swapnil1993/dev
Added pnp cmdlets to publish, unpublish and get publishing status of a content type in content type hub site
- Loading branch information
Showing
10 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPContentTypePublishingStatus.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Get-PnPContentTypePublishingStatus | ||
--- | ||
|
||
# Get-PnPContentTypePublishingStatus | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Fullcontrol permission on the content type hub site. | ||
|
||
Returns the publishing status of a content type present on content type hub site. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Get-PnPContentTypePublishingStatus -ContentType <ContentTypePipeBind> [-Connection <PnPConnection>] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Get-PnPContentTypePublishingStatus -ContentType 0x0101 | ||
``` | ||
|
||
This will return `True` if content type is published in the content type hub site otherwise it will return `False`. | ||
## PARAMETERS | ||
|
||
### -Connection | ||
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. | ||
|
||
```yaml | ||
Type: PnPConnection | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -ContentType | ||
The content type object in the content type hub site for which the publishing status needs to be fetched. | ||
```yaml | ||
Type: ContentType | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Publish-PnPContentType.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Publish-PnPContentType | ||
--- | ||
|
||
# Publish-PnPContentType | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Fullcontrol permission on the content type hub site. | ||
|
||
Publishes or republishes a content type present on content type hub site. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Publish-PnPContentType -ContentType <ContentTypePipeBind> [-Connection <PnPConnection>] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Publish-PnPContentType -ContentType 0x0101 | ||
``` | ||
|
||
This will publish the content type with the given id. | ||
## PARAMETERS | ||
|
||
### -Connection | ||
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. | ||
|
||
```yaml | ||
Type: PnPConnection | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -ContentType | ||
The content type object in the content type hub site which is to be published. | ||
```yaml | ||
Type: ContentType | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Unpublish-PnPContentType.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Unpublish-PnPContentType | ||
--- | ||
|
||
# Unpublish-PnPContentType | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Fullcontrol permission on the content type hub site. | ||
|
||
Unpublishes a content type present on content type hub site. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Unpublish-PnPContentType -ContentType <ContentTypePipeBind> [-Connection <PnPConnection>] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Unpublish-PnPContentType -ContentType 0x0101 | ||
``` | ||
|
||
This will unpublish the content type with the given id. | ||
## PARAMETERS | ||
|
||
### -Connection | ||
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. | ||
|
||
```yaml | ||
Type: PnPConnection | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -ContentType | ||
The content type object in the content type hub site which is to be unpublished. | ||
```yaml | ||
Type: ContentType | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) |
37 changes: 37 additions & 0 deletions
37
src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Management.Automation; | ||
using Microsoft.SharePoint.Client; | ||
|
||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
|
||
namespace PnP.PowerShell.Commands.ContentTypes | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPContentTypePublishingStatus")] | ||
public class GetContentTypePublishingStatus : PnPWebCmdlet | ||
{ | ||
[Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)] | ||
[ValidateNotNullOrEmpty] | ||
public ContentTypePipeBind ContentType; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
Microsoft.SharePoint.Client.Site site = ClientContext.Site; | ||
ClientContext.Load(site); | ||
ClientContext.ExecuteQuery(); | ||
var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); | ||
ClientContext.Load(pub); | ||
ClientContext.ExecuteQuery(); | ||
var ct = ContentType.GetContentTypeOrError(this, nameof(ContentType), site.RootWeb); | ||
|
||
if (ct == null) | ||
{ | ||
WriteError(new ErrorRecord(new Exception($"Invalid content type id."), "INVALIDCTID", ErrorCategory.InvalidArgument, ContentType)); | ||
return; | ||
} | ||
|
||
var isPublished = pub.IsPublished(ct); | ||
ClientContext.ExecuteQuery(); | ||
WriteObject(isPublished); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Management.Automation; | ||
using Microsoft.SharePoint.Client; | ||
|
||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
|
||
namespace PnP.PowerShell.Commands.ContentTypes | ||
{ | ||
[Cmdlet(VerbsData.Publish, "PnPContentType")] | ||
public class PublishContentType : PnPWebCmdlet | ||
{ | ||
[Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)] | ||
[ValidateNotNullOrEmpty] | ||
public ContentTypePipeBind ContentType; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
Microsoft.SharePoint.Client.Site site = ClientContext.Site; | ||
ClientContext.Load(site); | ||
ClientContext.ExecuteQuery(); | ||
var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); | ||
ClientContext.Load(pub); | ||
ClientContext.ExecuteQuery(); | ||
var ct = ContentType.GetContentTypeOrError(this, nameof(ContentType), site.RootWeb); | ||
|
||
if (ct == null) | ||
{ | ||
WriteError(new ErrorRecord(new Exception($"Invalid content type id."), "INVALIDCTID", ErrorCategory.InvalidArgument, ContentType)); | ||
return; | ||
} | ||
|
||
var republish = pub.IsPublished(ct); | ||
ClientContext.ExecuteQuery(); | ||
pub.Publish(ct, republish.Value); | ||
ClientContext.ExecuteQuery(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Management.Automation; | ||
using Microsoft.SharePoint.Client; | ||
|
||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
|
||
namespace PnP.PowerShell.Commands.ContentTypes | ||
{ | ||
[Cmdlet(VerbsData.Unpublish, "PnPContentType")] | ||
public class UnpublishContentType : PnPWebCmdlet | ||
{ | ||
[Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)] | ||
[ValidateNotNullOrEmpty] | ||
public ContentTypePipeBind ContentType; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
Microsoft.SharePoint.Client.Site site = ClientContext.Site; | ||
ClientContext.Load(site); | ||
ClientContext.ExecuteQuery(); | ||
var pub = new Microsoft.SharePoint.Client.Taxonomy.ContentTypeSync.ContentTypePublisher(ClientContext, site); | ||
ClientContext.Load(pub); | ||
ClientContext.ExecuteQuery(); | ||
var ct = ContentType.GetContentTypeOrError(this, nameof(ContentType), site.RootWeb); | ||
|
||
if (ct == null) | ||
{ | ||
WriteError(new ErrorRecord(new Exception($"Invalid content type id."), "INVALIDCTID", ErrorCategory.InvalidArgument, ContentType)); | ||
return; | ||
} | ||
|
||
pub.Unpublish(ct); | ||
ClientContext.ExecuteQuery(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Management.Automation.Runspaces; | ||
|
||
namespace PnP.PowerShell.Tests.ContentTypes | ||
{ | ||
[TestClass] | ||
public class GetPnPContentTypePublishingStatusTests : PnPTest | ||
{ | ||
#region Test Setup/CleanUp | ||
[ClassInitialize] | ||
public static void Initialize(TestContext testContext) | ||
{ | ||
// This runs on class level once before all tests run | ||
//using (var ctx = TestCommon.CreateClientContext()) | ||
//{ | ||
//} | ||
} | ||
#endregion | ||
#region Scaffolded Cmdlet Tests | ||
[TestMethod] | ||
public void GetPnPContentTypePublishingStatusTest() | ||
{ | ||
using (var scope = new PSTestScope(true)) | ||
{ | ||
var results = scope.ExecuteCommand("Get-PnPContentTypePublishingStatus", | ||
new CommandParameter("ContentType", "0x0101")); | ||
|
||
Assert.IsNotNull(results); | ||
} | ||
} | ||
#endregion | ||
} | ||
} | ||
|
Oops, something went wrong.