簡體   English   中英

Sitecore Powershell報告不返回任何結果

[英]Sitecore Powershell reports does not return any results

我創建了一個報告,如果我從Powershell ISE手動運行它,它會生成我期望的項目列表,但是當我從Reporting Tools運行它時,它不會返回任何結果。

該腳本會抓取所有項目的版本和語言,大約有80,000個項目,這需要一段時間。

有沒有一種方法可以增加延遲,直到生成所有項目的列表,或者有其他解決方法?

源代碼:

$RichTextContentID = "";
$internalLinkPattern = '<a href="~\/link\.aspx\?_id=(?<sitecoreid>[a-zA-Z\d]{32})&amp;_z=z">';
$literatureTemplate = "";
$global:guiltyItems = @();

function Process-RichText
{
    param(  [Parameter(Mandatory = $true)] [Sitecore.Data.Fields.Field]$field,
            [Parameter(Mandatory = $true)] [string]$pattern,
            [Parameter(Mandatory = $true)] [Sitecore.Data.Items.Item]$item)

    $allMatches = [System.Text.RegularExpressions.Regex]::Matches($field.Value,$pattern);
    foreach ($match in $allMatches)
    {
        $currentItem = Get-Item master -Id ([Sitecore.Data.ID]::Parse($match.Groups["sitecoreid"].Value)).Guid;

        if ($currentItem.Template.Id -eq $literatureTemplate)
        {   
            if ($global:guiltyItems -notcontains $item)
            {
                $global:guiltyItems += $item;
            }
        }
    }
}

$allitems = Get-Item master -Query "/sitecore/content/MyWebsiteTree//*" -Language * -Version *; 
foreach ($item in $allItems) {
    foreach ($field in $item.Fields)
    {
        if ($field.Id -eq $RichTextContentID -and ($field.Value -match $internalLinkPattern))
        {
           Process-RichText $field $internalLinkPattern $item;
        }
    }
}


if ($global:guiltyItems.Count -eq 0) {
        Show-Alert "Did not find any items to match your condition.";
    } 
else {
    $props = @{
        Title = ""
        InfoDescription = ""
        PageSize = 50
    };

    ($global:guiltyItems) |
        Show-ListView @props -Property @{ Label="Item name"; Expression={$_.Name}; },
            @{ Label="ID"; Expression={$_.ID}; },
            @{ Label="Display name"; Expression={$_.DisplayName}; },
            @{ Label="Language"; Expression={$_.Language}; },
            @{ Label="Version"; Expression={$_.Version}; },
            @{ Label="Path"; Expression={$_.ItemPath}; },
            @{ Label="Created"; Expression={$_.__Created}; },
            @{ Label="Created by"; Expression={$_."__Created by"}; },
            @{ Label="Updated"; Expression={$_.__Updated}; },
            @{ Label="Updated by"; Expression={$_."__Updated by"}; }
}

Close-Window;

謝謝

LE:對象$ allitems需要一段時間才能填充,並且sitecore客戶端不會等待后端讀取所有項目,因此,當我生成報告時,$ global:guiltyItems始終為空。

我找到了解決方案:使用過濾器。 它可以正常工作。

$RichTextContentID = "";
$internalLinkPattern = '<a href="~\/link\.aspx\?_id=(?<sitecoreid>[a-zA-Z\d]{32})&amp;_z=z">';
$literatureTemplateID = "";

$root = Get-Item -Path "master:/sitecore/content/MyWebsite";

filter Where-HasLiterature{
    param([Parameter(Mandatory=$TRUE,ValueFromPipeline=$TRUE)][Sitecore.Data.Items.Item]$item)

    if($item)
    {
        foreach ($field in $item.Fields)
        {
            if ($field.Id -eq $RichTextContentID -and ($field.Value -match $internalLinkPattern))
            {
                $allMatches = [System.Text.RegularExpressions.Regex]::Matches($field.Value,$internalLinkPattern);

                foreach ($match in $allMatches)
                    {
                        $guiltyItem = Get-Item "master:" -Id ([Sitecore.Data.ID]::Parse($match.Groups["sitecoreid"].Value)).Guid;
                        $guiltyItemTemplate = [Sitecore.Data.Managers.TemplateManager]::GetTemplate($guiltyItem);

                        if ($guiltyItem -ne $null -and $guiltyItemTemplate.DescendsFromOrEquals($literatureTemplateID) )
                        {
                            $item;
                        }
                    }   

            }

        }
    }
}

$items = Get-ChildItem -Path $root.ProviderPath -Recurse | Where-HasLiterature

if ($items.Count -eq 0) 
{
    Show-Alert "Did not find any items to match your condition.";
} 
else 
{
    $props = @{
        Title = ""
        InfoDescription = ""
        PageSize = 50
    }

    $items | Show-ListView @props -Property @{ Label="Item name"; Expression={$_.Name}; },
            @{ Label="ID"; Expression={$_.ID}; },
            @{ Label="Display name"; Expression={$_.DisplayName}; },
            @{ Label="Language"; Expression={$_.Language}; },
            @{ Label="Version"; Expression={$_.Version}; },
            @{ Label="Path"; Expression={$_.ItemPath}; },
            @{ Label="Created"; Expression={$_.__Created}; },
            @{ Label="Created by"; Expression={$_."__Created by"}; },
            @{ Label="Updated"; Expression={$_.__Updated}; },
            @{ Label="Updated by"; Expression={$_."__Updated by"}; }
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM