jalendport / craft-preparse

Field type that parses twig when an element is saved.
MIT License
108 stars 23 forks source link

Image Transform Issue #53

Open rogertinch opened 5 years ago

rogertinch commented 5 years ago

Does running an image transform inside of a Preparse Field work any differently to running it in a template? I'm encountering this issue when saving an entry that has a Preparse Field that applies a transform to an assets field:

yii\base\ErrorException: fopen(/srv/app/prod-crafthouse/htdocs/storage/runtime/assets/tempuploads/user_1/running-with-beto.jpg): failed to open stream: No such file or directory in /srv/app/prod-crafthouse/htdocs/vendor/league/flysystem/src/Adapter/Local.php:181

aelvan commented 5 years ago

Well, that depends.. From the error message, it looks like the Asset has not been created yet, it's trying to transform an image in the tempuploads folder. Is the preparse field on the Asset or the Entry? Have you set up the field to parse before or after save? Is it a multi-site install?

rogertinch commented 5 years ago

The preparse field is on the entry and the field is set to parse after save. It is not part of a multi-site install, but it is on fortrabbit's Pro Stack which doesn't have file storage.

In talking to fortrabbit they said that transforms in templates work fine on their Pro Stack, which points to Preparse Field maybe doing something different with the file before and after transforming?

rogertinch commented 5 years ago

Oh, and here is what I have in the field:

{% spaceless %}
{% if element.heroImage | length %}
  {% set heroImage = element.heroImage.one() %}
  {{ heroImage.getUrl('landscape') }}
{% endif %}
{% endspaceless %}

This was working fine on their Uni Stack which has file storage.

aelvan commented 5 years ago

I've tested in my test environments, and the setup you're describing works there.

The only thing Preparse Field maybe do differently, is changing the config setting generateTransformsBeforePageLoad to true before parsing the twig. Not sure how fortrabbit have adapted their platform to get the local copy of the files if there's no file system, but maybe that has something to do with it. Maybe they rely on the transform happening as a queue task?

Just as a test, try to set up the preparse field to parse before save (in the field settings). Does that change anything?

Also, what PHP-version are you using? Also, you get that error when you try to save? Or is it in your logs afterwards?

rogertinch commented 5 years ago

Setting it to preparse before save did not fix the issue. I reached out to fortrabbit again along with note about they're handing local copies of the files on their Pro Stack.