Migrating Umbraco Forms from 7 to modern
No migration, no cry
There is no uSync Migrations extension for moving forms from 7 to modern.
There isn't even a uSync Forms for V7.
However the serialization format for forms on disk didn't change (much?) from 7 to 8, so we can do a trick. (Thanks to Kevin for the tip)
We can do 7 to 8, then 8 to modern.
This applies to files. I have not tried with the forms in database method, but that should be possible to do with database migrations from 7 to 8.
7 to 8
Create an empty V8 site and install the following nuget packages:
- UmbracoForms
- uSync.Forms
To "migrate" your forms from 7 to 8 you just copy the files over. 😁
Your source files should be in /App_Data/UmbracoForms/Data
.
The target should be the same in a V8 site.
When your files are copied you're ready to go into the backoffice.
Go to Settings \ uSync and click Export.
You should now have uSync files for the forms under /uSync/v8/Forms
.
8 to modern
Install uSync.Forms in your modern site.
Copy your uSync forms files from the V8 site into /uSync/v9/Forms
.
The uSync files will have prevalues in a parsedPreValues
field instead of preValues
.
uSync Forms import in modern does not like this.
So I made a small powershell script that does the necessary "migration":
param(
$path
)
$files = Get-ChildItem -Path $path -File
$files | % {
$fileInfo = $_
$doc = [xml](Get-Content $fileInfo.FullName)
$pageNode = $doc.DocumentElement.SelectSingleNode("Pages")
$origCData = $pageNode.FirstChild
$pages = [array]($origCData.InnerText | ConvertFrom-Json)
$results = $pages | % {
$page = $_
$page.fieldSets | % {
$fieldSet = $_
$fieldSet.containers | % {
$container = $_
$container.fields | % {
$field = $_
if ($field.parsedPrevalues.Length -gt 0) {
$field.preValues = $field.parsedPrevalues
}
$field.psobject.Properties.Remove("parsedPreValues")
}
}
}
}
$cdata = $doc.CreateCDataSection((ConvertTo-Json -depth 99 -inputobject $pages))
$replaced = $pageNode.ReplaceChild($cdata, $origCData)
$doc.Save($fileInfo.FullName)
}
I called the script fix-usync-forms.ps1
and we can call it as such:
./fix-usync-forms.ps1 [path-to-site]/uSync/v9/Forms
That's it!
We can now go into the backoffice in our modern site.
Go to Settings \ uSync and click "Import" under Forms.
Success
Now all that's left is porting your potential code and views.
Happy migrating! 🙃