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.

Aperta Adatta ai principianti
#132 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Leggi src/Report.php, in particolare displayExport() nella sezione delle definizioni delle colonne, e segui la chiamata segnalata fino a Spreadsheet::formatValue() di GLPI. Riproduci l’esportazione in GLPI 12.0.2 usando il modulo della rete di indirizzamento e controlla i valori delle celle passati all’output del foglio di calcolo. Il lavoro è completato quando l’esportazione nei formati elencati non genera più l’errore di binding dell’array.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
PHP
Stelle
43
Fork
24
Merge medio
6h 30m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pluginsGLPI/addressing

Tutte le issue di pluginsGLPI/addressing

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.