Add automatic controller propagation for dualpath machines
When a PC is assigned to control equipment that has a dualpath relationship, the controller is now automatically propagated to the dualpath partner machine. Changes: - includes/db_helpers.asp: Add PropagateControllerToDualpathMachines() and PropagateControllerFromDualpathMachine() helper functions - savemachine_direct.asp: Call propagation on new equipment creation - savemachineedit.asp: Call propagation when editing equipment relationships - api.asp: Add PropagateControllerToDualpathMachinesAPI() for PowerShell API Also includes one-time fix script (sql/fix_dualpath_controller_relationships.sql) that fixes 140 backwards relationships (Equipment->PC to PC->Equipment) and propagates controllers to 30 dualpath machines that were missing them. Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
70
api.asp
70
api.asp
@@ -1609,10 +1609,80 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber)
|
||||
CreatePCMachineRelationship = False
|
||||
Else
|
||||
LogToFile "Created Controls relationship: Equipment " & equipmentMachineid & " controlled by PC " & pcMachineid
|
||||
|
||||
' Propagate controller to any dualpath machines
|
||||
Dim dualpathCount
|
||||
dualpathCount = PropagateControllerToDualpathMachinesAPI(CLng(equipmentMachineid), CLng(pcMachineid))
|
||||
If dualpathCount > 0 Then
|
||||
LogToFile "Propagated controller to " & dualpathCount & " dualpath machine(s)"
|
||||
End If
|
||||
|
||||
CreatePCMachineRelationship = True
|
||||
End If
|
||||
End Function
|
||||
|
||||
' ============================================================================
|
||||
' FUNCTION: PropagateControllerToDualpathMachinesAPI
|
||||
' PURPOSE: When a PC controls a machine, also assign it to dualpath'd machines
|
||||
' ============================================================================
|
||||
Function PropagateControllerToDualpathMachinesAPI(equipmentMachineid, pcMachineid)
|
||||
On Error Resume Next
|
||||
|
||||
Dim rsDP, rsDPCheck, controlsTypeID, dualpathMachineId, cnt
|
||||
cnt = 0
|
||||
|
||||
' Get Controls relationship type ID
|
||||
Set rsDP = objConn.Execute("SELECT relationshiptypeid FROM relationshiptypes WHERE relationshiptype = 'Controls'")
|
||||
If rsDP.EOF Then
|
||||
PropagateControllerToDualpathMachinesAPI = 0
|
||||
rsDP.Close
|
||||
Set rsDP = Nothing
|
||||
Exit Function
|
||||
End If
|
||||
controlsTypeID = CLng(rsDP("relationshiptypeid"))
|
||||
rsDP.Close
|
||||
Set rsDP = Nothing
|
||||
|
||||
' Find all machines with dualpath relationship to this equipment
|
||||
Set rsDP = objConn.Execute("SELECT related_machineid FROM machinerelationships mr " & _
|
||||
"JOIN relationshiptypes rt ON mr.relationshiptypeid = rt.relationshiptypeid " & _
|
||||
"WHERE mr.machineid = " & CLng(equipmentMachineid) & " " & _
|
||||
"AND rt.relationshiptype = 'Dualpath' AND mr.isactive = 1")
|
||||
|
||||
Do While Not rsDP.EOF
|
||||
dualpathMachineId = CLng(rsDP("related_machineid"))
|
||||
|
||||
' Check if this dualpath machine already has a Controls relationship with this PC
|
||||
Set rsDPCheck = objConn.Execute("SELECT relationshipid FROM machinerelationships " & _
|
||||
"WHERE machineid = " & CLng(pcMachineid) & " " & _
|
||||
"AND related_machineid = " & dualpathMachineId & " " & _
|
||||
"AND relationshiptypeid = " & controlsTypeID & " AND isactive = 1")
|
||||
|
||||
If rsDPCheck.EOF Then
|
||||
' Create Controls relationship: PC -> Dualpath Machine
|
||||
Dim cmdDPAPI
|
||||
Set cmdDPAPI = Server.CreateObject("ADODB.Command")
|
||||
cmdDPAPI.ActiveConnection = objConn
|
||||
cmdDPAPI.CommandText = "INSERT INTO machinerelationships (machineid, related_machineid, relationshiptypeid, isactive) VALUES (?, ?, ?, 1)"
|
||||
cmdDPAPI.Parameters.Append cmdDPAPI.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid))
|
||||
cmdDPAPI.Parameters.Append cmdDPAPI.CreateParameter("@equipid", 3, 1, , dualpathMachineId)
|
||||
cmdDPAPI.Parameters.Append cmdDPAPI.CreateParameter("@reltypeid", 3, 1, , controlsTypeID)
|
||||
cmdDPAPI.Execute
|
||||
Set cmdDPAPI = Nothing
|
||||
cnt = cnt + 1
|
||||
LogToFile "Created dualpath Controls relationship: Equipment " & dualpathMachineId & " controlled by PC " & pcMachineid
|
||||
End If
|
||||
rsDPCheck.Close
|
||||
Set rsDPCheck = Nothing
|
||||
|
||||
rsDP.MoveNext
|
||||
Loop
|
||||
rsDP.Close
|
||||
Set rsDP = Nothing
|
||||
|
||||
PropagateControllerToDualpathMachinesAPI = cnt
|
||||
End Function
|
||||
|
||||
Sub UpdateWarrantyData(machineid, warrantyEndDate, warrantyStatus, warrantyServiceLevel, warrantyDaysRemaining)
|
||||
On Error Resume Next
|
||||
|
||||
|
||||
Reference in New Issue
Block a user