【问题标题】:How to set IsPublishedTo status on a Tridion Component?如何在 Tridion 组件上设置 IsPublishedTo 状态?
【发布时间】:2012-07-04 20:42:56
【问题描述】:

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

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

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

【问题讨论】:

    标签: tridion


    【解决方案1】:

    我在命令行工具中使用以下基于 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 应该可以满足您的需要,因为组件在技术上并未发布,它是基于该 CT 的组件表示。

    【讨论】:

    • 非常感谢优秀的代码示例!我正在使用 Tridion 2011,幸运的是它向后兼容 TOM。我将对其进行调整以将其设置为已为恢复系统中可用的目标发布,因为我们也恢复了我们的代理数据库,然后一切都是同步的。非常感谢!
    • 在 Tridion 2013 SP1 中,您可以使用核心服务中的新 DecommissionPublicationTarget 方法将所有项目设置为未发布。
    【解决方案2】:

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

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

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

    【讨论】:

    • 感谢您的解释 - 有道理!我没有看 Component Template 的实现,因为我期待看到 Component。我想我们也可以在 PageTemplate 而不是 Page 上实现它。也许从历史上看,Page 方法是先添加的,然后是 ComponentTemplate 方法。
    • 当我第一次需要为我的二进制事件跟踪器设置发布状态时,我也有同样的困惑:sdltridionworld.com/community/2011_extensions/…。在那种情况下,确实没有正确的 CT,因为扩展实际上处理隐式发布的二进制文件:通常不使用 CT 的二进制文件。最后,我们让用户配置一个 CT,这很好,因为对于隐式二进制文件,CT 无论如何都毫无意义。
    猜你喜欢
    • 2021-11-21
    • 1970-01-01
    • 2018-08-13
    • 2020-10-06
    • 1970-01-01
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    相关资源
    最近更新 更多