Tuesday, May 10, 2016

Wrong Way to Patch Processor Params with Sitecore Patch Files

Recently, I had to look into an issue where Sitecore Rich Text Editor starts to display some buttons incorrectly on Hyperlink Manager popup window, as shown below






And when checked using Firebug, I can see that Sitecore is returning 500 error for ScriptResource.axd Urls.


http://<hostname>/ScriptResource.axd?d=5WkzNtzG0Iu_bSt84IS-lYFjFGuFXd3pdFFzPJGdqcFIuGYf2XpqGIuCBTqN9bJIQAaJ2kch7IJgHvqLtwY9fHsn0fn-cX5VNiqGRLNDhdxtCd6aGXAbZEUgdiGQtJ1ktTGlF3pRIhHkY1NQhI_YZAHBEZQLMlfWmgnlHln8D8A1&t=40eb3b32




When checked with ShowConfig.aspx, it turns out to be "Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions" processor has been removed from "preprocessRequest" pipeline.

So, when checked our custom configuration files added into /App_Config/Includes/zzz folder, I can see there was a configuration file with following configurations. With this, developer has tried to patch Sitecore connfigurations, but in a wrong way.

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <preprocessRequest>
        <processor patch:instead="processor[@type='Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel']" type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel">
          <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, abc</param>
          <param desc="Blocked extensions (comma separated)">*</param>
          <param desc="Blocked extensions that stream files (comma separated)">*</param>
          <param desc="Blocked extensions that do not stream files (comma separated)">
          </param>
        </processor>
      </preprocessRequest>
    </pipelines>
  </sitecore>
</configuration>


As you can see, even though above config has used "patch:instead", it uses same "type" value, which makes Sitecore to totally remove the above processor from configs.

One correct way to achieve above requirement is mention below. That configuration will replace the "param" value with new given value (i.e. "aspx, ashx, asmx, abc")


<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <preprocessRequest>
        <processor type='Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel'>
          <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, abc</param>
          </param>
        </processor>
      </preprocessRequest>
    </pipelines>
  </sitecore>
</configuration>

Happy Sitecore !!

Monday, May 2, 2016

Usage of Publishing.PublishEmptyItems Setting

Recently we had a discussion in Sitecore Community forum regarding a template container (template folder) not getting published and it causes the child templates also remove from web database.

The reason for this issue was the template container (template folder item) did not had any language versions defined. It was only an empty item without any versions.

One of friends from community suggested to adjust the Publishing.PublishEmptyItems setting to true, to allow Sitecore to publish empty items.

<!--
    PUBLISHING PUBLISH EMPTY ITEMS
    Specifies whether empty items (i.e. items without publishable versions) should be published.
    Default value: false
-->
<setting name="Publishing.PublishEmptyItems" value="false" />

But, eventhough that setting will solve this above issue mentions, can cause some serious side effects.


Sitecore had bugs related to empty item versions getting created automatically without knowledge of editors.

First senario I faced this was with Sitecore 6.6 release.
In that initial version of Sitecore, when a item created with a other language than 'en' language, Sitecore automatically created an empty item version in 'en' language also. (Sitecore Bug)

Also, recently I saw a same kind of issue on community forum, where empty item versions getting created with Sitecore 8.1 update-1.
https://community.sitecore.net/developers/f/8/t/2616


So, setting the Publishing.PublishEmptyItems setting to 'true' will cause these empty items to be get published.


So, correct way (or best practice) would be to create versions for the Containers/Folders also, which will allow publishing to work accordingly, while keeping the Publishing.PublishEmptyItems setting to "false"


Happy Sitecore!!