Open Araxor opened 2 years ago
Yes, currently mirthSync only adds/updates items in the Mirth server. It never deletes anything.
I don't really know the best approach at this point but any code or suggestions would be much appreciated.
I said in my previous message that I was willing to do a PR, but unfortunately I did not manage to do it (probably because I have to learn clojure first).
As a workaround, I call the following powershell script before the "push" action to clear all channels. It works quite well for my needs.
Maybe implementing the same logic in clojure would be a good approach?
param(
$username,
$password,
$server
)
$ErrorActionPreference = "Stop"
Write-Host "Authenticating to Mirth API"
Invoke-Restmethod `
-Method POST `
-Uri "$server/users/_login" `
-Body "username=$username&password=$password" `
-SkipCertificateCheck `
-Headers @{ 'Accept'='application/xml'; 'X-Requested-With'='powershell' } `
-SessionVariable mirthSession | Out-Null
Write-Host "Retrieving Mirth channels"
$channelsXml = Invoke-RestMethod `
-Method GET `
-Uri "$server/channels/idsAndNames" `
-SkipCertificateCheck `
-Headers @{ 'Accept'='application/xml'; 'X-Requested-With'='powershell' } `
-WebSession $mirthSession
$channelIds = $channelsXml | Select-Xml -XPath "/map/entry/string[1]" |
Select-Object -ExpandProperty Node |
Select-Object -ExpandProperty InnerText
foreach ($channelId in $channelIds) {
Write-Host "Deleting Mirth channel $channelId"
Invoke-RestMethod `
-Method DELETE `
-Uri "$server/channels/$channelId" `
-SkipCertificateCheck `
-Headers @{ 'Accept'='application/xml'; 'X-Requested-With'='powershell' } `
-WebSession $mirthSession | Out-Null
}
Write-Host "Retrieving Mirth channel group ids"
$groupsXml = Invoke-RestMethod `
-Method GET `
-Uri "$server/channelgroups" `
-SkipCertificateCheck `
-Headers @{ 'Accept'='application/xml'; 'X-Requested-With'='powershell' } `
-WebSession $mirthSession
$groupIds = $groupsXml | Select-Xml -XPath "/list/channelGroup/id/text()" |
Select-Object -ExpandProperty Node |
Select-Object -ExpandProperty InnerText
Write-Host "Deleting Mirth channel groups"
$body = @"
--abc123
Content-Disposition: form-data; name="channelGroups";
Content-Type: application/xml
<set/>
--abc123
Content-Disposition: form-data; name="removedChannelGroupIds";
Content-Type: application/xml
<set>$($groupIds | % {'<string>' + $_ + '</string>'})</set>
--abc123--
"@.Trim()
Invoke-RestMethod `
-Method POST `
-Uri "$server/channelgroups/_bulkUpdate?override=true" `
-SkipCertificateCheck `
-Headers @{ 'Accept'='application/json'; 'X-Requested-With'='powershell' } `
-ContentType 'multipart/form-data; boundary=abc123' `
-Body $body `
-WebSession $mirthSession | Out-Null
When I push my configuration to mirth, the existing channels/groups that exist in Mirth but not in the configuration folder are not removed.
I expect to have the exact same configuration in Mirth and in git after push. This is useful e.g. when switching from branch to another with different channels and groups.
For information, I use the following command for push:
Is this by design? Is it a bug or a feature? Maybe my use case is different than yours.
I am willing to develop this functionality in a PR.