Skip to content

Instantly share code, notes, and snippets.

@rvencu
Last active July 28, 2018 09:17
Show Gist options
  • Save rvencu/4883aeafbc91bc73b07b6d979d65610a to your computer and use it in GitHub Desktop.
Save rvencu/4883aeafbc91bc73b07b6d979d65610a to your computer and use it in GitHub Desktop.
<#
Script to update new items for an exported/imported form
Must replace all exported form fields IDs with imported form fields IDs - copy the ForEach-Object line as necessary
Must replace old form id with new form id
insert latest exported xml
specify the date from which new items are to be imported
run the script
import the updated.xml file into the target site
#>
$filetoimport = 'clinicaivory-lakeview.formidable.2018-07-28.xml'
$afterdate = [dateTime]"2018-07-01"
# change fields and form id
(Get-Content $filetoimport) |
ForEach-Object { $_ -replace "id>122</", "id>786</" } |
ForEach-Object { $_ -replace "id>123</", "id>787</" } |
ForEach-Object { $_ -replace "id>124</", "id>788</" } |
ForEach-Object { $_ -replace "id>125</", "id>789</" } |
ForEach-Object { $_ -replace "id>126</", "id>790</" } |
ForEach-Object { $_ -replace "id>127</", "id>792</" } |
ForEach-Object { $_ -replace "id>129</", "id>793</" } |
ForEach-Object { $_ -replace "id>135</", "id>794</" } |
ForEach-Object { $_ -replace "id>130</", "id>795</" } |
ForEach-Object { $_ -replace "id>131</", "id>796</" } |
ForEach-Object { $_ -replace "id>132</", "id>797</" } |
ForEach-Object { $_ -replace "id>133</", "id>798</" } |
ForEach-Object { $_ -replace "id>134</", "id>799</" } |
ForEach-Object { $_ -replace "id>136</", "id>800</" } |
ForEach-Object { $_ -replace "id>139</", "id>801</" } |
ForEach-Object { $_ -replace "id>138</", "id>802</" } |
ForEach-Object { $_ -replace "id>140</", "id>805</" } |
ForEach-Object { $_ -replace "id>294</", "id>803</" } |
ForEach-Object { $_ -replace "id>295</", "id>784</" } |
ForEach-Object { $_ -replace "id>141</", "id>804</" } |
ForEach-Object { $_ -replace "id>654</", "id>781</" } |
ForEach-Object { $_ -replace "id>656</", "id>785</" } |
ForEach-Object { $_ -replace "<form_id>8</form_id>", "<form_id>51</form_id>" } |
Set-Content updated.xml
#start cleaning the import file
$xmldata = [xml](Get-Content updated.xml)
# remove the form node
$xmldata.selectnodes("//form") | %{ $_.parentnode.removechild($_) }
# remove the form_actions nodes
$xmldata.selectnodes("//view/post_type[.='frm_form_actions']") | %{ $_.parentnode.parentnode.removechild($_.parentnode) }
# remove all items older than date
$xmldata.selectnodes("//item/updated_at") | ?{[dateTime]$_.'#text' -lt $afterdate} | %{ $_.parentnode.parentnode.removechild($_.parentnode) }
# remove all views older than date (these are posts created by entries)
$xmldata.selectnodes("//view/post_date") | ?{[dateTime]$_.'#text' -lt $afterdate} | %{ $_.parentnode.parentnode.removechild($_.parentnode) }
#save cleaned xml
$xmldata.Save("$pwd\updated.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment