dotmailer / dotmailer-magento2-extension

The official Dotdigital for Magento2 extension
https://dotdigital.com/integrations/magento
MIT License
48 stars 63 forks source link

gzuncompress data error when saving design configuration #568

Closed ghost closed 3 years ago

ghost commented 3 years ago

When trying to set a new Default Theme for the Global scope in Content > Design > Configuration, this error shows:

Something went wrong while saving this configuration: Warning: gzuncompress(): data error in /var/www/magento2/vendor/dotmailer/dotmailer-magento2-extension/Plugin/TemplatePlugin.php on line 164

This is on Magento 2.3.5-p2, with Dotmailer 4.4.0 (installed with Magento)

sta1r commented 3 years ago

@paul-gene Thanks, we'll take a look.

sta1r commented 3 years ago

Hi - We were able to replicate the issue, but only by removing the @ operator on L164. We're using this when checking if the supplied HTML is compressed or not - if there's an error the error should be suppressed and the method returns false.

What version of PHP are you running please?

ghost commented 3 years ago

I'm running PHP 7.3.

But, it looks like it was my xdebug settings (scream) that meant the @ error suppressor was being ignored.

With that said, usage of @ isn't ideal anyway.

sta1r commented 3 years ago

Ah that's actually good intel re xdebug. I was seeing the error in a different context and wondering why.

Yes we'd much prefer a try catch but gzuncompress doesn't throw an exception.

Previous to using @gzuncompress we had:

if (substr($string, 0, 1) == 'e' && substr_count($string, ' ') == 0) {
    return true;
}

return false;

but this was returning false positives in some cases.

If you know of a better way we'd happily check it out! 👍

ghost commented 3 years ago

@sta1r have you considered using this work around? https://www.php.net/manual/en/function.gzuncompress.php#79042

Alternatively, don't use gzcompress/gzuncompress?

sta1r commented 3 years ago

I think that's a workaround for cases where you are ingesting compressed strings that you didn't originally compress yourself - we'd be confident that any compressed template strings would have been compressed by us initially.

We know for sure that campaigns can exceed 64kb in size (mysql's limit for TEXT columns), so we do need some solution for compressing the HTML.