News Mover for the Web Database

Image

I recently needed to create a process that would run in the CD (content delivery) environment. This process will create items that need to be organized with folders and the CD environment only has access to the Web database.We decided to use the News Mover module to accomplish this. it does a great job of organizing items by using the value of a date field on the item to create configurable folders that correspond to the date. Unfortunately it does not work on the Web database. Well, it didn't. Until now.

The Problem

The configuration for News Mover adds an item:saved event handler. This handler has a <database> node that is set to master by default. Unfortunately this setting is not actually used by the code at any time.[code language="xml" highlight="3"]<event name="item:saved"> <handler type="Sitecore.Sharedsource.Tasks.NewsMover, Sitecore.Sharedsource.NewsMover" method="OnItemSaved"> <database>master</database> <templates hint="raw:AddTemplateConfiguration"> <template id="user defined/newsarticle" sort="Descending"> <DateField>releasedate</DateField> <YearTemplate formatString="yyyy">Common/Folder</YearTemplate> <MonthTemplate formatString="MMMM">Common/Folder</MonthTemplate> <DayTemplate formatString="dd">Common/Folder</DayTemplate> </template> </templates> </handler></event>[/code]Here we see that the database name is never set to anything by the code:

database_name_property

The Solution

The News Mover template settings are consumed via the Configuration Factory. For flexibility I decided to add a database property to each template definition so they can be configured in a more granular manner. Now each TemplateConfiguration has its own Database property that it will use for its operations.Updated config:[code language="xml" highlight="6"]<event name="item:saved"> <handler type="Sitecore.Sharedsource.Tasks.NewsMover, Sitecore.Sharedsource.NewsMover" method="OnItemSaved"> <database>web</database> <templates hint="raw:AddTemplateConfiguration"> <template id="user defined/newsarticle" sort="Descending"> <Database>web</Database> <DateField>releasedate</DateField> <YearTemplate formatString="yyyy">Common/Folder</YearTemplate> <MonthTemplate formatString="MMMM">Common/Folder</MonthTemplate> <DayTemplate formatString="dd">Common/Folder</DayTemplate> </template> </templates> </handler></event> [/code]The TemplateConfigurationBuilder will read this new property and use the value to get a Sitecore Database that will be passed into the TemplateConfiguration constructor. Now each template definition can be set to use any database that the environment has access to.

Source Code

I've committed these changes in a fork of the News Mover source: https://github.com/NotIsNull/NewsMover. A pull request has been submitted to the original author so it can be incorporated into the official source: https://github.com/JimmieOverby/NewsMover.