Skip to content

CRM: PDF invoice logo - image not found issue. Set the tmp folder and don't add protocols - #37311

Merged
cleacos merged 3 commits into
trunkfrom
fix/3459-crm-pdf-invoice-logo-not-found
May 14, 2024
Merged

cleacos merged 3 commits into
trunkfrom
fix/3459-crm-pdf-invoice-logo-not-found

Conversation

@cleacos

@cleacos cleacos commented May 9, 2024 •

Copy link
Copy Markdown
Contributor

Fixes https://github.com/Automattic/zero-bs-crm/issues/3459

Proposed changes:

This PR fixes our issue with the PDF invoices for rendering the logo. I've been investigating it for a while, and really, there were two issues;

The main one was a method introduced to check the remote link, but it was not working well because many sites use CDN to cache their assets, including images, which implies that the logo image has a different domain or subdomain.

The other issue was about the temporary folder to download that remote file locally and to be able the DomPdf to generate the PDF correctly. In some servers, the temporary folder is not writable, so we usually have an issue there. To fix this, we set the temporary folder inside of the JPCRM storage folder, in the wp-content folder to ensure we have a writable .temporary folder.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

N/A

Does this pull request change what data or activity we track or use?

N/A

Testing instructions:

  • In a JPCRM site, go to the settings and set Your Business Logo: to an external image link.
  • Create an invoice.
  • Generate the PDF.
  • In trunk, you will see the error, image not found with a white box.
  • In this PR, you will see the logo you selected.

@cleacos cleacos self-assigned this May 9, 2024
@github-actions github-actions Bot added [Plugin] CRM Moved to https://github.com/Automattic/jetpack-crm [Status] In Progress labels May 9, 2024
@github-actions

github-actions Bot commented May 9, 2024 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

@cleacos cleacos changed the title Fix/3459 crm pdf invoice logo not found CRM: PDF invoice logo - image not found issue. Set the tmp folder and don't add protocols May 9, 2024
@cleacos
cleacos requested a review from a team May 13, 2024 07:30
@cleacos
cleacos marked this pull request as ready for review May 13, 2024 07:31
@gogdzl gogdzl added this to the crm/6.4.3 milestone May 13, 2024
@cleacos cleacos added [Status] Needs Team Review Obsolete. Use Needs Review instead. and removed [Status] In Progress labels May 13, 2024
@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 13, 2024
@cleacos cleacos removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 13, 2024
@gogdzl

gogdzl commented May 13, 2024

Copy link
Copy Markdown
Contributor

Do you have any further testing instructions? I still can't see the logo:

image

@cleacos

cleacos commented May 13, 2024

Copy link
Copy Markdown
Contributor Author

@gogdzl

gogdzl commented May 13, 2024 •

Copy link
Copy Markdown
Contributor

Not related to this PR, but ran into this problem:

Fatal error: Uncaught ImagickException: NoDecodeDelegateForThisImageFormat `PNG' @ error/constitute.c/ReadImage/741 in /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/lib/Cpdf.php:5709 Stack trace: #0 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/lib/Cpdf.php(5709): Imagick->__construct('/home/lo...') #1 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/lib/Cpdf.php(5845): Dompdf\Cpdf->addImagePngAlpha('/home/lo...', 49.015748031496, 759.5434024688, 149.1745511811, 33.330849499708, 6) #2 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Adapter/CPDF.php(669): Dompdf\Cpdf->addPngFromFile('/home/lo...', 49.015748031496, 759.5434024688, 149.1745511811, 33.330849499708) #3 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer/Image.php(65): Dompdf\Adapter\CPDF->image('/home/lo...', 49.015748031496, 49.015748031496, 149.1745511811, 33.330849499708, 'normal') #4 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer.php(289): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\Image)) #5 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer.php(128): Dompdf\Renderer->_render_frame('image', Object(Dompdf\FrameDecorator\Image)) #6 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer.php(195): Dompdf\Renderer->render(Object(Dompdf\FrameDecorator\Image)) #7 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer.php(195): Dompdf\Renderer->render(Object(Dompdf\FrameDecorator\Block)) #8 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer.php(195): Dompdf\Renderer->render(Object(Dompdf\FrameDecorator\Block)) #9 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer.php(195): Dompdf\Renderer->render(Object(Dompdf\FrameDecorator\Block)) #10 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Renderer.php(195): Dompdf\Renderer->render(Object(Dompdf\FrameDecorator\Block)) #11 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/FrameReflower/Page.php(149): Dompdf\Renderer->render(Object(Dompdf\FrameDecorator\Block)) #12 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(913): Dompdf\FrameReflower\Page->reflow(NULL) #13 /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/src/Dompdf.php(765): Dompdf\FrameDecorator\AbstractFrameDecorator->reflow() #14 /home/dsk/git/avengers/jetpack/projects/plugins/crm/includes/ZeroBSCRM.GeneralFuncs.php(1621): Dompdf\Dompdf->render() #15 /home/dsk/git/avengers/jetpack/projects/plugins/crm/includes/ZeroBSCRM.InvoiceBuilder.php(308): jpcrm_generate_pdf('<!DOCTYPE html>...', 'invoice-3.pdf') #16 /home/dsk/git/avengers/jetpack/projects/plugins/crm/includes/ZeroBSCRM.InvoiceBuilder.php(250): jpcrm_invoice_generate_pdf('3') #17 /home/localwp/crmno1/app/public/wp-includes/class-wp-hook.php(324): zbs_invoice_generate_pdf('') #18 /home/localwp/crmno1/app/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #19 /home/localwp/crmno1/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #20 /home/dsk/git/avengers/jetpack/projects/plugins/crm/includes/ZeroBSCRM.Core.php(1811): do_action('zerobscrm_post_...') #21 /home/localwp/crmno1/app/public/wp-includes/class-wp-hook.php(324): ZeroBSCRM->init('') #22 /home/localwp/crmno1/app/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #23 /home/localwp/crmno1/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #24 /home/localwp/crmno1/app/public/wp-settings.php(695): do_action('init') #25 /home/localwp/crmno1/app/public/wp-config.php(103): require_once('/home/lo...') #26 /home/localwp/crmno1/app/public/wp-load.php(50): require_once('/home/lo...') #27 /home/localwp/crmno1/app/public/wp-admin/admin.php(34): require_once('/home/lo...') #28 {main} thrown in /home/dsk/git/avengers/jetpack/projects/plugins/crm/vendor/dompdf/dompdf/lib/Cpdf.php on line 5709
There has been a critical error on this website. Please check your site admin email inbox for instructions.

@gogdzl

gogdzl commented May 13, 2024

Copy link
Copy Markdown
Contributor

image

image

@gogdzl

gogdzl commented May 13, 2024

Copy link
Copy Markdown
Contributor

The thing I wasn't getting right is that this applies only to new invoices; all old ones won't get the new logo.

@gogdzl gogdzl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@cleacos
cleacos merged commit 0276389 into trunk May 14, 2024
@cleacos
cleacos deleted the fix/3459-crm-pdf-invoice-logo-not-found branch May 14, 2024 13:11
@github-actions github-actions Bot removed the [Status] Needs Team Review Obsolete. Use Needs Review instead. label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] CRM Moved to https://github.com/Automattic/jetpack-crm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants