## Phase 2 Migration Complete Successfully migrated all 286 active PCs from pc table to machines table. ### Migration Scripts Added/Updated: - **Phase 1.0**: Added ensure_all_machinetypes.sql (machinetypes 15-20) - **Phase 1.5**: Added migrate_equipment_ips_to_communications.sql - **Phase 2**: Updated 01_migrate_pcs_to_machines.sql for duplicate handling - **Phase 2**: Updated 08_update_schema_for_api.sql (rename pcid→machineid) - **Phase 2 Fixes**: Added FIX_migrate_remaining_pcs.sql (60 unmigrated PCs) - **Phase 2 Fixes**: Added FIX_pc_machine_types.sql ### Network Devices View Updated: - **CREATE_vw_network_devices_with_fqdn.sql**: Complete rewrite for Phase 2 - Infrastructure devices (IDF, Server, Switch, Camera, Access Point) query machines table - Printers remain in separate printers table (has fqdn column) - UNION approach: machines (machinetypeid 15-19) + printers table ### Documentation Added: - DATA_MIGRATION_EXPLAINED.md - Full migration architecture - PRODUCTION_MIGRATION_PLAN.md - Production deployment plan - VIEWS_MIGRATION_ANALYSIS.md - Views requiring updates - PRINTER_INSTALLER_FIX_2025-11-20.md - Printer installer fixes - SCHEMA_COMPARISON_REPORT_2025-11-20.md - Phase 2 schema comparison ### ASP Files Updated: - api_printers.asp - Printer API fixes - displaynotifications.asp - UI improvements - install_printer.asp - Installer fixes - v2/api_printers.asp - V2 API updates - v2/install_printer.asp - V2 installer updates ### Migration Results (DEV): - Total machines: 523 (237 equipment + 286 PCs) - Communications: 1,309 - Warranties: 212 - Machine relationships: 201 - PC migration: 286/286 ✓ - Duplicate PCs removed: 166 duplicates cleaned ### Key Achievements: ✓ All 286 active PCs migrated to machines table ✓ Network devices view updated for Phase 2 architecture ✓ pc_to_machine_id_mapping table populated (286 entries) ✓ Duplicate PC records cleaned (452→286) ✓ Schema updates for API compatibility (pcid→machineid) ### Next Steps: - Update PHP Dashboard API for Phase 2 schema (CRITICAL - see POWERSHELL_API_PHASE2_ISSUES.md) - Update PowerShell scripts for Phase 2 schema - Test Update-PC-CompleteAsset-Silent.bat - Production deployment planning 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
177 lines
7.7 KiB
Plaintext
177 lines
7.7 KiB
Plaintext
<%@ Language=VBScript %>
|
|
<%
|
|
' API endpoint to return printer data as JSON
|
|
' Used by PrinterInstaller to fetch available printers
|
|
|
|
Response.ContentType = "application/json"
|
|
Response.Charset = "UTF-8"
|
|
|
|
' Disable caching
|
|
Response.AddHeader "Cache-Control", "no-cache, no-store, must-revalidate"
|
|
Response.AddHeader "Pragma", "no-cache"
|
|
Response.AddHeader "Expires", "0"
|
|
%><!--#include file="./includes/sql.asp"--><%
|
|
' Query all active HP, Xerox, and HID printers with network addresses
|
|
Dim strSQL, rs, jsonOutput, isFirst
|
|
|
|
strSQL = "SELECT p.printerid, p.printerwindowsname, p.printercsfname, p.fqdn, p.ipaddress, " & _
|
|
"v.vendor, m.modelnumber, p.isactive, ma.alias, ma.machinenumber, p.installpath " & _
|
|
"FROM printers p " & _
|
|
"LEFT JOIN models m ON p.modelid = m.modelnumberid " & _
|
|
"LEFT JOIN vendors v ON m.vendorid = v.vendorid " & _
|
|
"LEFT JOIN machines ma ON p.machineid = ma.machineid " & _
|
|
"WHERE p.isactive = 1 " & _
|
|
"AND (v.vendor = 'HP' OR v.vendor = 'Xerox' OR v.vendor = 'HID') " & _
|
|
"ORDER BY " & _
|
|
"CASE WHEN p.printercsfname IS NOT NULL AND p.printercsfname != '' AND p.printercsfname != 'NONE' THEN 0 ELSE 1 END, " & _
|
|
"p.printercsfname, COALESCE(ma.alias, ma.machinenumber), v.vendor, m.modelnumber"
|
|
|
|
Set rs = objConn.Execute(strSQL)
|
|
|
|
' Build JSON array
|
|
jsonOutput = "["
|
|
isFirst = True
|
|
|
|
Do While Not rs.EOF
|
|
' Skip printers without a network address
|
|
If (Not IsNull(rs("fqdn")) And rs("fqdn") <> "") Or (Not IsNull(rs("ipaddress")) And rs("ipaddress") <> "" And rs("ipaddress") <> "USB") Then
|
|
|
|
If Not isFirst Then
|
|
jsonOutput = jsonOutput & ","
|
|
End If
|
|
isFirst = False
|
|
|
|
jsonOutput = jsonOutput & vbCrLf & " {"
|
|
jsonOutput = jsonOutput & vbCrLf & " ""printerid"": " & rs("printerid") & ","
|
|
|
|
' Escape quotes in string values
|
|
Dim printerName, csfName, fqdn, ipAddr, vendor, model, machineAlias, machineNumber, machineName, standardName
|
|
printerName = Replace(rs("printerwindowsname") & "", """", "\""")
|
|
csfName = Replace(rs("printercsfname") & "", """", "\""")
|
|
fqdn = Replace(rs("fqdn") & "", """", "\""")
|
|
ipAddr = Replace(rs("ipaddress") & "", """", "\""")
|
|
vendor = Replace(rs("vendor") & "", """", "\""")
|
|
model = Replace(rs("modelnumber") & "", """", "\""")
|
|
|
|
' Get machine name (prefer alias, fallback to machinenumber)
|
|
machineAlias = rs("alias") & ""
|
|
machineNumber = rs("machinenumber") & ""
|
|
If machineAlias <> "" Then
|
|
machineName = machineAlias
|
|
Else
|
|
machineName = machineNumber
|
|
End If
|
|
machineName = Replace(machineName, """", "\""")
|
|
|
|
' Generate standardized printer name: CSFName-Location-Brand-Description
|
|
' Per naming convention: CSF##-Location-Brand-Description
|
|
' Remove spaces and "Machine" word from names
|
|
Dim cleanMachine, cleanModel, shortDescription
|
|
cleanMachine = Replace(machineName, " ", "")
|
|
cleanMachine = Replace(cleanMachine, "Machine", "")
|
|
|
|
' Extract short description from model number
|
|
' Examples: "Color LaserJet M254dw" -> "ColorLaserJet"
|
|
' "Altalink C8135" -> "Altalink"
|
|
' "Versalink C7125" -> "Versalink"
|
|
cleanModel = Replace(model, " ", "")
|
|
|
|
' Try to extract base model name (remove version numbers and suffixes)
|
|
If InStr(cleanModel, "ColorLaserJet") > 0 Then
|
|
shortDescription = "ColorLaserJet"
|
|
ElseIf InStr(cleanModel, "LaserJetPro") > 0 Then
|
|
shortDescription = "LaserJetPro"
|
|
ElseIf InStr(cleanModel, "LaserJet") > 0 Then
|
|
shortDescription = "LaserJet"
|
|
ElseIf InStr(cleanModel, "Altalink") > 0 Then
|
|
shortDescription = "Altalink"
|
|
ElseIf InStr(cleanModel, "Versalink") > 0 Then
|
|
shortDescription = "Versalink"
|
|
ElseIf InStr(cleanModel, "DesignJet") > 0 Then
|
|
shortDescription = "DesignJet"
|
|
ElseIf InStr(cleanModel, "DTC") > 0 Then
|
|
shortDescription = "DTC"
|
|
Else
|
|
' Fallback: Extract model prefix before numbers
|
|
' For models like "EC8036" -> "EC", "C7125" -> "C"
|
|
Dim i, char
|
|
shortDescription = ""
|
|
For i = 1 To Len(cleanModel)
|
|
char = Mid(cleanModel, i, 1)
|
|
' Stop when we hit a number
|
|
If char >= "0" And char <= "9" Then
|
|
Exit For
|
|
End If
|
|
shortDescription = shortDescription & char
|
|
Next
|
|
' If we got nothing (started with number), use full model
|
|
If shortDescription = "" Then
|
|
shortDescription = cleanModel
|
|
End If
|
|
End If
|
|
|
|
' Determine printer name to use
|
|
' Prefer Windows Name from database if it's already in standardized format (contains dashes)
|
|
' Otherwise generate standardized name automatically
|
|
If InStr(printerName, "-") > 0 Then
|
|
' Use database Windows Name as-is (user manually set it)
|
|
standardName = printerName
|
|
Else
|
|
' Generate standard name: CSFName-Location-VendorModel (no dash between vendor and model)
|
|
If csfName <> "" And csfName <> "NONE" And csfName <> "gage lab " Then
|
|
' Has CSF name
|
|
' Check if CSF name already matches the machine location (avoid duplication)
|
|
If cleanMachine <> "" And LCase(csfName) <> LCase(cleanMachine) Then
|
|
standardName = csfName & "-" & cleanMachine & "-" & vendor & shortDescription
|
|
Else
|
|
' CSF name same as location, or no location - just use CSF-VendorModel
|
|
standardName = csfName & "-" & vendor & shortDescription
|
|
End If
|
|
Else
|
|
' No CSF name - use Location-VendorModel
|
|
If cleanMachine <> "" Then
|
|
standardName = cleanMachine & "-" & vendor & shortDescription
|
|
Else
|
|
standardName = "Printer" & rs("printerid") & "-" & vendor & shortDescription
|
|
End If
|
|
End If
|
|
End If
|
|
standardName = Replace(standardName, """", "\""")
|
|
|
|
' Escape install path
|
|
Dim installPath, preferredAddress
|
|
installPath = Replace(rs("installpath") & "", """", "\""")
|
|
|
|
' Determine preferred address: FQDN if exists, otherwise IP
|
|
If fqdn <> "" And fqdn <> "USB" Then
|
|
preferredAddress = fqdn
|
|
Else
|
|
preferredAddress = ipAddr
|
|
End If
|
|
preferredAddress = Replace(preferredAddress, """", "\""")
|
|
|
|
jsonOutput = jsonOutput & vbCrLf & " ""printerwindowsname"": """ & standardName & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""printercsfname"": """ & csfName & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""fqdn"": """ & fqdn & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""ipaddress"": """ & ipAddr & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""address"": """ & preferredAddress & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""vendor"": """ & vendor & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""modelnumber"": """ & model & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""machinename"": """ & machineName & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""installpath"": """ & installPath & ""","
|
|
jsonOutput = jsonOutput & vbCrLf & " ""isactive"": " & LCase(CStr(CBool(rs("isactive"))))
|
|
jsonOutput = jsonOutput & vbCrLf & " }"
|
|
End If
|
|
|
|
rs.MoveNext
|
|
Loop
|
|
|
|
rs.Close
|
|
Set rs = Nothing
|
|
objConn.Close
|
|
|
|
jsonOutput = jsonOutput & vbCrLf & "]"
|
|
|
|
Response.Write(jsonOutput)
|
|
%>
|