Skip to content

Commit

Permalink
Merge pull request #1597 from swapnil1993/dev
Browse files Browse the repository at this point in the history
Added pnp cmdlets to publish, unpublish and get publishing status of a content type in content type hub site
  • Loading branch information
KoenZomers authored Feb 3, 2022
2 parents 2439c7d + 3d8c34c commit 5a028cc
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added support to add multiple owners and members in `New-PnPTeamsTeam` cmdlet [#1241](https://github.com/pnp/powershell/pull/1241)
- Added the ability to set the title of a new modern page in SharePoint Online using `Add-PnPPage` to be different from its filename by using `-Title`
- Added `Get-PnPTeamsPrimaryChannel` to get the primary Teams channel, general, of a Team [#1572](https://github.com/pnp/powershell/pull/1572)
- Added `Publish\Unpublish-PnPContentType` to allow for content types to be published or unpublished on hub sites [#1597](https://github.com/pnp/powershell/pull/1597)
- Added `Get-PnPContentTypePublishingStatus` to get te current publication state of a content type in the content type hub site [#1597](https://github.com/pnp/powershell/pull/1597)
- Added ability to pipe the output of `Get-PnPTenantDeletedSite` to either `Restore-PnPTenantDeletedSite` or `Remove-PnPTenantDeletedSite` [#1596](https://github.com/pnp/powershell/pull/1596)

### Changed
Expand Down Expand Up @@ -54,6 +56,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Contributors

- [swapnil1993]
- Hugo Bernier [hugoabernier]
- brenle
- Johan Brännmar [brannmar]
Expand Down
68 changes: 68 additions & 0 deletions documentation/Get-PnPContentTypePublishingStatus.md
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)
68 changes: 68 additions & 0 deletions documentation/Publish-PnPContentType.md
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)
68 changes: 68 additions & 0 deletions documentation/Unpublish-PnPContentType.md
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 src/Commands/ContentTypes/Get-PnPContentTypePublishingStatus.cs
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);
}
}
}
38 changes: 38 additions & 0 deletions src/Commands/ContentTypes/Publish-PnPContentType.cs
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();
}
}
}
36 changes: 36 additions & 0 deletions src/Commands/ContentTypes/Unpublish-PnPContentType.cs
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 src/Tests/ContentTypes/GetPnPContentTypePublishingStatusTests.cs
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
}
}

Loading

0 comments on commit 5a028cc

Please sign in to comment.