mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-11 20:45:32 +08:00
Use device datastore .Devices() method instead of GetDeviceByUDID.
Query by both device.SerialNumber and device.UDID join WHERE conditions using the OR logical operator. I can't determine whether this has an impact elsewhere.
This commit is contained in:
@@ -83,11 +83,21 @@ func (svc service) checkRequeue(deviceUDID string) (int, error) {
|
||||
|
||||
// Acknowledge Queries sent with DeviceInformation command
|
||||
func (svc service) ackQueryResponses(req mdm.Response) error {
|
||||
existing, err := svc.devices.GetDeviceByUDID(req.UDID, []string{"device_uuid", "serial_number"}...)
|
||||
devices, err := svc.devices.Devices(
|
||||
device.SerialNumber{SerialNumber: req.QueryResponses.SerialNumber},
|
||||
device.UDID{UDID: req.UDID},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(devices) > 1 {
|
||||
return errors.New("Expected a single query result for device, got more than one.")
|
||||
}
|
||||
|
||||
existing := devices[0]
|
||||
|
||||
now := time.Now()
|
||||
existing.LastCheckin = &now
|
||||
existing.LastQueryResponse, err = json.Marshal(req.QueryResponses)
|
||||
@@ -105,5 +115,5 @@ func (svc service) ackQueryResponses(req mdm.Response) error {
|
||||
existing.OSVersion = req.QueryResponses.OSVersion
|
||||
existing.SerialNumber = req.QueryResponses.SerialNumber
|
||||
|
||||
return svc.devices.Save("queryResponses", existing)
|
||||
return svc.devices.Save("queryResponses", &existing)
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ func addWhereFilters(stmt string, params ...interface{}) string {
|
||||
}
|
||||
|
||||
if len(where) != 0 {
|
||||
whereFilter := strings.Join(where, ",")
|
||||
whereFilter := strings.Join(where, " OR ")
|
||||
stmt = fmt.Sprintf("%s WHERE %s", stmt, whereFilter)
|
||||
}
|
||||
return stmt
|
||||
|
||||
Reference in New Issue
Block a user