From d9acbd01a24054a8c5c8350b820465028c128b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Tue, 21 Jan 2025 16:50:33 +0100 Subject: [PATCH] Remove specific AJAX handling based on manual declarations --- .phpstan-baseline.php | 6 --- CHANGELOG.md | 2 +- ajax/2fa.php | 3 -- ajax/actorinformation.php | 2 - ajax/actors.php | 3 -- ajax/agent.php | 3 -- ajax/asset/assetdefinition.php | 3 -- ajax/asset/customfield.php | 3 -- ajax/central.php | 4 -- ajax/comments.php | 3 -- ajax/common.tabs.php | 3 -- ajax/commonitilsatisfaction.php | 3 -- ajax/displayMessageAfterRedirect.php | 3 -- ajax/dropdownConnectNetworkPort.php | 3 -- ajax/dropdownInstallVersion.php | 3 -- ajax/dropdownMassiveActionAddActor.php | 3 -- ajax/dropdownMassiveActionAddValidator.php | 3 -- ajax/dropdownMassiveActionAuthMethods.php | 3 -- ajax/dropdownRubDocument.php | 3 -- ajax/dropdownSoftwareLicense.php | 3 -- ajax/dropdownValidator.php | 3 -- ajax/entitytreesons.php | 3 -- ajax/fuzzysearch.php | 3 -- ajax/genericdate.php | 3 -- ajax/getDropdownUsers.php | 3 -- ajax/getFileTag.php | 3 -- ajax/getUserPicture.php | 3 -- ajax/impact.php | 3 -- ajax/itilfollowup.php | 3 -- ajax/itilvalidation.php | 3 -- ajax/kanban.php | 3 -- ajax/mailcollector.php | 3 -- ajax/notificationmailingsettings.php | 3 -- ajax/planningend.php | 3 -- ajax/projecttask.php | 3 -- ajax/rack.php | 4 -- ajax/resaperiod.php | 3 -- ajax/rule.php | 3 -- ajax/search.php | 5 -- ajax/solution.php | 3 -- ajax/subvisibility.php | 3 -- ajax/task.php | 3 -- ajax/ticketiteminformation.php | 3 -- ajax/uemailUpdate.php | 3 -- ajax/unlockobject.php | 3 -- ajax/visibility.php | 3 -- front/dropdown.common.form.php | 6 ++- front/reservation.form.php | 6 --- inc/includes.php | 10 ++-- phpstan.neon.dist | 3 -- .../Controller/LegacyFileLoadController.php | 18 +++---- .../LegacyPostRequestActionsListener.php | 53 ------------------- src/Glpi/Kernel/Kernel.php | 5 +- src/Session.php | 32 +++-------- 54 files changed, 30 insertions(+), 246 deletions(-) delete mode 100644 src/Glpi/Http/Listener/LegacyPostRequestActionsListener.php diff --git a/.phpstan-baseline.php b/.phpstan-baseline.php index 4e3b0703d8c..aee51d39cbb 100644 --- a/.phpstan-baseline.php +++ b/.phpstan-baseline.php @@ -2305,12 +2305,6 @@ 'count' => 2, 'path' => __DIR__ . '/src/Glpi/Controller/ApiController.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method Glpi\\\\Controller\\\\LegacyFileLoadController\\:\\:getRequest\\(\\) never returns null so it can be removed from the return type\\.$#', - 'identifier' => 'return.unusedType', - 'count' => 1, - 'path' => __DIR__ . '/src/Glpi/Controller/LegacyFileLoadController.php', -]; $ignoreErrors[] = [ 'message' => '#^Expression on left side of \\?\\? is not nullable\\.$#', 'identifier' => 'nullCoalesce.expr', diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ad2e72110..549b4c4a764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -233,7 +233,6 @@ The present file will list all changes made to the project; according to the - Usage of the `/marketplace` path for plugins URLs. All plugins URLs should now start with `/plugins`. - Usage of `GLPI_PLUGINS_PATH` javascript variable. - Usage of `MAIL_SMTPSSL` and `MAIL_SMTPTLS` constants. -- `$AJAX_INCLUDE` global variable usage. Use `$this->setAjax()` in legacy `/ajax/` and `/front` scripts or `Html::setAjax()` and `Session::setAjax()`. - Usage of `name` and `users_id_validate` parameter in `ajax/dropdownValidator.php`. - Usage of `users_id_validate` parameter in `front/commonitilvalidation.form.php`. - `front/ticket_ticket.form.php` script usage. @@ -307,6 +306,7 @@ The present file will list all changes made to the project; according to the - `GLPI_DEMO_MODE` constant. - `GLPI_DUMP_DIR` constant. - `GLPI_SQL_DEBUG` constant. +- `$AJAX_INCLUDE` global variable. - `$CFG_GLPI_PLUGINS` global variable. - `$DBCONNECTION_REQUIRED` and `$USEDBREPLICATE` global variables. Use `DBConnection::getReadConnection()` to get the most apporpriate connection for read only operations. - `$dont_check_maintenance_mode` and `$skip_db_check` global variables. diff --git a/ajax/2fa.php b/ajax/2fa.php index 89b9c1aaa82..083e075dcc2 100644 --- a/ajax/2fa.php +++ b/ajax/2fa.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - if (isset($_POST['regenerate_backup_codes'])) { $totp = new \Glpi\Security\TOTPManager(); $codes = $totp->regenerateBackupCodes(Session::getLoginUserID()); diff --git a/ajax/actorinformation.php b/ajax/actorinformation.php index 4a41f717054..23b8bb09d69 100644 --- a/ajax/actorinformation.php +++ b/ajax/actorinformation.php @@ -33,8 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/actors.php b/ajax/actors.php index 9da556143c2..4478188d366 100644 --- a/ajax/actors.php +++ b/ajax/actors.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - switch ($_REQUEST['action']) { case "getActors": header("Content-Type: application/json; charset=UTF-8"); diff --git a/ajax/agent.php b/ajax/agent.php index d5e852e1bed..81cd7882f13 100644 --- a/ajax/agent.php +++ b/ajax/agent.php @@ -36,9 +36,6 @@ use Glpi\Exception\Http\AccessDeniedHttpException; use Glpi\Exception\Http\NotFoundHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/asset/assetdefinition.php b/ajax/asset/assetdefinition.php index 52118a3124d..53b74ed186a 100644 --- a/ajax/asset/assetdefinition.php +++ b/ajax/asset/assetdefinition.php @@ -37,9 +37,6 @@ use Glpi\Exception\Http\BadRequestHttpException; use Glpi\Exception\Http\NotFoundHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - Session::checkRight(AssetDefinition::$rightname, READ); Session::writeClose(); diff --git a/ajax/asset/customfield.php b/ajax/asset/customfield.php index 813c1ab1d6b..992283916e7 100644 --- a/ajax/asset/customfield.php +++ b/ajax/asset/customfield.php @@ -35,9 +35,6 @@ use Glpi\Asset\CustomFieldDefinition; use Glpi\Exception\Http\BadRequestHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - Session::checkRight(CustomFieldDefinition::$rightname, READ); if (isset($_POST['action'])) { diff --git a/ajax/central.php b/ajax/central.php index 9c4c04b2184..8f4f8b46611 100644 --- a/ajax/central.php +++ b/ajax/central.php @@ -35,10 +35,6 @@ use Glpi\Exception\Http\BadRequestHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ - -$this->setAjax(); - // Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/comments.php b/ajax/comments.php index a87af662fe3..d9145520d90 100644 --- a/ajax/comments.php +++ b/ajax/comments.php @@ -38,9 +38,6 @@ */ global $CFG_GLPI; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - // Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/common.tabs.php b/ajax/common.tabs.php index 1cb12769e65..e3e6b7f41a2 100644 --- a/ajax/common.tabs.php +++ b/ajax/common.tabs.php @@ -38,9 +38,6 @@ */ global $CFG_GLPI; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/commonitilsatisfaction.php b/ajax/commonitilsatisfaction.php index 3eb091a66d4..cbd27da0bb7 100644 --- a/ajax/commonitilsatisfaction.php +++ b/ajax/commonitilsatisfaction.php @@ -36,9 +36,6 @@ use Glpi\Application\View\TemplateRenderer; use Glpi\Exception\Http\AccessDeniedHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/displayMessageAfterRedirect.php b/ajax/displayMessageAfterRedirect.php index 77bafa1e5ce..0f858262b0f 100644 --- a/ajax/displayMessageAfterRedirect.php +++ b/ajax/displayMessageAfterRedirect.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - Html::header_nocache(); if (isset($_GET['get_raw']) && filter_var(($_GET['display_container'] ?? true), FILTER_VALIDATE_BOOLEAN)) { diff --git a/ajax/dropdownConnectNetworkPort.php b/ajax/dropdownConnectNetworkPort.php index c6551f754e6..e4f35eec644 100644 --- a/ajax/dropdownConnectNetworkPort.php +++ b/ajax/dropdownConnectNetworkPort.php @@ -44,9 +44,6 @@ */ global $DB; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/dropdownInstallVersion.php b/ajax/dropdownInstallVersion.php index 8e99490ac03..e9f9c99f2fb 100644 --- a/ajax/dropdownInstallVersion.php +++ b/ajax/dropdownInstallVersion.php @@ -38,9 +38,6 @@ */ global $DB; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/dropdownMassiveActionAddActor.php b/ajax/dropdownMassiveActionAddActor.php index c692407c82d..f9a5ca4e00c 100644 --- a/ajax/dropdownMassiveActionAddActor.php +++ b/ajax/dropdownMassiveActionAddActor.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/dropdownMassiveActionAddValidator.php b/ajax/dropdownMassiveActionAddValidator.php index 81ec3e2ac75..b34a1eebece 100644 --- a/ajax/dropdownMassiveActionAddValidator.php +++ b/ajax/dropdownMassiveActionAddValidator.php @@ -42,9 +42,6 @@ */ global $CFG_GLPI; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/dropdownMassiveActionAuthMethods.php b/ajax/dropdownMassiveActionAuthMethods.php index b2da034b94b..dfe073beb66 100644 --- a/ajax/dropdownMassiveActionAuthMethods.php +++ b/ajax/dropdownMassiveActionAuthMethods.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/dropdownRubDocument.php b/ajax/dropdownRubDocument.php index ce3c0ad57b9..7572c50a2f4 100644 --- a/ajax/dropdownRubDocument.php +++ b/ajax/dropdownRubDocument.php @@ -38,9 +38,6 @@ */ global $DB; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/dropdownSoftwareLicense.php b/ajax/dropdownSoftwareLicense.php index b7e43977961..bc4430ac365 100644 --- a/ajax/dropdownSoftwareLicense.php +++ b/ajax/dropdownSoftwareLicense.php @@ -38,9 +38,6 @@ */ global $DB; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/dropdownValidator.php b/ajax/dropdownValidator.php index 1f8f772448c..7b0d8e476b4 100644 --- a/ajax/dropdownValidator.php +++ b/ajax/dropdownValidator.php @@ -42,9 +42,6 @@ */ global $CFG_GLPI; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/entitytreesons.php b/ajax/entitytreesons.php index 225d69b64c0..a12759e5b7c 100644 --- a/ajax/entitytreesons.php +++ b/ajax/entitytreesons.php @@ -39,9 +39,6 @@ */ global $CFG_GLPI, $GLPI_CACHE; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/fuzzysearch.php b/ajax/fuzzysearch.php index 80b29ff50a0..6d5fb43fa64 100644 --- a/ajax/fuzzysearch.php +++ b/ajax/fuzzysearch.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/genericdate.php b/ajax/genericdate.php index bf785befd82..9d0af418613 100644 --- a/ajax/genericdate.php +++ b/ajax/genericdate.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - // Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/getDropdownUsers.php b/ajax/getDropdownUsers.php index 474de9363e0..a5d8d2c6629 100644 --- a/ajax/getDropdownUsers.php +++ b/ajax/getDropdownUsers.php @@ -37,9 +37,6 @@ * @since 0.85 */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/getFileTag.php b/ajax/getFileTag.php index cb5ea33ea85..dc1b8d90680 100644 --- a/ajax/getFileTag.php +++ b/ajax/getFileTag.php @@ -37,9 +37,6 @@ * @since 0.85 */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header('Content-type: application/json; charset=UTF-8'); Html::header_nocache(); diff --git a/ajax/getUserPicture.php b/ajax/getUserPicture.php index dd1e7827930..8064c4e41f1 100644 --- a/ajax/getUserPicture.php +++ b/ajax/getUserPicture.php @@ -35,9 +35,6 @@ use Glpi\Exception\Http\BadRequestHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/impact.php b/ajax/impact.php index aae7d5d6c9a..dbf213731b0 100644 --- a/ajax/impact.php +++ b/ajax/impact.php @@ -41,9 +41,6 @@ const DELTA_ACTION_UPDATE = 2; const DELTA_ACTION_DELETE = 3; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - /** * @var array $CFG_GLPI */ diff --git a/ajax/itilfollowup.php b/ajax/itilfollowup.php index 394bf92b191..e7d0f00f80e 100644 --- a/ajax/itilfollowup.php +++ b/ajax/itilfollowup.php @@ -39,9 +39,6 @@ use Glpi\Exception\Http\BadRequestHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/itilvalidation.php b/ajax/itilvalidation.php index 0f9ddd55f94..c776c519167 100644 --- a/ajax/itilvalidation.php +++ b/ajax/itilvalidation.php @@ -39,9 +39,6 @@ use Glpi\Exception\Http\BadRequestHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/kanban.php b/ajax/kanban.php index efe4446c273..c69cadd6dd7 100644 --- a/ajax/kanban.php +++ b/ajax/kanban.php @@ -40,9 +40,6 @@ use Glpi\Features\Kanban; use Glpi\Features\Teamwork; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/mailcollector.php b/ajax/mailcollector.php index 10b9a220834..2c00e101db9 100644 --- a/ajax/mailcollector.php +++ b/ajax/mailcollector.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - // Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/notificationmailingsettings.php b/ajax/notificationmailingsettings.php index 25b2ae3eca2..74e99f6aa84 100644 --- a/ajax/notificationmailingsettings.php +++ b/ajax/notificationmailingsettings.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - Session::checkRight("config", UPDATE); if (isset($_POST["test_smtp_send"])) { diff --git a/ajax/planningend.php b/ajax/planningend.php index 9182b747c2f..4a2e8b56d7a 100644 --- a/ajax/planningend.php +++ b/ajax/planningend.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - // Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/projecttask.php b/ajax/projecttask.php index 8e8dcb267e4..e3e4deb52ce 100644 --- a/ajax/projecttask.php +++ b/ajax/projecttask.php @@ -37,9 +37,6 @@ * @since 9.2 */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/rack.php b/ajax/rack.php index dba8fcc1714..f07c75320ce 100644 --- a/ajax/rack.php +++ b/ajax/rack.php @@ -36,10 +36,6 @@ use Glpi\Exception\Http\AccessDeniedHttpException; use Glpi\Exception\Http\BadRequestHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ - -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/resaperiod.php b/ajax/resaperiod.php index b2c95fb2c18..c05b44a06d9 100644 --- a/ajax/resaperiod.php +++ b/ajax/resaperiod.php @@ -37,9 +37,6 @@ * @since 0.84 */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - // Send UTF8 Headers header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/rule.php b/ajax/rule.php index cfe0a199d75..45a25638087 100644 --- a/ajax/rule.php +++ b/ajax/rule.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - switch ($_REQUEST['action']) { case "move_rule": $rule_collection = getItemForItemtype($_POST['collection_classname']); diff --git a/ajax/search.php b/ajax/search.php index dfb70a2439f..41384f819e9 100644 --- a/ajax/search.php +++ b/ajax/search.php @@ -37,11 +37,6 @@ use Glpi\Exception\Http\BadRequestHttpException; use Glpi\Search\Input\QueryBuilder; -// Direct access to file - -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/solution.php b/ajax/solution.php index 95ef4b830a2..8a3060527d4 100644 --- a/ajax/solution.php +++ b/ajax/solution.php @@ -36,9 +36,6 @@ use Glpi\Exception\Http\BadRequestHttpException; use Glpi\RichText\RichText; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/subvisibility.php b/ajax/subvisibility.php index f8aabc0a304..2529e183197 100644 --- a/ajax/subvisibility.php +++ b/ajax/subvisibility.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/task.php b/ajax/task.php index 6b37a36752b..38d0d69f69a 100644 --- a/ajax/task.php +++ b/ajax/task.php @@ -39,9 +39,6 @@ use Glpi\Exception\Http\BadRequestHttpException; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: application/json; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/ticketiteminformation.php b/ajax/ticketiteminformation.php index ad856a288bb..177ff4eed65 100644 --- a/ajax/ticketiteminformation.php +++ b/ajax/ticketiteminformation.php @@ -33,9 +33,6 @@ * --------------------------------------------------------------------- */ -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/uemailUpdate.php b/ajax/uemailUpdate.php index 40de9d74b2a..cd7ad58bb6b 100644 --- a/ajax/uemailUpdate.php +++ b/ajax/uemailUpdate.php @@ -35,9 +35,6 @@ use Glpi\Application\View\TemplateRenderer; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/unlockobject.php b/ajax/unlockobject.php index 038c182f3af..6f862c7b3ba 100644 --- a/ajax/unlockobject.php +++ b/ajax/unlockobject.php @@ -42,9 +42,6 @@ // or url should be of the form 'http://.../.../unlockobject.php?requestunlock=1&id=xxxxxx' // to send notification to locker of object -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/ajax/visibility.php b/ajax/visibility.php index 0fed87fc095..f29c4b24d55 100644 --- a/ajax/visibility.php +++ b/ajax/visibility.php @@ -38,9 +38,6 @@ */ global $CFG_GLPI; -/** @var \Glpi\Controller\LegacyFileLoadController $this */ -$this->setAjax(); - header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); diff --git a/front/dropdown.common.form.php b/front/dropdown.common.form.php index e2346ebe140..3c11874d018 100644 --- a/front/dropdown.common.form.php +++ b/front/dropdown.common.form.php @@ -52,4 +52,8 @@ 'glpi_dropdown_form', )); -DropdownFormController::loadDropdownForm($this->request, $dropdown, $options ?? []); +DropdownFormController::loadDropdownForm( + $this->getRequest(), // @phpstan-ignore method.private + $dropdown, + $options ?? [] +); diff --git a/front/reservation.form.php b/front/reservation.form.php index 2b8377b9dba..e33b304fbd7 100644 --- a/front/reservation.form.php +++ b/front/reservation.form.php @@ -40,12 +40,6 @@ */ global $CFG_GLPI; -// avoid reloading js libs -if (isset($_GET['ajax']) && $_GET['ajax']) { - /** @var \Glpi\Controller\LegacyFileLoadController $this */ - $this->setAjax(); -} - Session::checkRight("reservation", ReservationItem::RESERVEANITEM); $rr = new Reservation(); diff --git a/inc/includes.php b/inc/includes.php index b8fbf3c1bf0..e2699290f2f 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -33,15 +33,13 @@ * --------------------------------------------------------------------- */ -use Glpi\Controller\LegacyFileLoadController; - /** @var int|bool|null $AJAX_INCLUDE */ global $AJAX_INCLUDE; if (isset($AJAX_INCLUDE)) { - \Toolbox::deprecated('The global `$AJAX_INCLUDE` variable usage is deprecated. Use "$this->setAjax()" from your controllers instead.'); - if ($this instanceof LegacyFileLoadController) { - $this->setAjax(); - } + trigger_error( + 'The global `$AJAX_INCLUDE` variable has no effect anymore.', + E_USER_WARNING + ); } /** @var string|null $SECURITY_STRATEGY */ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 3b983683fa7..f8da99fda8f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -62,9 +62,6 @@ parameters: ignoreErrors: - '~Instantiated class XHProfRuns_Default not found~' - '~Instantiation of deprecated class Glpi\\Http\\HeaderlessStreamedResponse~' - - { message: '~Variable \$this might not be defined~', paths: [ 'inc/includes.php' ] } - - { message: '~Call to protected method setAjax\(\) of class Glpi\\Controller\\LegacyFileLoadController.~', paths: [ 'ajax/*', 'front/*', 'inc/includes.php' ] } - - { message: '~Access to protected property~', paths: [ 'front/dropdown.common.form.php' ] } - { message: '~LDAP\\Connection~', reportUnmatched: false } - message: '~/(downstream\.php|config_db\.php|config_db_slave\.php)" is not a file or it does not exist.~' diff --git a/src/Glpi/Controller/LegacyFileLoadController.php b/src/Glpi/Controller/LegacyFileLoadController.php index 9117e7e9683..df383e84508 100644 --- a/src/Glpi/Controller/LegacyFileLoadController.php +++ b/src/Glpi/Controller/LegacyFileLoadController.php @@ -43,7 +43,7 @@ final class LegacyFileLoadController implements PublicService { public const REQUEST_FILE_KEY = '_glpi_file_to_load'; - protected ?Request $request = null; + private ?Request $request = null; public function __invoke(Request $request): Response { @@ -62,16 +62,14 @@ public function __invoke(Request $request): Response return new HeaderlessStreamedResponse($callback->bindTo($this, self::class)); } - protected function setAjax(): void + /** + * Method used in `front/dropdown.common.form.php` to get the current request. + * + * @phpstan-ignore method.unused + */ + private function getRequest(): Request { - $this->getRequest()->attributes->set('_glpi_ajax', true); - - \Session::setAjax(); - } - - private function getRequest(): ?Request - { - if (!$this->request) { + if ($this->request === null) { throw new \RuntimeException(\sprintf( 'Could not find Request in "%s" controller. Did you forget to call "%s"?', self::class, diff --git a/src/Glpi/Http/Listener/LegacyPostRequestActionsListener.php b/src/Glpi/Http/Listener/LegacyPostRequestActionsListener.php deleted file mode 100644 index 2342edf09f0..00000000000 --- a/src/Glpi/Http/Listener/LegacyPostRequestActionsListener.php +++ /dev/null @@ -1,53 +0,0 @@ -. - * - * --------------------------------------------------------------------- - */ - -namespace Glpi\Http\Listener; - -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\KernelEvents; - -final readonly class LegacyPostRequestActionsListener implements EventSubscriberInterface -{ - public static function getSubscribedEvents(): array - { - return [ - KernelEvents::FINISH_REQUEST => ['onFinishRequest'], - ]; - } - - public function onFinishRequest(): void - { - \Session::resetAjaxParam(); - } -} diff --git a/src/Glpi/Kernel/Kernel.php b/src/Glpi/Kernel/Kernel.php index 4d30511ac6e..991566f9532 100644 --- a/src/Glpi/Kernel/Kernel.php +++ b/src/Glpi/Kernel/Kernel.php @@ -161,7 +161,10 @@ private function triggerGlobalsDeprecation(): void */ global $AJAX_INCLUDE; if (isset($AJAX_INCLUDE)) { - \Toolbox::deprecated('The global `$AJAX_INCLUDE` variable usage is deprecated. Use "$this->setAjax()" from your controllers instead.'); + trigger_error( + 'The global `$AJAX_INCLUDE` variable has no effect anymore.', + E_USER_WARNING + ); } /** diff --git a/src/Session.php b/src/Session.php index d8889173130..ef4d276c27d 100644 --- a/src/Session.php +++ b/src/Session.php @@ -41,7 +41,6 @@ use Glpi\Exception\SessionExpiredException; use Glpi\Plugin\Hooks; use Glpi\Session\SessionInfo; -use Symfony\Component\HttpFoundation\Request; /** * Session Class @@ -53,12 +52,6 @@ class Session const TRANSLATION_MODE = 1; // no more used const DEBUG_MODE = 2; - /** - * Indicates whether the request is made in an AJAX context. - * @FIXME This flag is actually not set to true by all AJAX requests. - */ - private static bool $is_ajax_request = false; - /** * Max count of CSRF tokens to keep in session. * Prevents intensive use of forms from resulting in an excessively cumbersome session. @@ -358,9 +351,16 @@ public static function addToNavigateListItems($itemtype, $ID) **/ public static function initNavigateListItems($itemtype, $title = "", $url = null) { - if (self::$is_ajax_request === true && ($url === null)) { + /** + * @var \Symfony\Component\HttpFoundation\Request|null $request + */ + global $request; + + if ($request !== null && $request->isXmlHttpRequest() && $url === null) { + // `$request` is defined by the `/public/index.php` script. return; } + if (empty($title)) { $title = __('List'); } @@ -2352,22 +2352,6 @@ public static function getCurrentSessionInfo(): ?SessionInfo ); } - /** - * Indicates that the request is made in an AJAX context. - */ - public static function setAjax(): void - { - self::$is_ajax_request = true; - } - - /** - * Unset the flag that indicates that the request is made in an AJAX context. - */ - public static function resetAjaxParam(): void - { - self::$is_ajax_request = false; - } - public static function getCurrentProfile(): Profile { $profile_id = $_SESSION['glpiactiveprofile']['id'] ?? null;