Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1277 - retrieve deprecated terms #1903

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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