【问题标题】:In Sitecore powershell, can you make an item unpublishable在 Sitecore powershell 中,您可以将项目设为不可发布吗
【发布时间】:2015-08-11 19:12:14
【问题描述】:

在 Sitecore 7.2 的 Sitecore Powershell 中...

是否可以对给定项目设置“可发布”权限(使其不可发布)?

具体来说,我希望自动化以下过程:选择一个项目,打开Publish > Restrictions > Change,单击项目选项卡,然后取消选中“可发布”框。

我试过找到一个项目的属性,但没有运气。我认为这可能有效,但“__Publishable”不正确:

(get-item -Path master:/sitecore/content/Path/Home/About-Us)."__Publishable"

有没有办法让 Powershell 报告项目的所有属性?

【问题讨论】:

    标签: powershell sitecore


    【解决方案1】:

    使项目不可发布的字段是:

    __Never publish

    所以你可以这样做:

    (get-item -Path master:/sitecore/content/DIAGlobal/Home/About-Us)."__Never publish"
    

    或者,如果您想像后端代码一样编辑它,您可以这样做:

    $item = Get-Item master:/sitecore/content/DIAGlobal/Home/About-Us
    $item.Editing.BeginEdit()
    $item["__Never publish"] = "1"
    $item.Editing.EndEdit()
    

    可以在此处找到有关如何使用 Powershell 读取和编辑字段的一些很好的示例:http://blog.najmanowicz.com/2014/10/12/working-with-sitecore-items-in-powershell-extensions/

    【讨论】:

    • 谢谢,这是一个很好的提示。我要补充一点,在“继承”选项卡中的模板项上可以找到所有属性。 “__Hide version”属性也非常适合使特定内容可发布/不可发布。
    【解决方案2】:

    我有下一个脚本

        function GetItemDatasources {
        [CmdletBinding()]
        param([Item]$Item)
      
        # grab all datasources that are not header and footer elements
        return Get-Rendering -Item $item -FinalLayout -Device (Get-LayoutDevice -Default) |
            Where-Object { -not [string]::IsNullOrEmpty($_.Datasource)} |
            Where-Object { $_.Placeholder -ne 'Above Page Content' } |
            Where-Object { $_.Placeholder -ne 'Below Page Content' } |
            ForEach-Object { Get-Item "$($item.Database):" -ID $_.Datasource }
            # ForEach-Object { Write-Host ($_ | Format-List | Out-String) }
    }
      
    $location = get-location
      
    $languages = Get-ChildItem "master:\sitecore\system\Languages"
    $currentLanguage = [Sitecore.Context]::Language.Name
      
    $langOptions = @{};
      
    $actions = @{};
    $actions["Unpublish"] = "1";
    $actions["Publish"] = "";
      
    foreach ($lang in $languages) {
        $langOptions[$lang.Name] = $lang.Name
    }
      
    $result = Read-Variable -Parameters `
        @{ Name = "destinationLanguages"; Title="Language(s) for publich/unpublish"; Options=$langOptions; Editor="checklist"; },
        @{ Name = "includeSubitems"; Value=$false; Title="Include Subitems"; Columns = 4;},
        @{ Name = "action"; Value="1"; Title="Action"; Options=$actions; Tooltip="Unpublish: Set language as unblishded on all langauge vestions.<br>Publish: Set language as publishded on all langauge vestions."; }`
        -Description "Select languages that should be proceed during updates" `
        -Title "Language Publish - Unpublish" -Width 650 -Height 660 -OkButtonName "Proceed" -CancelButtonName "Cancel" -ShowHints
      
    if($result -ne "ok") {
        Exit
    }
      
    Write-Host "destinationLanguages = $destinationLanguages"
      
    $items = @()
      
    $items += Get-Item $location
      
    # add optional subitems
    if ($includeSubitems) {
        $items += Get-ChildItem $location -Recurse
    }
      
    # Remove any duplicates, based on ID
    $items = $items | Sort-Object -Property 'ID' -Unique
      
    $items | ForEach-Object { Write-Host ($_.ItemPath | Sort-Object | Format-List | Out-String) }
      
    $message = "You are about to publish/unpublish <span style='font-weight: bold'>$($items.Count) item(s)</span> with the following options:<br>"
    $message += "<br><table>"
    $message += "<tr><td style='width: auto'>Languages:</td><td>$destinationLanguages</td></tr>"
    $message += "<tr><td style='width: auto'>Include Subitems:</td><td>$includeSubitems</td></tr>"
    $message += "</table>"
    $message += "<br><p style='font-weight: bold'>Are you sure?</p>"
      
    $proceed = Show-Confirm -Title $message
      
    if ($proceed -ne 'yes') {
        Write-Host "Canceling"
        Exit
    }
      
    Write-Host "Proceeding with execution"
      
    $items | ForEach-Object { 
        $vitems = Get-Item $_.ID -Language $destinationLanguages -Version *
        $vitems | ForEach-Object {
            $_.Editing.BeginEdit()
            $_["__Hide version"] = $action
            $_.Editing.EndEdit()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      相关资源
      最近更新 更多