LibrarySites.Banner

FillDb Updates

Sitecore 7.2 has been released and brings with it a huge amount of changes affecting publishing performance, SPEAK UI, Content Search and more.

Tucked away in that list of changes is a section on the FillDB page:

  • The FillDB.aspx page can now be enabled using the new EnableFillDB setting in the Sitecore.Buckets.config file instead of developers having to modify the aspx file itself. This lets developers create an include file in their dev environment that enables this page, while keeping the page disabled on content management and content delivery instances. (399147)

  • The FillDB.aspx page has been completely reworked. Each step is now optional and lets you specify additional parameters for the step. In addition, the page provides additional steps that can be useful, such as the ability to clear site caches and to reindex all indexes or a specific index. (386884, 388566)

  • When enabled, the FillDB.aspx page now handles POST requests. For example, this lets you write PowerShell scripts that execute this page. In addition, you can specify a "json" parameter to return results as a JSON response. (386884)

In short, the FillDB page is now securable, more flexible and easier to control through automation scripts. Let's see how we can use these features.

Enabling FillDB

The FillDB page is now secured by default. Visiting the page out-of-the-box you'll see this warning:

The EnableFillDB setting can be found in Sitecore.Buckets.config. For a best practice approach, don't update the setting but apply the following patch in a seperate config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <settings>
            <setting name="EnableFillDB">
                <patch:attribute name="value" value="true"/>
            </setting>
        </settings>
    </sitecore>
</configuration>

Save the file as Sitecore.Buckets.Debug.config in the App_Config/Include folder.

Tip: Better yet, save the file in a new Debug folder under App_Config/Include. Sitecore applies config files in alphabetical order and will apply configs from descendant folders too. By creating a Debug folder you can configure your automated deployments to ignore this folder and any configs, ensuring debug only settings are not released to live environments.

Once you've created the file, refresh the FillDB page. The warning will no longer be displayed.

Using FillDB

Now the page is enabled, we can actually use the FillDB page. If you click the Go! button nothing will happen. We actually have to tell FillDB what steps to run. The page is broken up as follows:

Key Settings

  • Database Name: This is the database items will be created in.
  • Words Dictionary: This is the location in the web root the words files will be stored.

Steps

1. Prepare database

This script generates stored procedures to speed up the insertion process. It only needs to be ran once to use FillDB.

2. Prepare words directory

This step creates the location on disk to store the downloaded word files. This only needs to be ran once, unless you change the Words Dictionary setting.

3. Download word files

You can download multiple files from an HTTP resource and their content will be used to generate random text for items. These files will be stored for later use, so this step only needs to be re-ran if you require additonal files.

4. Clear site caches

By runnining this step, all site caches will be cleared. This can also be useful for general development.

5. Generate items

This step peforms the key feature of the FillDB page. By running this step you can generate numerous items with text content from your downloaded word files. This step has several fields you can change:

  • Name Prefix: This value will be prepended to the genreated items names (e.g. a prefix of 'Auto' will create items Auto Folder 0, Auto Item 1 etc).
  • Number of items: The number of Sitecore items to create.
  • Template Guid: The template to use when creating items. If you want to generate various items on different templates, just run FillDB with a different guid.
  • Template Fields: As well as controlling the template used you can provide the guids of fields to populate. FillDB only generates random text so you may get odd results when generating content for non text field types.
  • Max words per field: The total number of words that may be inserted into a field.
  • Parent Guid: The parent item in Sitecore that generated items will be created under.

6. Rebuild Index

By running this step, the Sitecore indexes will be rebuilt. You can also customise the process: + Index Name: The specific index to rebuild. If left blank, all indexes will be rebuilt. + Index roots: By providing one or more item guids, indexes will rebuild only those items and their descendants.

Go!

Once you've configured the steps you need, hit the Go! button. On a first run, you'll need to run all steps. For additional runs, you'll likely only need to run steps 4-6.

Once the page has finished running, the results will be displayed:

Automating FillDB

Now we know what the FillDB page can do, it would be great if we could automate it to generate content for testing.

All settings on the FillDB page can be POSTed and with a little Powershell to wrap things up we can integrate creation of our test content directly into our build processes.

Save this script locally and you'll be able to start automating. The following example runs all steps, downloads extra text files and uses a custom template with custom fields when creating items.

# Example of running Invoke-FillDB.ps1

# Additional files to download
$downloads= @(
    "http://www.gutenberg.org/files/42698/42698-0.txt",
    "http://www.gutenberg.org/cache/epub/42705/pg42705.txt",
    "http://www.gutenberg.org/cache/epub/42710/pg42710.txt",
    "http://www.gutenberg.org/files/42700/42700-0.txt",
    "http://www.gutenberg.org/files/42706/42706-0.txt"
)

# Custom template
$template = "{1C7E374B-44FC-4E33-8F8B-857D1A32CDC3}"

# Additional fields on a custom template to populate
$fields= @(
    "{DB074AA7-DF72-46C5-8269-E4A06FC8EC74}",
    "{6AB6FC48-D23C-465D-8D11-6BECB76C64CC}",
    "{D5E42CBE-3D6A-470F-A7B6-AC4EC7CF72D3}",
    "{3293A6C1-3E6F-45F3-9170-6D2D133C4304}",
    "{A4562857-67CC-48D3-9424-A0BF37C7F429}",
    "{EA0C14FF-2868-4F9A-8FCF-236B0DBCF86B}"
)

$site = "http://sitecore.testsite"
$username = "sitecore\username"
$password = "password"

# Invoke-FillDB performing all basic steps
$response = .\Invoke-FillDB.ps1 $site $username $password -clearCache -runSqlScript `
    -createWordsDir -wordsDir "words" -downloadFiles $downloads -templateFields $fields `
    -templateGuid $template -prefix "Standard" `
    -wordsPerField 100 -itemCount 100 -indexName "sitecore_master_index"

# See the response
$response.messages
$response.success

If you've already ran steps 1-3 you can just generate content using the defaults set in the script:

# Invoke-FillDB only creating items
$response = .\Invoke-FillDB.ps1 $site $username $password -itemCount 100 -clearcache    

The script will return a json response with a messages property listing the same details you'd see as if you ran the commands on the page itself. You can also check the success property to see if the request was a success.