Sitecore Stuff and Such

- by Christian Kay Linkhusen

NAVIGATION - SEARCH

Receiving the same reminder twice from Sitecore

When using the reminder function in Sitecore the editor will receive the same reminder for every database the Item exists. In a normal setup with a master and a web database this will cause the editor to get the same reminder twice.

If you only want the editors to receive one email (eg. for the master database) it is possible to disable the sending of reminders for other databases by overriding the Sitecore.Tasks.TaskDatabaseAgent in Sitecore.

After reflecting the TaskDatabaseAgent I came up with this implementation, which only execute a EmailReminderTask if it's from the Master database. If it's from another database the task is marked as done, but without executing the Task. 


public class CustomTaskDatabaseAgent : TaskDatabaseAgent
    {
        public new void Run()
        {
            Task[] pendingTasks = Globals.TaskDatabase.GetPendingTasks();
            this.LogInfo("Processing tasks (count: " + (object)pendingTasks.Length + ")");
            foreach (Task task in pendingTasks)
            {
                try
                {
                    task.LogActivity = this.LogActivity;
                    //Test if the Task is the EmailReminderTask and the current database is not master database
                    if (task.GetType() == typeof (EmailReminderTask) && !task.DatabaseName.ToLower().Equals("master"))
                    {
                        //If its not the master database
                        //Only mark the Task as done, dont execute the remider
                        Globals.TaskDatabase.MarkDone(task);
                    }
                    else
                    {
                        task.Execute();    
                    }
                    TaskCounters.TasksExecuted.Increment();
                }
                catch (Exception ex)
                {
                    Log.Error("Exception in task", ex, task.GetType());
                }
            }
        }

        private void LogInfo(string message)
        {
            if (!this.LogActivity)
                return;
            Log.Info(message, (object)this);
        }
    }


The custom DatabaseAgent is enabled by changing the Sitecore.Tasks.DatabaseAgent in the web.config file.


//Default TaskDatabaseAgent
<agent type="Sitecore.Tasks.TaskDatabaseAgent" method="Run" interval="00:10:00"/>

//Custom TaskDatabaseAgent
<agent type="Netmester.SitecoreExtensions.CustomTaskDatabaseAgent" method="Run" interval="00:10:00"/>
	

Now the editor will only receive one email pr. reminder, which is the one from the Master database.

Comments (1) -

Scott Freeman

Nice blog post! I'm currently upgrading to Sitecore 8.1 and stumbled across it while researching  an exception. My editors have been getting duplicate emails for some time. They will be very happy to hear a solution is coming in the new release.

Reply

Add comment