I am working on some event system code and I have the following snippet of code to examine the PublishQueue and see if the current item I am scheduling is already scheduled:
public static bool IsInPublishingQueue(Session session, String tcmUri, Int32 state, Int32 action, DateTime date, PublicationTarget publicationTarget)
{
try
{
PublishTransactionsFilter filter = new PublishTransactionsFilter(session);
filter.PublishTransactionState = PublishTransactionState.ScheduledForPublish;
filter.StartDate = date;//Convert.ToDateTime("4/1/2013 1:46 PM");
RepositoryLocalObject item = session.GetObject(tcmUri) as RepositoryLocalObject;
filter.ForRepository = item.ContextRepository;
if (publicationTarget != null)
{
filter.PublicationTarget = publicationTarget;
}
XmlElement element = PublishEngine.GetListPublishTransactions(filter);
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
namespaceManager.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
//String xPath = String.Format("tcm:ListPublishTransactions/tcm:Item[@ItemID='{0}']", tcmUri);
String xPath = String.Format("//*[@ItemID='{0}' and @State='{1}' and @Action={2}]", tcmUri, state, action);
XmlNodeList nodeList = element.SelectNodes(xPath, namespaceManager);
return nodeList.Count > 0;
}
catch (Exception ex)
{
throw new Exception("IsInPublishQueue Function Failed for Item with tcm: " + tcmUri + "Error: " + ex.Message);
}
}
The problem is that this results in an empty result set:
<tcm:ListPublishTransactions xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" />
When I change it to the following I get back the set of items in the queue that match the Start date in my filter:
public static bool IsInPublishingQueue(Session session, String tcmUri, Int32 state, Int32 action, DateTime date, PublicationTarget publicationTarget)
{
try
{
PublishTransactionsFilter filter = new PublishTransactionsFilter(session);
//filter.PublishTransactionState = PublishTransactionState.ScheduledForPublish;
filter.StartDate = date;//Convert.ToDateTime("4/1/2013 1:46 PM");
RepositoryLocalObject item = session.GetObject(tcmUri) as RepositoryLocalObject;
filter.ForRepository = item.ContextRepository;
if (publicationTarget != null)
{
filter.PublicationTarget = publicationTarget;
}
XmlElement element = PublishEngine.GetListPublishTransactions(filter);
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
namespaceManager.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
//String xPath = String.Format("tcm:ListPublishTransactions/tcm:Item[@ItemID='{0}']", tcmUri);
String xPath = String.Format("//*[@ItemID='{0}' and @State='{1}' and @Action={2}]", tcmUri, state, action);
XmlNodeList nodeList = element.SelectNodes(xPath, namespaceManager);
return nodeList.Count > 0;
}
catch (Exception ex)
{
throw new Exception("IsInPublishQueue Function Failed for Item with tcm: " + tcmUri + "Error: " + ex.Message);
}
}
This is the result set I get back which is what I expect:
<tcm:ListPublishTransactions xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<tcm:Item ID="tcm:0-1570-66560" Title="Article 2A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6009" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="1" State="0" StateChangeDate="2013-03-04T02:32:22" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />
<tcm:Item ID="tcm:0-1569-66560" Title="Article 1A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6008" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="1" State="0" StateChangeDate="2013-03-04T02:32:21" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />
<tcm:Item ID="tcm:0-1566-66560" Title="Article 2A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6009" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="0" State="0" StateChangeDate="2013-03-04T02:28:11" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />
<tcm:Item ID="tcm:0-1565-66560" Title="Article 1A" Publication="www.website.com" PublicationTarget="Staging" ItemType="16" ItemID="tcm:49-6008" ItemPath="\\www.website.com\\Building Blocks\\www.website.com" Action="0" State="0" StateChangeDate="2013-03-04T02:28:11" ScheduleDate="2013-04-01T13:46:19" UserId="tcm:0-13-65552" User="TestVM\\Administrator" Priority="4" Icon="T16L0P0" Managed="0" Allow="67133440" Deny="0" />
Any ideas why with the:
filter.PublishTransactionState = PublishTransactionState.ScheduledForPublish;
filter item the result set returns empty, when it should return the same result set as the second snippet of code which doesn’t have that filter option(the State=”0”, as seen above in bold is the indicator that the item is scheduled for publish)?