Debug v23

This commit is contained in:
Laurent Destailleur 2025-10-20 20:44:17 +02:00
parent 6f88b841e0
commit dab2bcbd90
2 changed files with 70 additions and 30 deletions

View file

@ -236,8 +236,9 @@ if ($action === 'downloadblockchain') {
}
if (!$error) {
// Now restart request with all data = no limit(1) in sql request
$sql = "SELECT rowid, date_creation, tms, user_fullname, action, amounts, element, fk_object, date_object, ref_object, signature, fk_user, object_data, object_version, debuginfo";
// Now restart request with all data, si without the limit(1) in sql request
$sql = "SELECT rowid, date_creation, tms, user_fullname, action, amounts, element, fk_object, date_object, ref_object,";
$sql .= " signature, fk_user, object_data, object_version, object_format, debuginfo";
$sql .= " FROM ".MAIN_DB_PREFIX."blockedlog";
$sql .= " WHERE entity = ".((int) $conf->entity);
if (GETPOSTINT('monthtoexport') > 0 || GETPOSTINT('yeartoexport') > 0) {
@ -280,21 +281,43 @@ if ($action === 'downloadblockchain') {
// We set here all data used into signature calculation (see checkSignature method) and more
// IMPORTANT: We must have here, the same rule for transformation of data than into the fetch method (db->jdate for date, ...)
$block_static->id = $obj->rowid;
$block_static->date_creation = $db->jdate($obj->date_creation);
$block_static->date_modification = $db->jdate($obj->tms);
$block_static->entity = $obj->entity;
$block_static->date_creation = $db->jdate($obj->date_creation); // TODO Use gmt
$block_static->amounts = (float) $obj->amounts; // Database store value with 8 digits, we cut ending 0 them with (flow)
$block_static->vat = $obj->vat;
$block_static->action = $obj->action;
$block_static->fk_object = $obj->fk_object;
$block_static->element = $obj->element;
$block_static->amounts = (float) $obj->amounts;
$block_static->date_object = $db->jdate($obj->date_object); // TODO Use gmt ?
$block_static->ref_object = $obj->ref_object;
$block_static->date_object = $db->jdate($obj->date_object);
$block_static->user_fullname = $obj->user_fullname;
$block_static->fk_user = $obj->fk_user;
$block_static->signature = $obj->signature;
$block_static->object_data = $block_static->dolDecodeBlockedData($obj->object_data);
$block_static->object_version = $obj->object_version;
// Old hash + Previous fields concatenated = signature
$block_static->signature = $obj->signature;
$block_static->element = $obj->element; // Not in signature
$block_static->fk_object = $obj->fk_object; // Not in signature
$block_static->fk_user = $obj->fk_user; // Not in signature
$block_static->date_modification = $db->jdate($obj->tms); // Not in signature
$block_static->object_version = $obj->object_version; // Not in signature
$block_static->object_format = $obj->object_format; // Not in signature
$block_static->signature_line = $obj->signature_line;
$block_static->certified = ($obj->certified == 1);
$block_static->linktoref = $obj->linktoref;
$block_static->linktype = $obj->linktype;
$block_static->debuginfo = $obj->debuginfo;
//var_dump($block->id.' '.$block->signature, $block->object_data);
$checksignature = $block_static->checkSignature($previoushash); // If $previoushash is not defined, checkSignature will search it
if ($checksignature) {
@ -313,21 +336,22 @@ if ($action === 'downloadblockchain') {
if ($i == 0) {
$statusofrecordnote = $langs->trans("PreviousFingerprint").': '.$previoushash.($statusofrecordnote ? ' - '.$statusofrecordnote : '');
}
fwrite($fh, $obj->rowid
.';'.$obj->date_creation
.';"'.str_replace('"', '""', $obj->user_fullname).'";'
.$obj->action
.';'.$obj->element
.';'.$obj->amounts
.';'.$obj->fk_object
.';'.$obj->date_object
.';"'.str_replace('"', '""', $obj->ref_object).'";'
.$obj->signature
.';'.$statusofrecord
fwrite($fh, $block_static->id
.';'.$block_static->date_creation
.';"'.str_replace('"', '""', $block_static->user_fullname).'";'
.$block_static->action
.';'.$block_static->element
.';'.$block_static->amounts // Can be 1.20000000 with 8 digits. TODO Clean to have 8 digits in V1
.';'.$block_static->fk_object
.';'.$block_static->date_object
.';"'.str_replace('"', '""', $block_static->ref_object).'";"'
.$block_static->signature.'";'
.$statusofrecord
.';'.$statusofrecordnote
.';'.$obj->object_version
.';"'.str_replace('"', '""', $obj->object_data).'";'
.str_replace('"', '""', $obj->debuginfo).'"'
.';'.$block_static->object_version
.';"'.str_replace('"', '""', $obj->object_data).'"' // We must the string to decode into object with dolDecodeBlockedData
.';"'.str_replace('"', '""', $block_static->debuginfo).'"'
."\n");
// Set new previous hash for next fetch
@ -593,9 +617,10 @@ if (getDolGlobalString('BLOCKEDLOG_SCAN_ALL_FOR_LOWERIDINERROR')) {
// TODO Make a full scan of table in reverse order of id of $block, so we can use the parameter $previoushash into checkSignature to save requests
// to find the $loweridinerror.
} else {
// This is version that optimize the memory (but will not report errors that are outside the filter range)
// This is version that optimize the memory (note: it will not report errors that are outside the filter range)
if (is_array($blocks)) {
foreach ($blocks as &$block) {
//var_dump($block->id.' '.$block->signature, $block->object_data);
$tmpcheckresult = $block->checkSignature('', 1); // Note: this make a sql request at each call, we can't avoid this as the sorting order is various
$checksignature = $tmpcheckresult['checkresult'];

View file

@ -77,12 +77,27 @@ class BlockedLog
*/
public $amounts = null;
/**
* @var float|string|null
*/
public $vat = null;
/**
* trigger action
* @var string
*/
public $action = '';
/**
* @var string $linktype. Example 'paymentofinvoice'
*/
public $linktype = '';
/**
* @var string $linkref
*/
public $linkref = '';
/**
* Object element
* @var string
@ -862,15 +877,15 @@ class BlockedLog
$this->id = $obj->rowid;
$this->entity = $obj->entity;
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_modification = $this->db->jdate($obj->tms);
$this->date_creation = $this->db->jdate($obj->date_creation); // TODO Use gmt ?
$this->date_modification = $this->db->jdate($obj->tms); // TODO Use gmt ?
$this->amounts = (float) $obj->amounts;
$this->action = $obj->action;
$this->element = $obj->element;
$this->fk_object = $obj->fk_object;
$this->date_object = $this->db->jdate($obj->date_object);
$this->date_object = $this->db->jdate($obj->date_object); // TODO Use gmt ?
$this->ref_object = $obj->ref_object;
$this->fk_user = $obj->fk_user;
@ -1102,7 +1117,7 @@ class BlockedLog
//$signature_line = dol_hash($concatenatedata, '5'); // Not really useful
$signature = dol_hash($previoushash.$concatenatedata, 'sha256');
//var_dump($previoushash); var_dump($concatenatedata); var_dump($signature_line); var_dump($signature);
$res = ($signature === $this->signature);