I'm trying to check if a binary is already published to the target and if not publish it.
private bool isCompToPublish(Component component)
{
bool compToPublish = false;
PublicationTarget target = new PublicationTarget(PublicationTargetId, component.Session);
ICollection<PublishInfo> pubInfoCol = PublishEngine.GetPublishInfo(component);
if (PublishEngine.IsPublished(component, target))
{
if (pubInfoCol.Where(a => a.PublicationTarget.Id == PublicationTargetId).Count() > 0)
{
PublishInfo pubInfo = pubInfoCol.Where(a => a.PublicationTarget.Id == PublicationTargetId).OrderBy(a => a.PublishedAt).Last();
compToPublish = pubInfo.PublishedAt < component.RevisionDate;
}
}
else
{
compToPublish = true;
}
return compToPublish;
}
But in some occasions it suddenly did republish the component. The check if (PublishEngine.IsPublished(component, target))
returned a false, although the binary is published to the target.
I even changed the check to if (PublishEngine.IsPublished(component))
, but still it returns a false.
And when I check the components XML with: component.ToXml(XmlSections.Info).SelectSingleNode("/*/*/*/*[local-name()='IsPublished']").InnerText
it returns a true.
The really weird stuff, is that some of the binaries do behave correctly.
All binaries use the same schema.
Update
I went and checked the database and there is actually something different in the Item_States table.
The binary that goes wrong:
And here the binary that works correctly:
IsPublished
element in the Component XML 300588 gives you false (which indeed appears to be incorrect then)? Maybe check with CS if there is a hotfix related to the incorrect item state.