So whenever I start a new project using the SIM or even a manual installation, I find myself having to remove a bunch of Sitecore Sample data from the Sitecore Master database. Is there a way to automatically remove this data? So that you can start from a blank install each time.
-
What are the sample items are you removing?– jammykamCommented Nov 11, 2016 at 15:14
-
The Sample Sitecore items: Sample Home, Sample Layouts, Sample Workflow, Sample Renderings/Sublayouts, Placeholder Setting, all the Templates that drive those Items. Basically the goal is a blank slate of Sitecore so I can setup the structure I need from there.– Dylan YoungCommented Nov 11, 2016 at 15:57
3 Answers
Option 1
SIM uses a zip archive of the Sitecore root folder, so a simple way to do this would be to take the version of Sitecore you want to setup, install that with the basic options.
Next open up Sitecore and delete all the sample content you do not want. Open SQL Server Management Studio and detach the Core & Master databases.
Finally, locate the original zip file containing the Sitecore root folder for your version and unzip it. It will contain 3 folders:
\Data
\Databases
\Website
The Databases
folder contains the detached MDF and LDF files, so add your updated database files and then re-zip the archive with the same name.
Now when you install that version, it will be using the updated databases with the sample data removed.
Option 2
Make Sitecore PowerShell Extensions part of the default options for installing and write a script that will remove all the sample data.
To remove an item you can get it by ID and call the Remove-Item
cmdlet:
Get-Item master: -ID "{your-guid-here}" | Remove-Item
So get all the paths or ID's of the sample items and create a script to remove them all, run that script once the install is complete.
There are no steps in SIM to clean the default items from the install of Sitecore. You can create a package containing a Post Deploy Step that will delete any items you wish though and add this as a Custom Package in SIM.
Create the following Post Deploy Step:
using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Install.Framework;
using Sitecore.Web;
using System.Collections.Specialized;
namespace Sitecore.CleanSlate
{
public class PostStepDelete : IPostStep
{
public void Run(ITaskOutput output, NameValueCollection metaData)
{
var parameters = WebUtil.ParseParameters(metaData["Attributes"], '|');
Database db = Factory.GetDatabase(parameters["database"]);
string[] items = parameters["items"].Split(',');
foreach (var i in items)
{
Item item = db.GetItem(i);
if (item != null)
{
Log.Info("Post Install Delete : " + item.Paths.FullPath, this);
item.Delete();
}
}
}
}
}
Then create a package using the Package Designer.
- From the ribbon, select
Files statically
and add the DLL containing the Post Deploy step - From the System section, enter the details of the Post Deploy step, e.g.
Sitecore.CleanSlate.PostStepDelete, Sitecore.CleanSlate
- Add the database and items to delete as attributes, e.g.
database
:master
items
:{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9},{4D8A1C4D-1351-4DD1-A502-0660F01FEDC7},{14030E9F-CE92-49C6-AD87-7D49B50E42EA},{1936B96E-DA1F-4A3A-8AAF-8C46268E2D84},{9EB73C4C-1AF7-47C7-85B8-93E08176D4D2},{CE4ADCFB-7990-4980-83FB-A00C1E3673DB},{885B8314-7D8C-4CBB-8000-01421EA8F406},{8AE1C245-A4FA-46AE-9B35-4FBC15F63169},{73BAECEB-744D-4D4A-A7A5-7A935638643F},{A5BC37E7-ED96-4C1E-8590-A26E64DB55EA}
- Generate the package zip
When installing Sitecore using SIM, on the Custom Packages step Add Package and select the zip that was generated earlier and then continue the install as normal.
This is not a SIM specific package, installing it via the Sitecore Installation Wizard will also produce the same result.
What does this delete?
The package has been tested with Sitecore 8.1.3 and 8.2 but it should work with most versions of Sitecore since the item guids should be the same across all versions but please verify if you're on a different version.
The guids specified as the items in the attributes relate to the following items:
{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9} // /sitecore/content/Home
{4D8A1C4D-1351-4DD1-A502-0660F01FEDC7} // /sitecore/media library/Default Website
{14030E9F-CE92-49C6-AD87-7D49B50E42EA} // /sitecore/layout/Layouts/Sample Layout
{1936B96E-DA1F-4A3A-8AAF-8C46268E2D84} // /sitecore/layout/Renderings/Sample
{9EB73C4C-1AF7-47C7-85B8-93E08176D4D2} // /sitecore/layout/Sublayouts/Sample Datasource Sublayout
{CE4ADCFB-7990-4980-83FB-A00C1E3673DB} // /sitecore/layout/Sublayouts/Sample Inner Sublayout
{885B8314-7D8C-4CBB-8000-01421EA8F406} // /sitecore/layout/Sublayouts/Sample Sublayout
{8AE1C245-A4FA-46AE-9B35-4FBC15F63169} // /sitecore/layout/Placeholder Settings/content
{73BAECEB-744D-4D4A-A7A5-7A935638643F} // /sitecore/templates/Sample
{A5BC37E7-ED96-4C1E-8590-A26E64DB55EA} // /sitecore/system/Workflows/Sample Workflow
Add or remove items as required.
Package Download
You can download the package containing the above from here:
https://github.com/jammykam/Sitecore.CleanSlate/tree/master/Module
If you wish to edit the list of items, then open Sitecore.CleanSlate-1.0.0.zip package using an archive tool like 7zip, extract Sitecore CleanSlate.zip\package.zip\metadata\items
file, edit using a text editor and then replace the modified file into the archive.
-
1This in my opinion is the most elegant solution. Because if there's a situation where I don't want a blank slate, I can choose to note install that package. Commented Nov 14, 2016 at 2:19
I'd suggest your "blank slate" need not be so blank at all. So I'm guessing here; but after cleaning out the items and templates you mention, wouldn't you normally proceed to set up a set of folders and items - which remain much the same for any solution?
Even if you don't; I would propose you solve what you're trying to achieve here using Unicorn. Basic principle would be this:
- Install your vanilla version using SIM
- Set up Unicorn for the solution, call the configuration something like "Clean"
- Add all of the target areas e.g.
\sitecore\templates\sample
and so on to Uncicorn configuration - Initialise Unicorn (Serialize All).
- Proceed to delete and remove all the sample items
Now you have a root Unicorn folder, with your "Clean" configuration root folder, and all of the empty root folders of the configuration. Zip that up or copy it somewhere along with your "Clean" config. Next time, all you need to do is drop Unicorn into your solution with your config, run "sync" and voila.
Now for just "cleaning out" sample stuff, this method is likely a bit overkill. But assuming that:
- You use Unicorn for your projects
- You have additional steps you always take, after cleaning out sample items
Then just expand upon the steps above. You'll end up having a Unicorn configuration, your preferred "startup items" all set up. Saves a lot of initial time.