如何在 Tridion 组件上设置 IsPublishedTo 状态? [英] How to set IsPublishedTo status on a Tridion Component?

查看:25
本文介绍了如何在 Tridion 组件上设置 IsPublishedTo 状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After a Tridion CMS Database restore from another environment we cannot unpublish Components from the Broker. If we publish to the Broker then we can unpublish. We want to set the IsPublishedTo status to the publish targets available in the new envioronment.

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

The TOM API has a SetPublishedTo method available for Pages and Component Templates but not Components.

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

How can I set the PublishedStatus for the Components? Is it possible using UpdateXML or do we need to perform database black magic?

推荐答案

我在命令行工具中使用以下基于 C# 的代码,用于在 SDL Tridion 2009 环境切换后切换我所有项目的 PublishStates(您使用的是什么版本)?):

I use the following C# based code in a command line tool for switching the PublishStates of all my items after a SDL Tridion 2009 environment switch (What version are you using?):

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 的组件演示.

So basically setting the CT to UnPublished should do what you need, as the Component is not technically published, it is a Component Presentation based on that CT.

这篇关于如何在 Tridion 组件上设置 IsPublishedTo 状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆