Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channels and groups not removed on push #45

Open
Araxor opened this issue Jun 2, 2022 · 2 comments
Open

Channels and groups not removed on push #45

Araxor opened this issue Jun 2, 2022 · 2 comments

Comments

@Araxor
Copy link

Araxor commented Jun 2, 2022

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:

mirthsync push --force --server $server --username $username --password $password --target ./mirth --ignore-cert-warnings --include-configuration-map

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.

@jessesaga
Copy link
Contributor

Yes, currently mirthSync only adds/updates items in the Mirth server. It never deletes anything.

#26 is related to this and we have plans to implement something to address renames and deletions but have not found the time to work on it yet. A PR would be welcome.

#34 is also related to this in a roundabout way. If, for instance, we implemented the ability to assemble a mirth backup file from the mirthsync target directory (which I don't believe would be that hard) - we could then add the ability for mirthSync to operate in a 'restore' mode that would function like restoring a mirth backup.

I don't really know the best approach at this point but any code or suggestions would be much appreciated.

@Araxor
Copy link
Author

Araxor commented Apr 21, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants