Exporting the IP addressing report (from an addressing network's form) fails with HTTP 500 and the generic "An unexpected error occurred" message. The plugin itself works fine otherwise.

未关闭 适合新手
#132 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
backend

调研方向

阅读 src/Report.php,尤其是列定义附近的 displayExport(),并追踪报告中的调用到 GLPI 的 Spreadsheet::formatValue()。在 GLPI 12.0.2 中使用寻址网络表单重现导出,并检查传递给电子表格输出的单元格值。完成的标准是以所列格式导出时不再引发数组绑定错误。

由索引模型根据 Issue 内容生成。

描述

Code of Conduct
  • I agree to follow this project's Code of Conduct
Is there an existing issue for this?
  • I have searched the existing issues
GLPI Version

12.0.2

Plugin version

3.3.1

Bug description

Steps to reproduce

  1. Go to Tools > IP Addressing and open a network (e.g. addressing.form.php?id=2)
  2. Choose any export format (e.g. PDF landscape) and start the export
  3. → HTTP 500, "An unexpected error occurred"

Request:

GET /front/report.dynamic.php?item_type=GlpiPlugin%5CAddressing%5CReport&id=2&ping_on=1&ping_off=1&filter=0&seeallotedip=1&seedoubleip=1&seereservedip=1&seefreeip=1&start=0&display_type=2&export=

Expected behavior

The report is exported in the selected format.

Actual behavior

glpi.CRITICAL: *** Uncaught PHP Exception PhpOffice\PhpSpreadsheet\Exception: "Unable to bind unstringable array" at DefaultValueBinder.php line 43
Backtrace :
...c/PhpSpreadsheet/Cell/DefaultValueBinder.php:43
...preadsheet/src/PhpSpreadsheet/Cell/Cell.php:252          PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder->bindValue()
...src/PhpSpreadsheet/Worksheet/Worksheet.php:1219          PhpOffice\PhpSpreadsheet\Cell\Cell->setValue()
./src/Glpi/Search/Output/Spreadsheet.php:596                PhpOffice\PhpSpreadsheet\Worksheet\Worksheet->setCellValue()
./src/Glpi/Search/Output/Spreadsheet.php:151                Glpi\Search\Output\Spreadsheet->formatValue()
.../glpi/marketplace/addressing/src/Report.php:451          Glpi\Search\Output\Spreadsheet->displayData()
.../glpi/marketplace/addressing/src/Report.php:113          GlpiPlugin\Addressing\Report::displayExport()
/var/glpi/marketplace/addressing/hook.php:444               GlpiPlugin\Addressing\Report->displayReport()
./src/Plugin.php:1913                                       plugin_addressing_dynamicReport()
./front/report.dynamic.php:116                              Plugin::doOneHook()
...Glpi/Controller/LegacyFileLoadController.php:64          require()
...
./public/index.php:78                                       Glpi\Kernel\Kernel->handle()

Root cause

In GLPI 12, Glpi\Search\Output\Spreadsheet::formatValue() only unwraps a cell array (['displayname' => ...]) when the column options contain a searchopt key:

if (is_array($value) && isset($options['searchopt'])) {
    ...
    $value = DataExport::normalizeValueForTextExport($value['displayname'] ?? '');
}
$worksheet->setCellValue([$x_coordinate, $y_coordinate], $value);

Report::displayExport() builds its column definitions without searchopt, so the whole cell array is passed to setCellValue(), which throws Unable to bind unstringable array. As GLPI 12 handles all non-HTML outputs via Spreadsheet, this affects every export format (PDF, CSV, ODS, XLSX).

Proposed fix

In src/Report.php, displayExport():

         $colid = 0;
         foreach ($headers as $header) {
             $addressing_data['data']['cols'][] = [
-                'name'     => $header,
-                'itemtype' => $itemtype,
-                'id'       => ++$colid,
+                'name'      => $header,
+                'itemtype'  => $itemtype,
+                'id'        => ++$colid,
+                // Spreadsheet::formatValue() only unwraps the cell array
+                // (['displayname' => ...]) when a search option is given.
+                'searchopt' => ['datatype' => 'string'],
             ];
         }

Using datatype => 'string' avoids the date formatting branch and lets normalizeValueForTextExport() decode the escaped displayname, as displayExport() already expects.

Tested on GLPI 12.0.2: export works again with this change.

Relevant log output

Page URL

No response

Steps To reproduce

No response

Your GLPI setup information

No response

Anything else?

No response

主要语言
PHP
星标
43
派生
24
平均合并
6 小时 30 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pluginsGLPI/addressing 的其他 Issue

查看 pluginsGLPI/addressing 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。