From 5fe018cdba22129356b8dbe773e37229623e8c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Wed, 19 Mar 2025 13:53:17 +0100 Subject: [PATCH] NEW ; Add hook on API call (#33501) * NEW ; Add hook on API call * Update index.php --------- Co-authored-by: Laurent Destailleur --- htdocs/api/index.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 7dab6412a7c..0f98d959e7b 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -3,8 +3,8 @@ * Copyright (C) 2016 Laurent Destailleur * Copyright (C) 2017 Regis Houssin * Copyright (C) 2021 Alexis LAURIER - * Copyright (C) 2024 MDW - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 MDW + * Copyright (C) 2024 Frédéric France * * 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 @@ -379,6 +379,15 @@ if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && } } + $parameters = array('url' => $url, 'ip' => getUserRemoteIP(), 'moduleobject' => $moduleobject, 'classfile' => $classfile, 'classname' => $classname); + $object = $api; + $action = $api->r->requestMethod; + // Note that $action and $object may be modified by some hooks + $reshook = $hookmanager->executeHooks('beforeApiCall', $parameters, $object, $action); + if ($reshook < 0) { + dol_syslog('beforeapicall Failed to call hook '.$hookmanager->error, LOG_ERR); + } + dol_syslog('Search api file /'.$moduledirforclass.'/class/api_'.$classfile.'.class.php => dir_part_file='.$dir_part_file.', classname='.$classname); $res = false;