Manage Learn to apply best practices and optimize your operations.

Update ACL of selected databases

This code allows you to easily update the ACL (access control list) so that the administration server is changed from the old server to the new server in a migration.

We are in the process of moving a large number of databases from a single server to several servers. This code allows us to easily update the ACL (access control list) so that the administration server is changed from the old server to the new server. The old and new servers are selected from a dialog by the person making the changes. The new server is given all privileges and roles within the database. It also updates any agents scheduled to run on the old server so that they will run on the new server. The agent is set up to be called from a button on a view so that this code can be executed against all databases selected in the view. The "By Title" view in catalog.nsf is used to select the databases. One "Lookup Server" view has been added that is a simple view with one categorized column showing the fully qualified server names available.

Dim ws As New NotesUIWorkspace
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim UpdateDb As NotesDatabase
 Dim doc As NotesDocument
 Dim InputDoc As NotesDocument
 Dim col As NotesDocumentCollection
 Dim v As NotesView
 Dim item As NotesItem
 Dim NewServer As Variant
 Dim OldServer As Variant
 Dim acl As NotesACL
 Dim entry As NotesACLEntry
 Dim summary As String
 Dim ModifyAgents As String
 
 Set ws = New NotesUIWorkspace
 Set s = New NotesSession
 Set db = s.CurrentDatabase
 
 Dim c0 As Single ' Docs Processed
 Dim c1 As Single ' Databases Updated
 Dim c2 As Single ' Errors Encountered
 
 Set col = db.UnprocessedDocuments
 If col.Count = 0 Then
  Msgbox "No documents are selected.  
Please select the document(s) you 
want to process and try again.", 64, "Error"
  Goto TheEnd
 Else
  Dim Answer As Integer
  Answer = Msgbox (col.Count & " 
document(s) have been selected." + 
Chr(13) +  Chr(13) + "Continue?", 4, "Warning!")
  If Answer = 7 Then
   Goto TheEnd
  End If 
 End If
 
 OldServer = ws.Pickliststrings(3, 0, 
Db.Server, Db.Filepath, "Lookup Server", 
"Server Picklist", "Select server to REMOVE.  
Use 'Cancel' to bypass removing any 
server from the ACL(s).", 1) 
 NewServer = ws.Pickliststrings(3, 0, 
Db.Server, Db.Filepath, "Lookup Server", 
"Server Picklist", "Select the server to ADD.  
Use 'Cancel' to bypass adding a server 
to the ACL(s).", 1) 
 
 Set doc = col.GetFirstDocument
 ModifyAgents = "Y"
 
 While Not (doc Is Nothing)
  
  c0 = c0 + 1
  
  Set UpdateDb = New NotesDatabase("","")
  Call UpdateDb.Open(doc.Server(0), 
doc.Pathname(0))
  If UpdateDb.IsOpen Then
   c1 = c1 + 1
   
RemoveServerEntry:    
   If Isempty(OldServer) Then
    ModifyAgents = "N"
    Goto AddServerEntry
   Else
    If OldServer(0) = "" Then
     ModifyAgents = "N"
     Goto AddServerEntry
    End If
   End If
   
   Set acl = UpdateDb.ACL
'   Set entry = acl.GetFirstEntry
   Set entry = acl.GetEntry(OldServer(0))
   
   If Not (entry Is Nothing) Then
    Call entry.Remove
    Call acl.Save
   Else
    Goto AddServerEntry
   End If
  Else
   c2 = c2 + 1
   Summary = Summary + "Could not open " 
+ doc.Title(0) + ".  "
  End If
  
AddServerEntry:  
  If Isempty(NewServer) Then
   ModifyAgents = "N"
   Goto ProcessNextEntry
  Else
   If NewServer(0) = "" Then
    ModifyAgents = "N"
    Goto ProcessNextEntry
   End If
  End If
  
  Set acl = UpdateDb.ACL
  
  Set entry = acl.GetFirstEntry
  While Not entry Is Nothing
   If entry.Name = NewServer(0) Then
    Goto ProcessAgents
   End If
   Set entry = acl.GetNextEntry(entry)
  Wend
  
  Set entry = acl.CreateACLEntry(NewServer(0), 6)
  entry.IsServer = True
  entry.IsAdminServer = True
  entry.IsAdminReaderAuthor = True
  Forall role In acl.Roles
   If role > "" Then
    Call entry.EnableRole(role) 
   End If
  End Forall
  
  Call acl.Save
  
ProcessAgents: 
  If ModifyAgents = "Y" Then
   Forall a In UpdateDb.Agents
    If a.ServerName = OldServer(0) Then
     a.ServerName = NewServer(0)
     Call a.Save
    End If
   End Forall
  End If
  
ProcessNextEntry:  
  Call s.UpdateProcessedDoc(doc)
  Set doc = col.GetNextDocument(doc)
 Wend
 
TheEnd:
 Msgbox Summary + "  Processed " + 
Cstr(c0) + " documents.  Updated " + 
Cstr(c1) + " databases.  " + Cstr(c2) + " 
errors encountered.", , "Processing 
Complete!"

Do you have comments on this tip? Let us know.

Dig Deeper on LotusScript

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close