Skip to content

Commit

Permalink
Merge branch 'develop' into patch-10
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy authored Nov 12, 2024
2 parents a079f4d + b86a481 commit ef800a1
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 26 deletions.
13 changes: 7 additions & 6 deletions htdocs/blockedlog/admin/blockedlog_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@
$result = restrictedArea($user, 'blockedlog', 0, '');

// Execution Time
$max_execution_time_for_importexport = (!getDolGlobalString('EXPORT_MAX_EXECUTION_TIME') ? 300 : $conf->global->EXPORT_MAX_EXECUTION_TIME); // 5mn if not defined
$max_execution_time_for_importexport = getDolGlobalInt('EXPORT_MAX_EXECUTION_TIME', 300); // 5mn if not defined
$max_time = @ini_get("max_execution_time");
if ($max_time && $max_time < $max_execution_time_for_importexport) {
dol_syslog("max_execution_time=".$max_time." is lower than max_execution_time_for_importexport=".$max_execution_time_for_importexport.". We try to increase it dynamically.");
@ini_set("max_execution_time", $max_execution_time_for_importexport); // This work only if safe mode is off. also web servers has timeout of 300
}

$MAXLINES = getDolGlobalInt('BLOCKEDLOG_MAX_LINES', 10000);
$MAXFORSHOWNLINKS = getDolGlobalInt('BLOCKEDLOG_MAX_FOR_SHOWN_LINKS', 100);


/*
* Actions
Expand Down Expand Up @@ -350,8 +353,6 @@

llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-blockedlog page-admin_blockedlog_list');

$MAXLINES = getDolGlobalInt('BLOCKEDLOG_MAX_LINES', 1000);

$blocks = $block_static->getLog('all', $search_id, $MAXLINES, $sortfield, $sortorder, $search_fk_user, $search_start, $search_end, $search_ref, $search_amount, $search_code);
if (!is_array($blocks)) {
if ($blocks == -2) {
Expand Down Expand Up @@ -587,7 +588,6 @@

if (is_array($blocks)) {
$nbshown = 0;
$MAXFORSHOWLINK = 100;
$object_link = '';
$object_link_title = '';

Expand All @@ -596,7 +596,7 @@
if (empty($search_showonlyerrors) || !$checkresult[$block->id]) {
$nbshown++;

if ($nbshown < $MAXFORSHOWLINK) { // For performance and memory purpose, we get/show the link of objects only for the 100 first output
if ($nbshown < $MAXFORSHOWNLINKS) { // For performance and memory purpose, we get/show the link of objects only for the 100 first output
$object_link = $block->getObjectLink();
$object_link_title = '';
} else {
Expand Down Expand Up @@ -647,8 +647,9 @@

// Fingerprint
print '<td class="nowraponall">';
// Note: the previous line id is not necessarily id-1, so in texttoshow we say "on previous line" without giving id to avoid a search/fetch to get previous id.
$texttoshow = $langs->trans("Fingerprint").' - '.$langs->trans("SavedOnLine").' =<br>'.$block->signature;
$texttoshow .= '<br><br>'.$langs->trans("Fingerprint").' - Recalculated sha256('.$langs->trans("PreviousHash").' on line '.($block->id - 1).' + data) =<br>'.$checkdetail[$block->id]['calculatedsignature'];
$texttoshow .= '<br><br>'.$langs->trans("Fingerprint").' - Recalculated sha256('.$langs->trans("PreviousHash").' on previous line + data) =<br>'.$checkdetail[$block->id]['calculatedsignature'];
$texttoshow .= '<br><span class="opacitymedium">'.$langs->trans("PreviousHash").'='.$checkdetail[$block->id]['previoushash'].'</span>';
//$texttoshow .= '<br>keyforsignature='.$checkdetail[$block->id]['keyforsignature'];
print $form->textwithpicto(dol_trunc($block->signature, 8), $texttoshow, 1, 'help', '', 0, 2, 'fingerprint'.$block->id);
Expand Down
50 changes: 37 additions & 13 deletions htdocs/blockedlog/class/blockedlog.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1088,23 +1088,47 @@ public function getPreviousHash($withlock = 0, $beforeid = 0)

$previoussignature = '';

$sql = "SELECT rowid, signature FROM ".MAIN_DB_PREFIX."blockedlog";
$sql .= " WHERE entity = ".((int) $conf->entity);
// Fast search of previous record by searching with beforeid - 1. This is very fast and will work 99% of time.
if ($beforeid) {
$sql .= " AND rowid < ".(int) $beforeid;
$sql = "SELECT rowid, signature FROM ".MAIN_DB_PREFIX."blockedlog";
$sql .= " WHERE entity = ".((int) $conf->entity);
$sql .= " AND rowid = ".((int) $beforeid - 1);
$sql .= ($withlock ? " FOR UPDATE " : "");

$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj) {
$previoussignature = $obj->signature;
}
} else {
dol_print_error($this->db);
exit;
}
}
$sql .= " ORDER BY rowid DESC LIMIT 1";
$sql .= ($withlock ? " FOR UPDATE " : "");

$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj) {
$previoussignature = $obj->signature;
if (empty($previoussignature)) {
$sql = "SELECT rowid, signature FROM ".MAIN_DB_PREFIX."blockedlog";
if ($beforeid) {
$sql.= $this->db->hintindex('entity_rowid', 1);
}
$sql .= " WHERE entity = ".((int) $conf->entity);
if ($beforeid) {
$sql .= " AND rowid < ".(int) $beforeid;
}
$sql .= " ORDER BY rowid DESC LIMIT 1";
$sql .= ($withlock ? " FOR UPDATE " : "");

$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj) {
$previoussignature = $obj->signature;
}
} else {
dol_print_error($this->db);
exit;
}
} else {
dol_print_error($this->db);
exit;
}

if (empty($previoussignature)) {
Expand Down
3 changes: 2 additions & 1 deletion htdocs/core/db/DoliDB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ public function stddevpop($nameoffield)
* Return SQL string to force an index
*
* @param string $nameofindex Name of index
* @param int $mode 0=Use, 1=Force
* @return string SQL string
*/
public function hintindex($nameofindex)
public function hintindex($nameofindex, $mode = 1)
{
return '';
}
Expand Down
5 changes: 3 additions & 2 deletions htdocs/core/db/mysqli.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ public function __construct($type, $host, $user, $pass, $name = '', $port = 0)
* Return SQL string to force an index
*
* @param string $nameofindex Name of index
* @param int $mode 0=Use, 1=Force
* @return string SQL string
*/
public function hintindex($nameofindex)
public function hintindex($nameofindex, $mode = 1)
{
return " FORCE INDEX(".preg_replace('/[^a-z0-9_]/', '', $nameofindex).")";
return " ".($mode == 1 ? 'FORCE' : 'USE')." INDEX(".preg_replace('/[^a-z0-9_]/', '', $nameofindex).")";
}


Expand Down
3 changes: 3 additions & 0 deletions htdocs/install/mysql/migration/20.0.0-21.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ALTER TABLE llx_hrm_evaluation MODIFY COLUMN modelpdf varchar(255) DEFAULT NULL;

-- V21 migration

ALTER TABLE llx_blockedlog DROP INDEX entity_action;
ALTER TABLE llx_blockedlog ADD INDEX entity_rowid (entity, rowid);

ALTER TABLE llx_ecm_files MODIFY COLUMN description varchar(255);
ALTER TABLE llx_ecm_files MODIFY COLUMN cover varchar(32);
ALTER TABLE llx_ecm_files ADD COLUMN content text;
Expand Down
23 changes: 21 additions & 2 deletions htdocs/install/mysql/tables/llx_blockedlog.key.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
-- ===================================================================
-- Copyright (C) 2024 Laurent Destailleur <[email protected]>
--
-- 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/>.
--
-- ===================================================================

ALTER TABLE llx_blockedlog ADD INDEX signature (signature);
ALTER TABLE llx_blockedlog ADD INDEX fk_object_element (fk_object,element);
ALTER TABLE llx_blockedlog ADD INDEX entity (entity);
ALTER TABLE llx_blockedlog ADD INDEX fk_user (fk_user);
ALTER TABLE llx_blockedlog ADD INDEX entity_action (entity,action);
ALTER TABLE llx_blockedlog ADD INDEX fk_user (fk_user);
ALTER TABLE llx_blockedlog ADD INDEX entity_action_certified (entity,action,certified);

ALTER TABLE llx_blockedlog ADD INDEX entity_rowid (entity, rowid); -- for the "SELECT rowid, signature FROM llx_blockedlog FORCE INDEX entity_rowid WHERE entity = x AND rowid < z ORDER BY rowid DESC"
4 changes: 2 additions & 2 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,14 @@ class Product extends CommonObject
/**
* Stock real (denormalized data)
*
* @var int
* @var float
*/
public $stock_reel = 0;

/**
* Stock virtual
*
* @var int
* @var float
*/
public $stock_theorique;

Expand Down

0 comments on commit ef800a1

Please sign in to comment.