Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active November 15, 2018 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/23c6a0c0ed08cc835f2fed8331569b66 to your computer and use it in GitHub Desktop.
Save michaellwest/23c6a0c0ed08cc835f2fed8331569b66 to your computer and use it in GitHub Desktop.
Bulk load Sitecore items using Sitecore.DataBlaster and Sitecore PowerShell Extensions.
$db = Get-Database -Name "master"
$item = $db.GetItem("/sitecore/content/Home/Delete Me")
$item.DeleteChildren()
$template = [Sitecore.Data.Managers.TemplateManager]::GetTemplate("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", $db)
$bulkLoader = New-Object Sitecore.DataBlaster.Load.BulkLoader
$context = $bulkLoader.NewBulkLoadContext($db.Name)
$action = [Sitecore.DataBlaster.Load.BulkLoadAction]::Update
$bulkItems = New-Object "System.Collections.Generic.List[Sitecore.DataBlaster.Load.BulkLoadItem]"
for($i = 0; $i -lt 100; $i++) {
$bulkItems.Add((New-Object Sitecore.DataBlaster.Load.BulkLoadItem($action, $template, $item, "BulkItem$($i)"))) > $null
}
$watch = [System.Diagnostics.Stopwatch]::StartNew()
$bulkLoader.LoadItems($context, $bulkItems.ToArray())
$watch.Stop()
"$($watch.ElapsedMilliseconds / 1000) seconds"
$templateItem = Get-Item -Path "master:" -ID $template.ID
$watch = [System.Diagnostics.Stopwatch]::StartNew()
for($i = 0; $i -lt 100; $i++) {
New-Item -Parent $item -Name "BulkItem-a$($i)" -ItemType $templateItem.Paths.Path > $null
}
$watch.Stop()
"$($watch.ElapsedMilliseconds / 1000) seconds"
$rainbowItem = $item | ConvertTo-RainbowYaml | ConvertFrom-RainbowYaml
$db = Get-Database -Name "master"
$action = [Sitecore.DataBlaster.Load.BulkLoadAction]::Update
$bulkLoadItems = New-Object "System.Collections.Generic.List[Sitecore.DataBlaster.Load.BulkLoadItem]"
$bulkLoader = New-Object Sitecore.DataBlaster.Load.BulkLoader
$context = $bulkLoader.NewBulkLoadContext($db.Name)
$itemMapper = New-Object Unicorn.DataBlaster.Sync.ItemMapper
$bulkLoadItem = $itemMapper.ToBulkLoadItem($rainbowItem, $context, $action)
$bulkLoadItems.Add($bulkLoadItem) > $null
$bulkLoader.LoadItems($context, $bulkLoadItems.ToArray())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment