CampTix Invoices: Don't record the invoice PDF when generation fails - #1761
Open
wputasic wants to merge 1 commit into
Open
CampTix Invoices: Don't record the invoice PDF when generation fails#1761wputasic wants to merge 1 commit into
wputasic wants to merge 1 commit into
Conversation
create_invoice_document() wrote the invoice_document meta unconditionally, so a wkhtmltopdf failure left the invoice pointing at a file that was never written: the download button 404s and send_invoice() attaches a missing file. Bail out and log via $camptix->log() unless the generated PDF exists, is non-empty, and was moved into uploads/camptix-invoices successfully. Fixes WordPress#1760.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1760.
Problem
create_invoice_document()records theinvoice_documentpost meta unconditionally.WordCamp_Docs_PDF_Generatorrunsexec( 'wkhtmltopdf ...' )with no error checking and returns the target path either way, and therename()return value is ignored — so when PDF generation fails, the invoice still ends up pointing at a file that was never written. The "Download invoice" button then 404s,send_invoice()attaches a missing file, and nothing is logged anywhere organizers or support can see. This happened network-wide when wkhtmltopdf was temporarily unavailable on production in July 2026.Fix
Only record the document once the PDF verifiably exists:
$camptix->log()if the generated file is missing or zero bytes;rename()intouploads/camptix-invoices/fails;invoice_documentmeta.Both callers ignore the function's return value, so the early
return falserequires no caller changes, and the sharedWordCamp_Docs_PDF_Generatorclass is untouched. Invoices that hit the guard can be regenerated later simply by re-saving (thesave_posthandler already regenerates, reusing the stored filename when present).Testing
Verified in the local Docker environment (multisite, camptix-invoices active):
create_invoice_document()returnsfalse, noinvoice_documentmeta is written, and the expected log entry (message + filename) appears in the CampTix network log via camptix-network-tools. On the unpatched code the same scenario writes meta pointing at a nonexistent PDF — reproducing the July incident.uploads/camptix-invoices/, and the meta is written exactly as before.