Skip to content

fix: move ODT source unlink before download block to ensure cleanup on exception#38936

Open
support-accellier wants to merge 4 commits into
Dolibarr:developfrom
support-accellier:fix/38930-odf-unlink-order
Open

fix: move ODT source unlink before download block to ensure cleanup on exception#38936
support-accellier wants to merge 4 commits into
Dolibarr:developfrom
support-accellier:fix/38930-odf-unlink-order

Conversation

@support-accellier

Copy link
Copy Markdown
Contributor

Summary

Moves the unlink($name) call (controlled by MAIN_ODT_AS_PDF_DEL_SOURCE) to before the $dooutputfordownload block in odf.php::exportAsAttachedPDF().

Previously, if headers_sent() caused an OdfException to be thrown inside the download block, the unlink() was never reached and the .odt source file remained on disk despite MAIN_ODT_AS_PDF_DEL_SOURCE being enabled. The PDF conversion is already complete at this point, so deleting the ODT source before attempting the download is safe and ensures cleanup always happens.

Fixes #38930


if ($dooutputfordownload) {
if (php_sapi_name() != 'cli') { // If we are in a web context (not into CLI context)
if (headers_sent($filename, $linenum)) {

@eldy eldy Jun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a header was sent, it means we got a problem into odt to pdf conversion. In such a case, we would like to keep the odt file, so we can analyze it, to try to reproduce to problem with the source file.

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Discussion Some questions or discussions are opened and wait answers of author or other people to be processed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ODT→PDF export — ODT source file not deleted when MAIN_ODT_AS_PDF_DEL_SOURCE is set as 1

2 participants