0
votes

We are using Sitecore 6.5, and our site is set to auto-publish media items using this guide. All media items are using a custom workflow that is set to default to the Publish state that is the final workflow step and which is set to auto-publish. It works great and it's really lessened the confusion of our web editors.

The issue: if an editor overwrites a media item (say an outdated pdf), the new item doesn't auto-publish. The web editors' have to remember to publish the overwritten item. We have over 500 editors with varying degrees of experience, so this issue comes up often. Does anyone know of a solution for this?

3

3 Answers

1
votes

If auto-publishing the entire media library via a scheduled task or agent is off the table, you might consider hooking into Sitecore's item:saved event (more info on events here).

When this event fires, you can determine if the item being saved is a Media Item using item.Paths.IsMediaItem, and if so, programmatically publish the item (or) trigger the desired workflow state.

0
votes

This is what I've come up with based on Derek's answer, but since I'm new to Sitecore development, do I have this right?

Add handling event to web.config

<event name="item:saved">
  <handler type="SomeNamespace.MediaOverwritePublisher, SomeAssembly" method="OnItemSaved" />
</event>

And then in an assembly in our custom folder I would add:

namespace SomeNamespace
{
    public class MediaOverwritePublisher
    {
        public void OnItemSaved(Object sender, EventArgs args)
        {
            var item = Event.ExtractParameter(args, 0) as Item;

            using (new SecurityDisabler())
            {
                if (item != null)
                {
                    if (item.Paths.IsMediaItem)
                    {
                        var source = Factory.GetDatabase("master");;
                        var target = Factory.GetDatabase("web");;

                        var options = new PublishOptions(source, target, PublishMode.SingleItem, item.Language, DateTime.Now)
                                          {
                                              RootItem = item,
                                              Deep = true,
                                          };

                        var publisher = new Publisher(options);

                        publisher.PublishAsync();
                    }
                }
            }
        }
    }
}
0
votes

This is what I've come up with based on Derek's answer

I would suggest you used Derek’s 2nd suggested option to trigger the workflow. As you already have the workflow set up that you only need to put the item to the state where has the auto publish action.

This should get you started: Sitecore: Assign workflow to an item programmatically

If you still want to publish then I would suggest to get the target database from sitecore in case you have more than on “web” or the name get renamed.

Item itemNotNull = Client.GetItemNotNull("/sitecore/system/publishing targets");
ArrayList arrayList = new ArrayList();
ChildList children = itemNotNull.Children;
foreach (Item item in children)
{
    string name = item["Target database"];
    Database database = Factory.GetDatabase(name, false);
    if (database != null)
     …

}