https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44086 --- Comment #2 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 211531 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211531&action=edit Bug 44086: Restore the previously selected filehandle in Koha::Exporter::Record::export When output_filepath is passed, export() opens the file and selects it, so that the internal prints without an explicit filehandle go to the file. The file is closed at the end, but the previously selected filehandle (usually STDOUT) is never restored. Any later print without a filehandle in the calling code then fails with "print() on closed filehandle $fh", and its output is lost. The same happened when export() died because of an invalid csv profile: the check ran after the file had been selected, so the selected filehandle stayed on the export file. This patch saves the selected filehandle before selecting the output file and restores it after closing it. The csv profile check is moved before opening the file, so an invalid profile no longer changes the selected filehandle or leaves an empty file behind. Core callers are not affected today: tools/export.pl prints to STDOUT and misc/export_records.pl redirects STDOUT instead of passing output_filepath. Any script or plugin that passes output_filepath and prints anything afterwards is. Steps to follow: 1. Run this from the Koha root (in KTD, as the koha user, e.g. inside koha-shell): perl -we 'use Koha::Exporter::Record; Koha::Exporter::Record::export({ record_type => "bibs", record_ids => [1], format => "xml", output_filepath => "/tmp/export.xml" }); print "Export finished\n";' 2. Note the warning "print() on closed filehandle $fh" and that "Export finished" is not printed. /tmp/export.xml is written. 3. Apply this patch. 4. Run the same command again. 5. Note that "Export finished" is printed, with no warning, and that /tmp/export.xml is still written. 6. prove t/db_dependent/Exporter/Record.t -- You are receiving this mail because: You are watching all bug changes.