问题
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.
回答1:
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.
回答2:
You should use OrganizationalItemItemsFilter
:
var filter = new OrganizationalItemItemsFilter(session);
filter.BaseColumns = ListBaseColumns.Extended;
var structureGroup = (StructureGroup)session.GetObject("tcm:2-5-4");
var result = structureGroup.GetListItems(filter);
It will return you list like this:
<tcm:ListItems Managed="68" ID="tcm:2-5-4" xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
<tcm:Item ID="tcm:2-46-64" Title="p" Type="64" Modified="2012-03-19T16:21:10" IsNew="false" Icon="T64L0P0" IsPublished="false" Lock="0" IsShared="false" IsLocalized="false" Trustee="tcm:0-0-0" />
</tcm:ListItems>
You can check properties of OrganizationalItemItemsFilter
for some more nice parameters, like Recursive
, or IncludePathColumn
But be careful with this approach, as it will only tell you if it is published anywhere, but not necessary to publication target you expect.
回答3:
After searching by filter, you can try to use the PublishEngine.IsPublished method:
public static bool IsPublished(
IdentifiableObject item,
PublicationTarget publicationTarget
)
Returns whether the given item is published at the specified PublicationTarget.
回答4:
I'm not really understanding your statement, is published to a particular Publication. A Page resides inside a Publication and can be published to one or more Publication Targets (and this can be done for every Publication that Page resides in, in case it is Blue Printed).
So to find out if a certain page is published, you need to check if it is published to at least one target. This you can do directly in the list, by means of the OrganizationalItemItemsFilter. The returned list will show you per item whether or not it is published:
<tcm:Item ID="tcm:2-46-64" Title="p" Type="64" Modified="2012-03-19T16:21:10" IsNew="false" Icon="T64L0P0" IsPublished="false" Lock="0" IsShared="false" IsLocalized="false" Trustee="tcm:0-0-0" />
Here you see that Page tcm:2-46-64 is not published. if we investigate the unique ID of that Page further we see that it resides in Publication tcm:0-2-1 (the Publication ID is the first number in the TCM URI of an Item).
Now if the attribute IsPublished would have the value "true", this would indicate that this Page (in its Publication) is published to at least one target.
To find out to which target that page is published, you can use the PublishEngine.IsPublished method. The IdentifiableObject you need to specify as the first parameter, will be that of your Page. It doesn't matter if we are talking about a shared (BluePrinted), localized or local item. The Publication ID in the TCM URI of your Page will tell you from what Publication the Page is Published in this case.
Please note you need to use the 3rd overload: IsPublished(IdentifiableObject item, PublicationTarget publicationTarget, bool isPublishedInContext) and set the last parameter to true. This will get you the Publish Status for the specified item only, and not for any of its (BluePrint) parents or children.
来源:https://stackoverflow.com/questions/9772321/tridion-2009-tbb-how-do-i-determine-if-a-page-is-published-to-particular-public