如何在Tridion组件上设置IsPublishedTo状态?

时间:2012-07-04 10:42:45

标签: tridion

从另一个环境恢复Tridion CMS数据库后,我们无法从Broker中取消发布组件。如果我们发布到Broker,那么我们可以取消发布。我们希望将IsPublishedTo状态设置为新环境中可用的发布目标。

TOM API有一个可用于页面和组件模板的SetPublishedTo方法,但不适用于组件。

如何设置Components的PublishedStatus?是否可以使用UpdateXML或我们是否需要执行数据库黑魔术?

2 个答案:

答案 0 :(得分: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设置为UnPublished应该可以满足需要,因为Component在技术上没有发布,它是基于该CT的组件演示。

答案 1 :(得分:4)

组件本身永远不会从Tridion发布,它们只作为组件演示(组件+组件模板)的一部分发布。

组件模板上的SetPublishedTo方法将Component作为参数。因此,通过调用它,您可以将一个组件表示设置为已发布或未发布。

取消发布组件的所有组件演示文稿后,该组件将隐式变为未发布。

相关问题