Future publish in Sitecore Part 1

Hello,

I think all of us tried this at some point looking at out of the box features and surprise surprise you cannot do it 🙂

So here is my approach and it is a very simple one which can be extended in a much more complex piece of code but for my requirements it will do.

I have created a cs file with the code:  AutomatedPublish (not sure if its a English word)

public class AutomatedPublish
{
public void FuturePublish(Item[] items, Sitecore.Tasks.CommandItem command, Sitecore.Tasks.ScheduleItem schedule)
{
foreach (var item in items)
{
// The publishOptions determine the source and target database,
// the publish mode and language, and the publish date
Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(
item.Database,
Database.GetDatabase("web"),
Sitecore.Publishing.PublishMode.SingleItem,
item.Languag,System.DateTime.Now);

// Create a publisher with the publishoptions
Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

// Choose where to publish from
publisher.Options.RootItem = item;

// Publish children as well?
publisher.Options.Deep = false;

// Do the publish!
publisher.Publish();
}
}
}

In sitecore you will have to create the command in the System -> Tasks -> Commands.

Continue reading

Sitecore fun fact #1

Hello,

I came across this funny fact today:

  1. If a parent item has an unpublished date set up, lets say today and you save the setting but you don’t publish the change to the web.
  2. Then you go to a child item and publish it.It will delete everything that sits under the parent item to the child but it will not show any warning message like: the version you try to publish will be not displayed. Is life fare ?!?! I don’t know. But it should be some kind of message(my opinion!?).
  3. The only error you will get is this “layout not found” which will make you crazy and will force you to start republishing layouts and sublayouts and eventually punch the monitor 🙂 (which I did, but this may not apply to all)

VP