`front/config.form.php`: `$CFG_GLPI` used without `global` (undefined variable warning, wrong redirect when GLPI is in a subdirectory)
評估
研究方向
開啟 front/config.form.php,檢查處理直接存取外掛程式設定頁面的最後一個 else 分支。在該處將 $CFG_GLPI 宣告為全域變數,接著確認重新導向使用其 root_doc 值,且不再記錄未定義變數的警告。Issue 回報此修正可在 GLPI 11.0.12 上運作;未提及測試檔案。
由索引模型根據 Issue 內容生成。
描述
GLPI Version
11.0.12 (also reproducible on 11.0.11)
Plugin version
1.4.3 — same code in 1.5.0 and on main/develop as of 2026-10-29
Bug description
The final else branch of front/config.form.php uses $CFG_GLPI without declaring it global:
} else {
Session::checkRight(Config::$rightname, READ);
/** @var array $CFG_GLPI */
Html::redirect($CFG_GLPI['root_doc'] . '/front/config.form.php?forcetab=PluginMetabaseConfig$1');
}
Since GLPI 11, legacy front/ scripts are included from inside a method (Glpi\Controller\LegacyFileLoadController::__invoke()), so they no longer run in the global scope and $CFG_GLPI is null there unless it is declared with global. The @var annotation documents the variable but does not import it.
Consequences when the plugin configuration page is opened directly (e.g. the "configure" icon in Setup > Plugins, which points to plugins/metabase/front/config.form.php):
- Two PHP warnings are written to
php-errors.logon every access (see log below). $CFG_GLPI['root_doc']evaluates tonull, so the redirect target becomes/front/config.form.php?.... This happens to work when GLPI is served at the web root, but on an instance installed in a subdirectory (for examplehttps://example.org/glpi, whereroot_docis/glpi) the browser is sent outside of GLPI and the configuration page cannot be reached from that link.
Expected: no warning, and a redirect to <root_doc>/front/config.form.php?forcetab=PluginMetabaseConfig$1.
Suggested fix (one line, same pattern used elsewhere in GLPI plugins):
} else {
Session::checkRight(Config::$rightname, READ);
/** @var array $CFG_GLPI */
+ global $CFG_GLPI;
Html::redirect($CFG_GLPI['root_doc'] . '/front/config.form.php?forcetab=PluginMetabaseConfig$1');
}
We applied exactly this change locally on a production GLPI 11.0.12 instance: the warnings disappear and the redirect lands on the Metabase configuration tab as expected.
Relevant log output
[2026-10-29 15:38:22] glpi.WARNING: *** Warning: Undefined variable $CFG_GLPI at config.form.php line 51
Backtrace :
./marketplace/metabase/front/config.form.php:51
...Glpi/Controller/LegacyFileLoadController.php:64 require()
./vendor/symfony/http-kernel/HttpKernel.php:181 Glpi\Controller\LegacyFileLoadController->__invoke()
./vendor/symfony/http-kernel/HttpKernel.php:76 Symfony\Component\HttpKernel\HttpKernel->handleRaw()
./vendor/symfony/http-kernel/Kernel.php:208 Symfony\Component\HttpKernel\HttpKernel->handle()
[2026-10-29 15:38:22] glpi.WARNING: *** Warning: Trying to access array offset on value of type null at config.form.php line 51
Page URL
/plugins/metabase/front/config.form.php (no parameters)
Steps To reproduce
- Install and enable the Metabase plugin on GLPI 11.
- Log in as a user with
configREAD right. - Open
plugins/metabase/front/config.form.phpdirectly (or click the plugin's configure icon in Setup > Plugins). - Check
files/_log/php-errors.log: the two warnings above are logged. - On an instance where GLPI is installed in a subdirectory, observe that the redirect goes to
/front/config.form.php(outside of the GLPI path) instead of<root_doc>/front/config.form.php.
Your GLPI setup information
- PHP 8.2.35, Apache 2.4 (mod_php), Debian 12
- MariaDB 10.11.19
- GLPI installed at the web root (
root_docempty), so only the warnings are visible on our side; the wrong redirect follows from the code for subdirectory installs.
- 主要語言
- PHP
- 星號
- 17
- 分支
- 12
- 平均合併
- 1 小時 47 分鐘
- 30 天內合併 PR
- 5
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
pluginsGLPI/metabase 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 48/100
pluginsGLPI/metabase#171 · 1 則留言 ·
查看 pluginsGLPI/metabase 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
-
難度 1/5 1 小時以內 新手友好度 82/100
-
35-feedback
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 82/100
pluginsGLPI/carbon#396 ·