Sitecore Stuff and Such

- by Christian Kay Linkhusen

NAVIGATION - SEARCH

Publish Item from the Context Menu

A nice feature in Sitecore when you are editing Items from the Content Editor, is the Context Menu. Here are almost all functions you'll need when working with Items. Create new, Copy, Delete, Rename Item and more. But one feature that is missing is the possibility to publish your Items.
But don't cry yourself to sleep anymore over this, because this little tip will fix this small issue for you :)

In Sitecore open the Desktop and switch to the Core Database. Here you'll find how Sitecore is build up inside Sitecore, so be carefull not to mess it all up inside here! 

Next you wil have to navigate to the Menu Item for Publish Item. This you will find on the path: "/sitecore/content/Applications/Content Editor/Menues/Publish/Publish Item"

Then you just have to copy the Publish Item menu item to the Default Context menu. This is done by selecting Copying -> Copy to and select the destination: "/sitecore/content/Applications/Content Editor/Context Menues/Default"

Last thing you just have to do is to sort the new Menu Item in the Context menu, making it appear in a logical order in the menu. Go to the Default Context menu in the Content editor: "/sitecore/content/Applications/Content Editor/Context Menues/Default", and just sort the Publishing Item to the position you find best.

That's all - shift back to the Master database and start publishing your Sitecore Items from the Context Menu. 

Update Items without changing theirs statistics

I have a small tip to you, when you have to update items in your Sitecore solution from a batch job or a script correcting data on several items in the solution. It is possible to accomplice this without changing the fields "Updated by" and "Updated", there by your script will not overwrite the original data about, who updated the item and when.
 
This is simply done by setting the updateStatistics flag to false when editing the Item.

    using (new SecurityDisabler())
    {
        var items = Sitecore.Context.Item.Children;
        foreach (var scItem in items)
        {
            using (new EditContext(scItem, false, false))
            {
                //update whatever data on your childitem you have to correct
                //without changing the statistics fields
            }
        }
    }

Thats all folks - hapii coding ;)


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.

Problems with Reminders not being sent in Sitecore CM/CD setup

If you set up the reminder function in Sitecore, and you have a Multi server setup with Content Manager and Content Delivery instances, you may run into problems with reminders not being sent.

The problem is that the TaskDatabaseAgent are running on both the CM- and the CD instance in your Sitecore setup, and if the Master database is disabled on the CD instance, the sending of the reminder will fail. In the Sitecore logfiles on the CD instance you will find log entries like this one:


ManagedPoolThread #13 14:34:25 ERROR Exception in task
Exception: System.InvalidOperationException
Message: Could not find configuration node: databases/database[@id='master']
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.IsTrue(Boolean condition, String message)
   at Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert)
   at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
   at Sitecore.Configuration.Factory.GetDatabase(String name, Boolean assert)
   at Sitecore.Tasks.EmailReminderTask.SendReminder()
   at Sitecore.Tasks.TaskDatabaseAgent.Run()

ManagedPoolThread #13 14:34:25 INFO  Executing email reminder task
ManagedPoolThread #13 14:34:25 INFO  Parameters: <r><to>xyz@domain.net</to><txt>Påmindelse kl 13:41 - ckl</txt></r>
ManagedPoolThread #13 14:34:25 ERROR Exception in task
Exception: System.InvalidOperationException
Message: Could not find configuration node: databases/database[@id='master']
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.IsTrue(Boolean condition, String message)
   at Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert)
   at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
   at Sitecore.Configuration.Factory.GetDatabase(String name, Boolean assert)
   at Sitecore.Tasks.EmailReminderTask.SendReminder()
   at Sitecore.Tasks.TaskDatabaseAgent.Run()

ManagedPoolThread #13 14:34:25 INFO  Job ended: Sitecore.Tasks.TaskDatabaseAgent (units processed: )

The solution to the problem is to disable the TaskDatabaseAgent on the CD instance. This is done by setting the interval to 00:00:00 on the TaskDatabaseAgent in the web.config file.

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


Once you have solved the problem, you might receive a reminder mail from each database for every item where a reminder was created in Sitecore. How to solve this problem you can read about in this  blog: Receiving the same reminder twice :)

Single Sign On to the Sitecore desktop

When you use Sitecore Active Directory module it is possible to set up Single Sign On by protecting the file LDAPLogin.aspx with Windows Authentication. Then it is possible to login to Sitecore without entering username and password, when you enter the following URL: http://[yoursite]/sitecore/admin/LDAPLogin.aspx.
This will login the user to the Content Editor or the StartURL entered on the users User Profile in Sitecore.

But what if you want to make it possible for the users to decide for them self, if they would like to login to the Desktop or the Content Editor?