Disabling Sitecore search index update during package install will speed up the installation, making it noticable quicker for large packages. We found a good blog post about this by Alex Shyba. During the implementation of that solution we found an enhancement to do.
Instead of enabling the indexing again after the user clicks “close” in the installation wizard this tutorial will re-enable it directly after the installation is finished (before the user clicks close). This will avoid having the indexing disabled if you open another window or browse away from the sitecore gui directly after installing and not clicking close.
This code is tested in Sitecore 8.
1. Custom packager class
Add a new class that will handle enable and disable indexing and make it look like this (code borrowed from Alex Shyba)
namespace SCUSAINC.Custom.Packager
{
using System;
using Sitecore.Reflection;
using Sitecore.Web.UI.HtmlControls;
using Sitecore.Web.UI.Sheer;
using Sitecore.Shell.Applications.Install.Dialogs.InstallPackage;
public class CustomInstallPackageForm : InstallPackageForm
{
[HandleMessage("installer:setTaskId")]
private void OnSetTaskId(Message message)
{
var obj = this as InstallPackageForm;
ReflectionUtil.CallMethod(typeof(InstallPackageForm), obj, "SetTaskID", true, true, new object[] { message });
}
[HandleMessage("installer:commitingFiles")]
private void OnCommittingFiles(Message message)
{
var obj = this as InstallPackageForm;
ReflectionUtil.CallMethod(typeof(InstallPackageForm), obj, "OnCommittingFiles", true, true, new object[] { message });
}
protected Checkbox DisableIndexing;
protected override void OnLoad(EventArgs e)
{
DisableIndexing.Checked = false;
base.OnLoad(e);
}
protected override void OnNext(object sender, EventArgs formEventArgs)
{
base.OnNext(sender, formEventArgs);
if (Active == "Installing" && DisableIndexing.Checked)
{
Sitecore.Configuration.Settings.Indexing.Enabled = false;
}
}
protected override void EndWizard()
{
base.EndWizard();
if (DisableIndexing.Checked)
{
DisableIndexing.Checked = false;
Sitecore.Configuration.Settings.Indexing.Enabled = true;
}
}
}
}
2. Copy install package wizard
Copy /sitecore/shell/Applications/Install/Dialogs/Install package/Install Package.xml to /sitecore/shell/override Open that file and edit the codebeside attribute to this:
<WizardForm Application="Tools/Installer/InstallationWizard" CodeBeside="SCUSAINC.Custom.Packager.CustomInstallPackageForm,SCUSAINC.Custom ">
Also add a checkbox to that xml markup between GridPanel and WizardFormIndent
...
</GridPanel>
<Checkbox ID="DisableIndexing" Header="Disable search index update during the install" Checked="True" />
</WizardFormIndent>
...
3. Enhancing functionality
The code above is, as said before, borrowed from Alex. Now to enhance this code to re-enable the indexing directly after package is installed but before clicking the close button. Open web.config and search for packageinstall:ended and edit it to look like this:
<event name="packageinstall:ended">
<handler type="SCUSAINC.Custom.Packager.CustomInstallPackageForm, Website" method="OnPackageInstallEnded" />
</event>
Now go back to the CustomInstallPackageForm and lets edit it to look like this instead:
namespace SCUSAINC.Custom.Packager
{
using System;
using Sitecore.Reflection;
using Sitecore.Web.UI.HtmlControls;
using Sitecore.Web.UI.Sheer;
using Sitecore.Shell.Applications.Install.Dialogs.InstallPackage;
public class CustomInstallPackageForm : InstallPackageForm
{
private static Checkbox IndexingIsDisabledCheckbox;
[HandleMessage("installer:setTaskId")]
private void OnSetTaskId(Message message)
{
var obj = this as InstallPackageForm;
ReflectionUtil.CallMethod(typeof(InstallPackageForm), obj, "SetTaskID", true, true, new object[] { message });
}
[HandleMessage("installer:commitingFiles")]
private void OnCommittingFiles(Message message)
{
var obj = this as InstallPackageForm;
ReflectionUtil.CallMethod(typeof(InstallPackageForm), obj, "OnCommittingFiles", true, true, new object[] { message });
}
protected Checkbox DisableIndexing
{
get { return IndexingIsDisabledCheckbox; }
set { IndexingIsDisabledCheckbox = value; }
}
protected override void OnLoad(EventArgs e)
{
DisableIndexing.Checked = false;
base.OnLoad(e);
}
protected override void OnNext(object sender, EventArgs formEventArgs)
{
base.OnNext(sender, formEventArgs);
if (Active == "Installing" && DisableIndexing.Checked)
{
Sitecore.Configuration.Settings.Indexing.Enabled = false;
}
}
protected void OnPackageInstallEnded(object sender, EventArgs args)
{
if (DisableIndexing.Checked)
{
DisableIndexing.Checked = false;
Sitecore.Configuration.Settings.Indexing.Enabled = true;
}
}
}
}
The EndWizard() method and contents is removed and replaced by another method called OnPackageInstallEnded(). This method is referenced from web.config. And as said before, it’s a smaller risk that the indexing will be left disabled with this approach. The checkbox needs to be static as well, because the wizard and the callback is run by different threads.
private static Checkbox IndexingIsDisabledCheckbox;
protected Checkbox DisableIndexing
{
get { return IndexingIsDisabledCheckbox; }
set { IndexingIsDisabledCheckbox = value; }
}
Something to think about is that both these solutions might enable indexing for another user if more than one is installing packages at the same time. Thanks to Peter Grace for the ideas!