Dmytro Pastovenskyi
Dmytro Pastovenskyi

Reputation: 5419

Clear Replication History programmatically

I'm looking for a way to clear "Replication History" programmatically (typically we do it manually if needed, see image below)

enter image description here

  1. I have checked LS and Java classes and did not found anything useful.
  2. I will try to find something Notes C API database but I really want to avoid using C API.

Any ideas or suggestion would be very welcome.

Upvotes: 4

Views: 187

Answers (1)

Dmytro Pastovenskyi
Dmytro Pastovenskyi

Reputation: 5419

Here is a solution (credits go to Richard Schwartz as well for helping with C API function).

(Declarations)

Public Const W32_LIB = {nnotes.dll}
Public Const LINUX_LIB = {libnotes.so}

Declare Function W32_NSFDbOpen Lib W32_LIB Alias {NSFDbOpen} (ByVal dbName As String, hDb As Long) As Integer
Declare Function W32_NSFDbClose Lib W32_LIB Alias {NSFDbClose} (ByVal hDb As Long) As Integer
Declare Function W32_NSFDbClearReplHistory Lib W32_LIB Alias {NSFDbClearReplHistory} (ByVal hDb As Long, flags As Integer) As Integer

Declare Function LINUX_NSFDbOpen Lib LINUX_LIB Alias {NSFDbOpen} (ByVal dbName As String, hDb As Long) As Integer
Declare Function LINUX_NSFDbClose Lib LINUX_LIB Alias {NSFDbClose} (ByVal hDb As Long) As Integer
Declare Function LINUX_NSFDbClearReplHistory Lib LINUX_LIB Alias {NSFDbClearReplHistory} (ByVal hDb As Long, flags As Integer) As Integer

Dim IS_WINDOWS As Boolean

Initialize (figure out platform: windows or linux)

Dim session As NotesSession
Set session = New NotesSession

IS_WINDOWS = InStr(session.Platform, "Windows") <> 0

Clear replication history

Function processDb(server As String, filename As String) As Boolean
    On Error GoTo errh
    
    Dim hdb As Long
    Dim rc As Integer

    If Server = "" Then
        If IS_WINDOWS Then
            rc = W32_NSFDbOpen(FileName, hDb)
        Else
            rc = LINUX_NSFDbOpen(FileName, hDb)
        End If
    Else
        If IS_WINDOWS Then
            rc = W32_NSFDbOpen(Server & "!!" & FileName, hDb)
        Else
            rc = LINUX_NSFDbOpen(Server & "!!" & FileName, hDb)
        End If
    End If

    If rc <> 0 Then
        Error 9001, "Database " & Server & "!!" & FileName & " - could not be opened"
    End If
    
    If IS_WINDOWS Then
        rc = W32_NSFDbClearReplHistory(hDb, 0)
    Else
        rc = LINUX_NSFDbClearReplHistory(hDb, 0)
    End If

    If rc <> 0 Then
        Error 9002, "Database " & Server & "!!" & FileName & " - replication history failed"
    End If

    If IS_WINDOWS Then
        rc = W32_NSFDbClose(hDb)
    Else
        rc = LINUX_NSFDbClose(hDb)
    End If
    
    processDb = true
    
final:
    Exit Function
errh:
    MsgBox "!! " & Error$ & " at line: " & erl
    Resume final
End Function

published solution on github: https://github.com/dpastov/DominoReplicationHistoryCleaner

Upvotes: 3

Related Questions