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.

Đang mở Phù hợp với người mới
#132 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend

Hướng nghiên cứu

Đọc src/Report.php, đặc biệt là displayExport() ở phần định nghĩa cột, và lần theo lệnh gọi được báo cáo đến Spreadsheet::formatValue() của GLPI. Tái hiện thao tác xuất trong GLPI 12.0.2 bằng biểu mẫu mạng định địa chỉ và kiểm tra các giá trị ô được truyền vào đầu ra bảng tính. Hoàn thành khi xuất ở các định dạng được liệt kê không còn gây ra lỗi liên kết mảng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
PHP
Star
43
Fork
24
Merge trung bình
6 giờ 30 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pluginsGLPI/addressing

Tất cả issue của pluginsGLPI/addressing

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.