Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion 2009 TBB: How do I determine if a Page is published to particular publication target?

Tags:

c#

tridion

In a TBB using the TOM.NET API I want to get a list of pages which are published - basically I'm building a sitemap. I am trying to determine if a Tridion.ContentManager.CommunicationManagement.Page is published.

There doesn't seem to be an IsPublished property or the IsPublishedTo method.

Is there a Filter condition I can add? E.g.

pageFilter.Conditions["Published"] = "true";

In response to comments:

I'm using the TOM.NET API and I want to get a list of pages which are published - basically I'm building a sitemap.

It seems like the PublicationEngine.IsPublished method is returning "true" if the page is published to the given target anywhere within the BluePrint hierarchy. This doesn't seem like expected behaviour.

like image 464
Rob Stevenson-Leggett Avatar asked Dec 09 '22 01:12

Rob Stevenson-Leggett


1 Answers

In this scenario where you have multiple Publications in the BluePrint, you can use the PublishEngine.GetPublishInfo() method against the page you are on and check if the Publication you are publishing from exists in the Publications returned from that method:

IList<RepositoryLocalObject> rlos = structuregroup.GetItems(pageFilter);
List<Page> pages = new List<Page>(rlos.Count);    
foreach (RepositoryLocalObject o in rlos)
{  
    Page p = (Page) o;
    bool isPublished = false;
    ICollection<PublishInfo> publishInfo = PublishEngine.GetPublishInfo(p);
    foreach (PublishInfo info in publishInfo)
    {
        if (info.Publication.Id.ItemId == p.Id.PublicationId)
        {
            isPublished = true;
        }
    }

    if(p != null && isPublished)
    {
        pages.Add(p);
    }
}

You have to be aware that there was a bug in this method where it will always return the current Publication that you are publishing from. This has been fixed in the Hotfix CM_2009.1.74835. You need to apply that otherwise the code above won't work correctly.

like image 165
Ryan Durkin Avatar answered Dec 11 '22 13:12

Ryan Durkin