3

What is the SPE equivalent of "Revert Tree"?

I've attempted the following:

$config = [Sitecore.Configuration.Factory]::GetConfiguration();
$dataFolderPath = ($config.sitecore."sc.variable" | ?{ $_.name -eq 'dataFolder'}).Value
$serializationPath = "$dataFolderPath/serialization/master$($MyBucket.ItemPath)"

...

if(test-path "$serializationpath.item") {
    # restore the empty folder to delete children (~10,000) as a side-effect
    deserialize-item -path $serializationPath -root "$dataFolderPath/serialization/" -ForceUpdate -DisableEvents
}

. But this does not seem to do the same thing as the button. The documentation doesn't reference this use case at all. Any feedback would be appreciated.

1
  • 1
    Having a look at the source code for Import-Item it appears that "revert" is tied to the "ForceUpdate" switch. The "Recurse" switch indicates that a tree should be loaded rather than just the item. Oct 16, 2019 at 20:11

1 Answer 1

1

deserialize-item command requires 2 parameters -

  1. path - which is a path to the item on the drive but without .item extension. If the item does not exist in the Sitecore tree yet, you need to pass the parent item path.
  2. root - the directory which is the root of serialization. The trailing slash \ character is required

In your case, you want to deserialize tree so -Recurse option is also required.

  • You are passing both the parameter in your script but $dataFolderPath value may not have a full path from config if it is set to /app_data. Try to do a write-host for the path to make sure it is a full file path.
  • try to use slash \ character in the path not /
  • Make sure $serializationPath value is correct with $dataFolderPath and $MyBucket

A sample script will be like this -

//serialization item path without .item extension
$serializationPath = "C:\inetpub\wwwroot\yourwebsite\App_Data\serialization\master\sitecore\content\Global Settings\Topics"
//root file path of serialization
$rootPath = "C:\inetpub\wwwroot\yourwebsite\App_Data\serialization\"
if(test-path "$serializationpath.item") {
deserialize-item -path $serializationPath -root $rootPath -ForceUpdate -DisableEvents -Recurse
}
1
  • 1
    In this case i looks like my issue was a combination of '/' and the missing -recurse flag. With just the recurse flag I was receiving errors, but with both in place the script works as desired
    – mlhaufe
    Oct 17, 2019 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.