Wednesday, 3 April 2013

Automated Publishing in Sitecore

In the time I have been working with Sitecore I have noticed that a lot of content editors are using the "Publish" button in the U.I. to publish their work, when there is a much easier way of running the publishing process.

In my mind the ideal process is that anything that is ready to be published (either in the final state of a workflow or not in a workflow) should be published automatically without the user having to do anything.

The majority of the time that I have seen this concept implemented is through the use of a workflow action, which works but it means:
  • That for each workflow you have in your site you need to associate the "publish action"
  • Out of the box your related media assets will not be published (unless you use the publishing spider module or a similar concept)
There is a simpler way. In the Sitecore configuration section of your application there is a scheduler, this scheduler can run publish jobs for you. Take a look at the configuration snippet below:


<!-- SCHEDULING -->
<scheduling>
  <!-- Time between checking for scheduled tasks waiting to execute -->
  <frequency>00:00:30</frequency>
  <!-- Agent to publish database periodically -->
  <agent type="Sitecore.Tasks.PublishAgent" method="Run" interval="00:02:00">
   <param desc="source database">master</param>
   <param desc="target database">web</param>
   <param desc="mode (full or smart or incremental)">
     incremental
   </param>
   <param desc="languages">en, da</param>
  </agent>
</scheduling>
This piece of configuration (no code required) will look for new scheduled jobs every 30 seconds. It will then run an incremental publish of the English and Danish languages from master to web every 2 minutes. 

What this means for your users is that they will never need to click "publish" ever again, they will never need to worry about whether or not an image gets published or not and as a developer you get fine grained control over when and what type of publishes occur.

Tuesday, 19 March 2013

Does my Sitecore Item Have a Version in a Specific Language

So, this post is pretty heavily related to my last one "How to get Language Specific Links from Sitecore" and comes from the fact that even if you haven't created a version of your item in a specific language it will act as though it does. The quick snippet for this one is:
if (item.Versions.GetLatestVersion(language).Versions.Count >0)
{
     // you have a version
}
else
{
     // you don't
}
The thing to note here is that "GetLatestVersion" will return you an item, even if it doesn't have a version in the specified language, but the count of versions on that item will be 0.

How to get Language Specific Links from Sitecore

By default Sitecore's Link Manager class will return you a link in the context language, this is great when you have a single language site. If you have a multi-lingual site however, this can be quite annoying, especially if you want to do a "this page is also available in X language". So here is the snippet for doing it, the key part being urlOptions.Language.

public class SomeClass
{
  public void SomeMethod()
  {
    var urlOptions = UrlOptions.DefaultOptions;
    urlOptions.Language = language;
    var link = LinkManager.GetItemUrl(item, urlOptions);
  }
}

How to disable "Add Users" in Sitecore's Platform DXP

 I have seen a few posts going around the community asking how to disable the "Add Users" button in Sitecore Platform DXP.   This ...