Skip to content

Commit

Permalink
#1277 - retrieve deprecated terms (#1903)
Browse files Browse the repository at this point in the history
* #1277 - retrieve deprecated terms

* Added changelog
  • Loading branch information
gautamdsheth committed May 31, 2022
1 parent 4d70a9f commit fbdbad9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added capability to Debug the module in Visual Studio. [#1880](https://github.com/pnp/powershell/pull/1880)
- Added `Set-PnPTeamsChannelUser` cmdlet to update the role of user in a private channel. [#1865](https://github.com/pnp/powershell/pull/1865)
- Added `Restart-PnPFlowRun` which allows for a failed Power Automate flow run to be retried [#1915](https://github.com/pnp/powershell/pull/1915)
- Added `-IncludeDeprecated` parameter to `Get-PnPTerm` cmdlet to fetch deprecated terms if specified [#1903](https://github.com/pnp/powershell/pull/1903)

### Changed
- Changed `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory` to map users based on their Ids instead which should resolve some issues around user identities reporting not to exist. You can use the new `-IdType` option to switch it back to `PrincipalName` if needed. [#1752](https://github.com/pnp/powershell/pull/1752)
Expand Down
23 changes: 22 additions & 1 deletion documentation/Get-PnPTerm.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Get-PnPTerm
-TermGroup <Guid|Name>
[-TermStore <Guid>]
[-Recursive]
[-IncludeChildTerms] [-Connection <PnPConnection>] [-Includes <String[]>] [<CommonParameters>]
[-IncludeChildTerms][-IncludeDeprecated] [-Connection <PnPConnection>] [-Includes <String[]>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -74,6 +74,13 @@ $term.Labels

Returns all the localized labels for the term named "Small Finance", from the "Departments" termset in a term group called "Corporate"

### EXAMPLE 6
```powershell
Get-PnPTerm -Identity "Small Finance" -TermSet "Departments" -TermGroup "Corporate" -Recursive -IncludeDeprecated
```

Returns the deprecated term named "Small Finance", from the "Departments" termset in a term group called "Corporate" from the site collection termstore even if it is a subterm below "Finance"

## PARAMETERS

### -Connection
Expand Down Expand Up @@ -174,6 +181,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -IncludeDeprecated
Includes the deprecated terms if available.

```yaml
Type: SwitchParameter
Parameter Sets: By Term name

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Expand Down
37 changes: 26 additions & 11 deletions src/Commands/Base/PipeBinds/TaxonomyTermPipeBind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public TaxonomyTermPipeBind(Term item)

public Term Item => _item;

public Term GetTerm(ClientContext clientContext, TermStore termStore, TermSet termSet, bool recursive, Expression<Func<Term, object>>[] expressions = null)
public Term GetTerm(ClientContext clientContext, TermStore termStore, TermSet termSet, bool recursive, Expression<Func<Term, object>>[] expressions = null, bool includeDeprecated = false)
{
Term term = null;
if (_id != Guid.Empty)
Expand All @@ -55,20 +55,35 @@ public Term GetTerm(ClientContext clientContext, TermStore termStore, TermSet te
}
else
{
var lmi = new LabelMatchInformation(clientContext)
if (includeDeprecated)
{
TrimUnavailable = true,
TermLabel = termName
};
var allTerms = termSet.GetAllTermsIncludeDeprecated();
clientContext.Load(allTerms);
clientContext.ExecuteQueryRetry();

var termMatches = termSet.GetTerms(lmi);
clientContext.Load(termMatches);
clientContext.ExecuteQueryRetry();

if (termMatches.AreItemsAvailable)
if (allTerms.AreItemsAvailable)
{
term = allTerms.Where(t => t.Name == termName).FirstOrDefault();
}
}
else
{
term = termMatches.FirstOrDefault();
var lmi = new LabelMatchInformation(clientContext)
{
TrimUnavailable = true,
TermLabel = termName
};

var termMatches = termSet.GetTerms(lmi);
clientContext.Load(termMatches);
clientContext.ExecuteQueryRetry();

if (termMatches.AreItemsAvailable)
{
term = termMatches.FirstOrDefault();
}
}

}
}
else
Expand Down
7 changes: 5 additions & 2 deletions src/Commands/Taxonomy/GetTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class GetTerm : PnPRetrievalsCmdlet<Term>
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_TERMNAME)]
public TaxonomyTermPipeBind ParentTerm;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_TERMNAME)]
public SwitchParameter IncludeDeprecated;

protected override void ExecuteCmdlet()
{
DefaultRetrievalExpressions = new Expression<Func<Term, object>>[] { g => g.Name, g => g.TermsCount, g => g.Id };
Expand Down Expand Up @@ -77,7 +80,7 @@ protected override void ExecuteCmdlet()

if (Identity != null && ParentTerm == null)
{
var term = Identity.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions);
var term = Identity.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions, IncludeDeprecated);

if (IncludeChildTerms.IsPresent && term.TermsCount > 0)
{
Expand All @@ -87,7 +90,7 @@ protected override void ExecuteCmdlet()
}
else if (Identity != null && ParentTerm != null)
{
var term = ParentTerm.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions);
var term = ParentTerm.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions, IncludeDeprecated);

if (IncludeChildTerms.IsPresent && term.TermsCount > 0)
{
Expand Down

0 comments on commit fbdbad9

Please sign in to comment.