All checks were successful
Deploy netdiag / deploy (push) Successful in 14s
protocols.php (POST) gab bei JEDEM Sync HTTP 500 zurueck — 0 Protokolle wurden je gespeichert. Ursache: protocol/device/measurement-Klassen deklarierten das tms-Feld im $fields-Array als 'notnull' => 1. Dolibarrs createCommon() bricht ab (-1), wenn ein notnull-Feld den Wert NULL hat und kein 'default' gesetzt ist. tms wird von der App nie gesetzt (die DB fuellt es per CURRENT_TIMESTAMP), also schlug jedes Insert fehl, bevor es ueberhaupt an die DB ging. Fix: tms auf 'notnull' => 0 — so wie es der Dolibarr-Modul-Builder auch generiert. Die DB-Spalte bleibt NOT NULL DEFAULT CURRENT_TIMESTAMP. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
170 lines
5.7 KiB
PHP
170 lines
5.7 KiB
PHP
<?php
|
|
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* \file htdocs/custom/netdiag/class/netdiagmeasurement.class.php
|
|
* \ingroup netdiag
|
|
* \brief Klasse für eine Messung (ein Tool-Lauf) im Diagnose-Protokoll
|
|
*/
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
|
|
|
/**
|
|
* Klasse NetDiagMeasurement — Ergebnis eines Tool-Laufs.
|
|
*
|
|
* params/result sind generisches JSON: neue Tools brauchen kein Schema-Update.
|
|
*/
|
|
class NetDiagMeasurement extends CommonObject
|
|
{
|
|
/** @var string Modul-Name */
|
|
public $module = 'netdiag';
|
|
|
|
/** @var string Element-Typ */
|
|
public $element = 'netdiagmeasurement';
|
|
|
|
/** @var string Datenbanktabelle (ohne Präfix) */
|
|
public $table_element = 'netdiag_measurement';
|
|
|
|
/** @var string Icon */
|
|
public $picto = 'fa-wave-square';
|
|
|
|
/** @var int 1 = Tabelle hat ein 'entity'-Feld */
|
|
public $ismultientitymanaged = 1;
|
|
|
|
/** Ampel-Status der Messung */
|
|
const RESULT_OK = 0;
|
|
const RESULT_WARN = 1;
|
|
const RESULT_FAIL = 2;
|
|
|
|
/**
|
|
* @var array<string,array<string,mixed>> Felddefinitionen
|
|
*/
|
|
public $fields = array(
|
|
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1),
|
|
'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'default' => 1, 'index' => 1, 'position' => 5),
|
|
'fk_protocol' => array('type' => 'integer', 'label' => 'Protocol', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 10),
|
|
'fk_device' => array('type' => 'integer', 'label' => 'Device', 'enabled' => 1, 'visible' => 0, 'index' => 1, 'position' => 15),
|
|
'tool' => array('type' => 'varchar(64)', 'label' => 'Tool', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 20),
|
|
'category' => array('type' => 'varchar(32)', 'label' => 'ToolCategory', 'enabled' => 1, 'visible' => 1, 'position' => 25),
|
|
'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30),
|
|
'params' => array('type' => 'text', 'label' => 'Params', 'enabled' => 1, 'visible' => 0, 'position' => 40),
|
|
'result' => array('type' => 'text', 'label' => 'Result', 'enabled' => 1, 'visible' => 0, 'position' => 45),
|
|
'measure_status' => array('type' => 'smallint', 'label' => 'MeasureStatus', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'default' => 0, 'position' => 50),
|
|
'date_measure' => array('type' => 'datetime', 'label' => 'DateMeasure', 'enabled' => 1, 'visible' => 1, 'position' => 55),
|
|
'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 500),
|
|
'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 0, 'position' => 501),
|
|
);
|
|
|
|
public $rowid;
|
|
public $entity;
|
|
public $fk_protocol;
|
|
public $fk_device;
|
|
public $tool;
|
|
public $category;
|
|
public $label;
|
|
public $params;
|
|
public $result;
|
|
public $measure_status;
|
|
public $date_measure;
|
|
public $date_creation;
|
|
public $tms;
|
|
|
|
/**
|
|
* Konstruktor
|
|
*
|
|
* @param DoliDB $db Datenbank-Handler
|
|
*/
|
|
public function __construct(DoliDB $db)
|
|
{
|
|
$this->db = $db;
|
|
}
|
|
|
|
/**
|
|
* Datensatz anlegen
|
|
*
|
|
* @param User $user Benutzer
|
|
* @param int $notrigger 1 = Trigger unterdrücken
|
|
* @return int >0 wenn OK, <=0 bei Fehler
|
|
*/
|
|
public function create(User $user, $notrigger = 0)
|
|
{
|
|
if (empty($this->date_measure)) {
|
|
$this->date_measure = dol_now();
|
|
}
|
|
return $this->createCommon($user, $notrigger);
|
|
}
|
|
|
|
/**
|
|
* Datensatz laden
|
|
*
|
|
* @param int $id Rowid
|
|
* @param string $ref Referenz
|
|
* @return int >0 wenn OK, 0 wenn nicht gefunden, <0 bei Fehler
|
|
*/
|
|
public function fetch($id, $ref = null)
|
|
{
|
|
return $this->fetchCommon($id, $ref);
|
|
}
|
|
|
|
/**
|
|
* Alle Messungen eines Protokolls laden
|
|
*
|
|
* @param int $fk_protocol Protokoll-Rowid
|
|
* @return NetDiagMeasurement[] Liste der Messungen
|
|
*/
|
|
public function fetchAllByProtocol($fk_protocol)
|
|
{
|
|
$result = array();
|
|
$sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element;
|
|
$sql .= " WHERE fk_protocol = ".((int) $fk_protocol);
|
|
$sql .= " ORDER BY date_measure, rowid";
|
|
$resql = $this->db->query($sql);
|
|
if ($resql) {
|
|
while ($obj = $this->db->fetch_object($resql)) {
|
|
$m = new self($this->db);
|
|
if ($m->fetch((int) $obj->rowid) > 0) {
|
|
$result[] = $m;
|
|
}
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Datensatz aktualisieren
|
|
*
|
|
* @param User $user Benutzer
|
|
* @param int $notrigger 1 = Trigger unterdrücken
|
|
* @return int >0 wenn OK, <=0 bei Fehler
|
|
*/
|
|
public function update(User $user, $notrigger = 0)
|
|
{
|
|
return $this->updateCommon($user, $notrigger);
|
|
}
|
|
|
|
/**
|
|
* Datensatz löschen
|
|
*
|
|
* @param User $user Benutzer
|
|
* @param int $notrigger 1 = Trigger unterdrücken
|
|
* @return int >0 wenn OK, <=0 bei Fehler
|
|
*/
|
|
public function delete(User $user, $notrigger = 0)
|
|
{
|
|
return $this->deleteCommon($user, $notrigger);
|
|
}
|
|
}
|