Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 14, 2024

Conversation

cleacos
Copy link
Contributor

@cleacos cleacos commented May 9, 2024

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 Issues about the Jetpack CRM plugin [Status] In Progress labels May 9, 2024
Copy link
Contributor

github-actions bot commented May 9, 2024

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
@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label May 13, 2024
@cleacos cleacos removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label May 13, 2024
@gogdzl
Copy link
Contributor

gogdzl commented May 13, 2024

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

image

@cleacos
Copy link
Contributor Author

cleacos commented May 13, 2024

@gogdzl
Copy link
Contributor

gogdzl commented May 13, 2024

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
Copy link
Contributor

gogdzl commented May 13, 2024

image

image

@gogdzl
Copy link
Contributor

gogdzl commented May 13, 2024

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

Copy link
Contributor

@gogdzl gogdzl left a comment

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
58 of 59 checks passed
@cleacos cleacos deleted the fix/3459-crm-pdf-invoice-logo-not-found branch May 14, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] CRM Issues about the Jetpack CRM plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants