Skip to content

Commit

Permalink
Merge branch 'develop' of [email protected]:Dolibarr/dolibarr.git into f…
Browse files Browse the repository at this point in the history
…ix_dev_permissions_error
  • Loading branch information
hregis committed Apr 9, 2024
2 parents 214d62a + 4bcbe4e commit 8ced7f5
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 291 deletions.
26 changes: 26 additions & 0 deletions htdocs/core/class/hookmanager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class HookManager
// Array with instantiated classes
public $hooks = array();

/**
* @var array List of hooks called during this request
*/
public $hooksHistory = [];

Check warning on line 56 in htdocs/core/class/hookmanager.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

hookmanager.class.php: PhanPluginUnknownArrayPropertyType: Property \HookManager->hooksHistory has an array type, but does not specify any key types or value types (Types inferred after analysis: array|array<string,array<string,associative-array<int,mixed>>>|array<string,array<string,associative-array<mixed,string>>>|array<string,array<string,float>>|array<string,array<string,int>>|array<string,array<string,mixed>>|array<string,array<string,string>>)

// Array result
public $resArray = array();
// Printable result
Expand Down Expand Up @@ -155,6 +160,27 @@ public function initHooks($arraycontext)
*/
public function executeHooks($method, $parameters = array(), &$object = null, &$action = '')
{
//global $debugbar;
//if (is_object($debugbar) && get_class($debugbar) === 'DolibarrDebugBar') {
if (isModEnabled('debugbar') && function_exists('debug_backtrace')) {
$trace = debug_backtrace();
if (isset($trace[0])) {
$hookInformations = [
'name' => $method,
'contexts' => $this->contextarray,
'file' => $trace[0]['file'],
'line' => $trace[0]['line'],
];
$hash = md5(json_encode($hookInformations));
if (!empty($this->hooksHistory[$hash])) {
$this->hooksHistory[$hash]['count']++;
} else {
$hookInformations['count'] = 1;
$this->hooksHistory[$hash] = $hookInformations;
}
}
}

if (!is_array($this->hooks) || empty($this->hooks)) {
return 0; // No hook available, do nothing.
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/class/html.form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8504,12 +8504,12 @@ public static function selectarray($htmlname, $array, $id = '', $show_empty = 0,
foreach ($array as $key => $tmpvalue) {
if (is_array($tmpvalue)) {
$value = $tmpvalue['label'];
$valuehtml = $tmpvalue['data-html'];
//$valuehtml = empty($tmpvalue['data-html']) ? $value : $tmpvalue['data-html'];
$disabled = empty($tmpvalue['disabled']) ? '' : ' disabled';
$style = empty($tmpvalue['css']) ? '' : ' class="' . $tmpvalue['css'] . '"';
} else {
$value = $tmpvalue;
$valuehtml = $tmpvalue;
//$valuehtml = $tmpvalue;
$disabled = '';
$style = '';
}
Expand Down
94 changes: 94 additions & 0 deletions htdocs/debugbar/class/DataCollector/DolHooksCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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/debugbar/class/DataCollector/DolHooksCollector.php
* \brief Class for debugbar collection
* \ingroup debugbar
*/

use DebugBar\DataCollector\RequestDataCollector;


/**
* DolRequestDataCollector class
*/
class DolHooksCollector extends RequestDataCollector
{
/**
* Collects the data from the collectors
*
* @return array
*/
public function collect()

Check warning on line 37 in htdocs/debugbar/class/DataCollector/DolHooksCollector.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

DolHooksCollector.php: PhanPluginUnknownArrayMethodReturnType: Method \DolHooksCollector::collect() has a return type of array, but does not specify any key types or value types
{
/**
* @global $hookmanager HookManager
*/
global $hookmanager;

$data = ['hooks' => []];
if (empty($hookmanager->hooksHistory)) {
return $data;
}
$i = 0;
foreach ($hookmanager->hooksHistory as $key => $hookHistory) {
$i++;
$hookHistory['contexts'] = implode(', ', $hookHistory['contexts']);
$data['hooks']["[$i] {$hookHistory['name']}"] = $hookHistory;

// $data["[$key] {$hookHistory['name']}"] = "{$hookHistory['file']} (L{$hookHistory['line']}). Contexts: "
// . implode(', ', $hookHistory['contexts']);
}
$data['nb_of_hooks'] = count($data['hooks']);

return $data;
}

/**
* Return widget settings
*
* @return string[][]
*/
public function getWidgets()
{
global $langs;

$langs->load("other");

return [
$langs->transnoentities('Hooks') => [
"icon" => "tags",
"widget" => "PhpDebugBar.Widgets.HookListWidget",
"map" => "hooks.hooks",
"default" => "{}"
],
"{$langs->transnoentities('Hooks')}:badge" => [
"map" => "hooks.nb_of_hooks",

Check warning on line 81 in htdocs/debugbar/class/DataCollector/DolHooksCollector.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

DolHooksCollector.php: PhanTypeMismatchReturn: Returning ['map'=&gt;'hooks.nb_of_hooks','default'=&gt;0] of type array&lt;string,array{map:'hooks.nb_of_hooks',default:0}&gt; but getWidgets() is declared to return string[][]
"default" => 0
]
];
}

/**
* @return string
*/
public function getName()
{
return 'hooks';
}
}
57 changes: 0 additions & 57 deletions htdocs/debugbar/class/DataCollector/DolMessagesCollector.php

This file was deleted.

3 changes: 2 additions & 1 deletion htdocs/debugbar/class/DataCollector/DolibarrCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public function getAssets()
{
return array(
'base_url' => dol_buildpath('/debugbar', 1),
'js' => 'js/widgets.js'
'js' => 'js/widgets.js',
'css' => 'css/widgets.css'
);
}
}
5 changes: 2 additions & 3 deletions htdocs/debugbar/class/DebugBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

use DebugBar\DebugBar;

dol_include_once('/debugbar/class/DataCollector/DolMessagesCollector.php');
dol_include_once('/debugbar/class/DataCollector/DolRequestDataCollector.php');
dol_include_once('/debugbar/class/DataCollector/DolConfigCollector.php');
dol_include_once('/debugbar/class/DataCollector/DolTimeDataCollector.php');
Expand All @@ -35,6 +34,7 @@
dol_include_once('/debugbar/class/DataCollector/DolQueryCollector.php');
dol_include_once('/debugbar/class/DataCollector/DolibarrCollector.php');
dol_include_once('/debugbar/class/DataCollector/DolLogsCollector.php');
dol_include_once('/debugbar/class/DataCollector/DolHooksCollector.php');

/**
* DolibarrDebugBar class
Expand All @@ -50,8 +50,6 @@ class DolibarrDebugBar extends DebugBar
*/
public function __construct()
{
global $conf;

//$this->addCollector(new PhpInfoCollector());
//$this->addCollector(new DolMessagesCollector());
$this->addCollector(new DolRequestDataCollector());
Expand All @@ -62,6 +60,7 @@ public function __construct()
//$this->addCollector(new DolExceptionsCollector());
$this->addCollector(new DolQueryCollector());
$this->addCollector(new DolibarrCollector());
$this->addCollector(new DolHooksCollector());
if (isModEnabled('syslog')) {
$this->addCollector(new DolLogsCollector());
}
Expand Down
48 changes: 48 additions & 0 deletions htdocs/debugbar/css/widgets.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
span.phpdebugbar-widgets-value {
white-space: pre;
}

dl.phpdebugbar-widgets-kvlist.phpdebugbar-widgets-hooklist dt {
float: left;
width: 230px;
padding: 5px;
border-top: 1px solid #eee;
font-weight: bold;
clear: both;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
dl.phpdebugbar-widgets-kvlist.phpdebugbar-widgets-hooklist dt span {
font-weight: bold;
}
dl.phpdebugbar-widgets-kvlist dd {
margin-left: 240px;
padding: 5px;
border-top: 1px solid #eee;
cursor: pointer;
min-height: 17px;
}

dl.phpdebugbar-widgets-kvlist dd span {
display: inline-block;
}

dl.phpdebugbar-widgets-kvlist dd span strong{
font-weight: bold;
}

dl.phpdebugbar-widgets-kvlist dd span:nth-of-type(1) {
min-width: 550px;
margin-right: 20px;
}

dl.phpdebugbar-widgets-kvlist dd span:nth-of-type(2) {
min-width: 90px;
margin-right: 20px;
}

dl.phpdebugbar-widgets-kvlist dd span:nth-of-type(3) {
min-width: 80px;
margin-right: 20px;
}
26 changes: 25 additions & 1 deletion htdocs/debugbar/js/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,28 @@

});

})(PhpDebugBar.$);
/**
* An extension of KVListWidget where the data represents a list
* of variables
*
* Options:
* - data
*/
var HookListWidget = PhpDebugBar.Widgets.HookListWidget = PhpDebugBar.Widgets.KVListWidget.extend({
className: csscls('widgets-kvlist widgets-hooklist'),

itemRenderer: function(dt, dd, key, object) {
$('<span />').attr('title', key).text(key).appendTo(dt);


dd.html('<span><strong>File: </strong> ' + object.file
+ '</span><span><strong>Line: </strong>' + object.line
+ '</span><span><strong>Count: </strong>' + object.count
+ '</span><span><strong>Contexts: </strong>' + (object.contexts === null || object.contexts === '' ? 'Not set' : object.contexts)
+ '</span>'
);
}
});


})(PhpDebugBar.$);
Loading

0 comments on commit 8ced7f5

Please sign in to comment.