Sync-500 behoben: App-Zeitstempel (ms) auf Sekunden umrechnen [deploy]
All checks were successful
Deploy netdiag / deploy (push) Successful in 16s

DER eigentliche Fehler: Die App schickt dateDiag/dateMeasure als
JavaScript-Millisekunden (Date.now(), 13-stellig). Dolibarrs idate()
erwartet Unix-Sekunden -> MySQL: "Incorrect datetime value: Bad value
1779211311036 for date" -> createCommon scheitert -> HTTP 500.

Fix: netdiag_api_timestamp() rechnet ms-Zeitstempel (> 1e11) auf Sekunden
um. protocols.php nutzt sie fuer date_diag und date_measure.

Serverseitig bewusst — so synchronisieren auch bereits installierte
App-Versionen ohne APK-Update korrekt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Eduard Wisch 2026-05-19 19:34:48 +02:00
parent e914454e0f
commit db2390d997
2 changed files with 24 additions and 2 deletions

View file

@ -298,6 +298,28 @@ function netdiag_api_read_body()
return is_array($data) ? $data : array();
}
/**
* Zeitstempel der App in einen Unix-Zeitstempel (Sekunden) umrechnen.
*
* Die App (JavaScript) liefert Zeitstempel in Millisekunden (Date.now()).
* Dolibarr/`idate()` erwartet Sekunden sonst: "Bad value ... for date".
*
* @param mixed $value Zeitstempel aus dem Request (ms, s oder leer)
* @return int Unix-Zeitstempel in Sekunden
*/
function netdiag_api_timestamp($value)
{
$v = (int) $value;
if ($v <= 0) {
return dol_now();
}
// 13-stellig (> ~Jahr 5138 in Sekunden) = Millisekunden -> auf Sekunden
if ($v > 100000000000) {
$v = (int) ($v / 1000);
}
return $v;
}
/**
* Liste von Diagnose-Protokollen als Array zurückgeben (für API-Antworten).
*

View file

@ -134,7 +134,7 @@ $protocol->client_uuid = $uuid;
$protocol->label = isset($p['label']) ? (string) $p['label'] : '';
$protocol->fk_soc = !empty($p['socId']) ? (int) $p['socId'] : null;
$protocol->fk_commande = !empty($p['orderId']) ? (int) $p['orderId'] : null;
$protocol->date_diag = !empty($p['dateDiag']) ? (int) $p['dateDiag'] : dol_now();
$protocol->date_diag = netdiag_api_timestamp($p['dateDiag'] ?? 0);
$protocol->fk_user_techniker = (int) $user->id;
$protocol->standort = isset($p['location']) ? (string) $p['location'] : '';
$protocol->subnet = isset($p['subnet']) ? (string) $p['subnet'] : '';
@ -194,7 +194,7 @@ foreach ($measIn as $m) {
$meas->params = isset($m['params']) ? json_encode($m['params'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : null;
$meas->result = isset($m['result']) ? json_encode($m['result'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : null;
$meas->measure_status = isset($m['measureStatus']) ? (int) $m['measureStatus'] : 0;
$meas->date_measure = !empty($m['dateMeasure']) ? (int) $m['dateMeasure'] : dol_now();
$meas->date_measure = netdiag_api_timestamp($m['dateMeasure'] ?? 0);
$meas->tms = dol_now();
if ($meas->create($user, 1) <= 0) {
$db->rollback();