mdjnelson / moodle-mod_customcert

Enables the creation of dynamically generated certificates with complete customisation via the web browser.
https://moodle.org/plugins/mod_customcert
GNU General Public License v3.0
89 stars 157 forks source link

Exception - TCPDF ERROR when mod/customcert/edit.php 'Save changes and preview' AND debugging NOTICES on #558

Closed x-iy closed 1 year ago

x-iy commented 1 year ago

With debugging on, receive following error when trying to preview edited template:

Exception - TCPDF ERROR: Some data has already been output, can't send PDF file
More information about this error
    Debug info:  
Error code: generalexceptionmessage    
    Stack trace:  
line 3007 of /lib/tcpdf/tcpdf.php: Exception thrown
line 7698 of /lib/tcpdf/tcpdf.php: call to TCPDF->Error()
line 190 of /lib/pdflib.php: call to TCPDF->Output()
line 348 of /mod/customcert/classes/template.php: call to pdf->Output()
line 232 of /mod/customcert/edit.php: call to mod_customcert\template->generate_pdf()        

Output buffer:  <br /> <b>Notice</b>:  Trying to get property 'language' of non-object in <b>/var/www/xxxxxx/mod/customcert/classes/template.php</b> on line <b>275</b><br /> <br /> <b>Notice</b>:  Trying to get property 'language' of non-object in <b>/var/www/xxxxxx/mod/customcert/classes/template.php</b> on line <b>335</b><br />      

In this situation, $customcert = FALSE as id doesn't exist therefore $customcert->language is property of non-object and Notice created for display.

Suggested fix: check existence of $customcert->language beforehand in classes/template.php lines 275 and 335

With debugging off, no exception occurs.

mdjnelson commented 1 year ago

Thanks! This was fixed in https://github.com/mdjnelson/moodle-mod_customcert/commit/a851ff6c048b95ebbba051485aa2b482b9977e97. :)

x-iy commented 1 year ago

Hi Mark, Sorry for not being clear, but this is a separate issue to the one you mention as fixed.

This issue only occurs when:

The issue doesn't occur when editing from a course activity.

I will create an MR with my suggested fix / workaround.

mdjnelson commented 1 year ago

Thanks. I was able to replicate this, thanks for the PR. Ill comment over there.