2012-07-04 20 views
4

從其他環境中恢復Tridion CMS數據庫後,我們無法從代理中取消發佈組件。如果我們發佈給經紀商,那麼我們可以取消發佈。我們希望將IsPublishedTo狀態設置爲新環境中可用的發佈目標。如何在Tridion組件上設置IsPublishedTo狀態?

TOM API有一個SetPublishedTo方法可用於頁面和組件模板,但不包含組件。

如何設置組件的PublishedStatus?是否有可能使用UpdateXML或我們需要執行數據庫黑魔法?

回答

5

我使用一個命令行工具,下面的C#基於代碼的支持SDL Tridion 2009年環境切換後切換我的所有項目的PublishStates(您正在使用什麼版本?):

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Tridion.ContentManager.Interop.TDS; 
using Tridion.ContentManager.Interop.TDSDefines; 
using System.Xml; 

namespace SetAllItemsAsUnpublished 
{ 
    /// <summary> 
    /// A command line script that can enable/disable users 
    /// </summary> 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      TDSE tdse = new TDSE(); 
      User currentUser = tdse.User; 
      ListRowFilter listRowFilter = tdse.CreateListRowFilter(); 
      String xpath = "/tcm:ListPublishItems/*/*[local-name()='Page' or local-name()='Component']"; 
      listRowFilter.SetCondition("Recursive", true); 
      listRowFilter.SetCondition("OnlyPublishedPages", true); 
      listRowFilter.SetCondition("OnlyPublishedCPs", true); 


      //listRowFilter.SetCondition("ItemType", ItemType.ItemTypePage); 

      XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); 
      nsmgr.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0"); 

      //Check that the user running the script is an Administrator 
      if (currentUser.privileges == TDSPrivileges.TdsPrivilegeSystemAdministrator) 
      { 
       Publications publications = tdse.GetPublications(); 
       Console.WriteLine("There are " + publications.Count + " to be processed"); 
       int i = 0; 
       foreach (Publication publication in tdse.GetPublications()) 
       { 
        ++i; 
        Console.WriteLine(" - Processing " + publication.Title + "(" + i + " of " + publications.Count + ")"); 
        foreach(PublicationTarget target in tdse.GetPublicationTargets()){ 
         Console.Write("  checking target: " + target.Title); 
         XmlDocument publishedItemsXml = new XmlDocument(); 
         try 
         { 
          publishedItemsXml.LoadXml(publication.GetListPublishItems(target.ID, false, false, ListColumnFilter.XMLListID, listRowFilter)); 
          foreach (XmlElement publishedItemNode in publishedItemsXml.SelectNodes(xpath, nsmgr)) 
          { 
           String uri = publishedItemNode.Attributes["ID"].Value; 
           Console.Write("."); 
           if (publishedItemNode.LocalName == "Page") 
           { 
            Page page = (Page)tdse.GetObject(uri, EnumOpenMode.OpenModeView, publication, XMLReadFilter.XMLReadAll); 
            page.SetPublishedTo(target, false, currentUser); 
            if (page.Info.IsCheckedOut) 
            { 
             page.CheckIn(true); 
            } 
           } 
           else 
           { 
            foreach (XmlElement ctRenderNode in publishedItemNode.SelectNodes("tcm:RenderWith", nsmgr)) 
            { 
             String uriCT = ctRenderNode.Attributes["ID"].Value; 
             ComponentTemplate ct = (ComponentTemplate)tdse.GetObject(uriCT, EnumOpenMode.OpenModeView, publication, XMLReadFilter.XMLReadAll); 
             ct.SetPublishedTo(uri, target, false, currentUser); 
             if (ct.Info.IsCheckedOut) 
             { 
              ct.CheckIn(true); 
             } 
            }         
           } 
          } 
          Console.WriteLine(); 
         } 
         catch (Exception e) 
         { 
          Console.WriteLine(e.Message); 
         } 
        } 
       } 
      } 
      else 
      { 
       //Warn when there is a non-admin user running the script 
       Console.WriteLine("You must be an SDL Tridion CMS Administrator to run this application"); 
      } 
      Console.WriteLine(); 
      Console.WriteLine("Done! Hit ENTER key to close"); 
      Console.ReadLine(); 
     } 
    } 
} 

所以基本上設置未發佈的CT應該做你所需要的,因爲該組件在技術上沒有發佈,它是基於該CT的組件演示。

+0

非常感謝優秀的代碼示例!我正在使用Tridion 2011,很幸運,它與TOM向後兼容。我會根據恢復的系統中的可用目標對其進行調整,因爲我們也恢復了我們的Broker數據庫,然後全部同步。 Muchos gracias! – robrtc

+0

在Tridion 2013 SP1中,您可以使用核心服務中的新DecommissionPublicationTarget方法將所有項目設置爲未發佈。 – robrtc

4

組件本身從未從Tridion發佈,它們僅作爲組件展示(組件+組件模板)的一部分發布。

組件模板上的SetPublishedTo方法將組件作爲參數。所以通過調用它可以將一個組件演示文稿設置爲已發佈或未發佈。

一旦您未發佈組件的所有組件演示文稿,該組件將隱式變爲未發佈。

+0

感謝您的解釋 - 合理!我沒有看到Component Template的實現,因爲我期待看到Component。我想我們也可以在PageTemplate而不是Page上實現它。也許從歷史上講,首先添加Page方法,然後再添加ComponentTemplate方法。 – robrtc

+0

當我第一次需要爲我的二進制事件跟蹤器設置已發佈狀態時,我有同樣的困惑:http://www.sdltridionworld.com/community/2011_extensions/binaryeventtracker.aspx。在那種情況下,確實沒有一個正確的CT,因爲擴展實際上處理了隱式發佈的二進制文件:那些通常不使用CT的文件。最後,我們讓用戶配置一個CT,它工作正常,因爲對於隱式二進制文件,CT無論如何都是毫無意義的。 –

相關問題