If your getTarget is not reentrant and there is no for it to be then the calling chain is this:

  1. Image field formatter
  2. theme_image_style
  3. image_style_url
  4. image_style_path
  5. file_uri_target
  6. getTarget
  7. Output of getTarget gets into the image/generate URL
  8. image_style_generate
  9. image_style_path but with the URI already got back from getTarget. This is the feedback loop of death.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

Status: Active » Needs review
FileSize
694 bytes

So when i have converted the file system to a flexible one, well, THIS one wanted the original file_uri_target...

chx’s picture

Here is a more understandable example of what happens. If you have something like flickr://chx/4781325384/ which would serve the picture at http://www.flickr.com/photos/chx/4781325384/ then image style generate would create a URL like image/generate/large/flickr/www.flickr.com/photos/chx/4781325384/ instead of image/generate/large/flickr/chx/4781325384. And the flickr stream wrapper would get flickr://www.flickr.com/photos/chx/4781325384 and it would not know what the heck is on.

chx’s picture

Priority: Critical » Normal

Hm, sorry, this does not break core.

chx’s picture

Priority: Normal » Major

But we have a shiny new major priority. Good!

drewish’s picture

subscribe

Damien Tournoud’s picture

I am *very* confused as of what file_uri_target() is actually supposed to do (transform an URI... into what?)...

Damien Tournoud’s picture

Title: Image generate is not working with flexible wrappers » file_uri_target() purpose is unclear
FileSize
4.78 KB

So it seems that file_uri_target() is actually just designed to return the part of the URI after the '://' (while keeping it URL-encoded). As a consequence, the current implementation looks correct.

But file_uri_target() feels completely foobar right now. I guess we need something like this.

Status: Needs review » Needs work

The last submitted patch, 858528-file-uri-target-foobar.patch, failed testing.

chx’s picture

Damien, this is a gem. In an issue about something being unclear you said:

It seems that file_uri_target() [...] current implementation looks correct.

But file_uri_target() feels completely foobar right now.

:D

Your patch would revert what I did with file_uri_target. You can be right. Returning a locally writeable file path indeed more belongs to the local class than the generic interface. However we can not remove getTarget from there because if you want to extend that (nee hash_target) you simply can't.

andypost’s picture

I think flickr is not a good example because this kind of field should have own formatter and does not correlate with image field at all

aaron’s picture

subscribe. and don't forget that image != imagefield, and with stream wrappers there's no technical reason that image couldn't work on remote images.

chx’s picture

Status: Needs work » Needs review
FileSize
2.77 KB

It seems drewish, Damien and I are all agreed on this patch.

  1. file_uri_target just separates out the part after the schema. It walks hand-in-hand with file_uri_schema.
  2. Yet, getTarget is useful but pertains to the local wrapper.
chx’s picture

FileSize
2.79 KB

eh i moved too much. there is already a getTarget in local.

drewish’s picture

This seems like the sanest way out of the mess we've made.

Damien Tournoud’s picture

Status: Needs review » Reviewed & tested by the community

This looks very good to me. It's probably not the only modification we need to make to the stream wrappers, but it's a good first step.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, targeted.patch, failed testing.

aaron’s picture

Status: Needs work » Needs review

i was going to test out an example or two, but remembered that, unfortunately, the stream wrapper implementation is still a bit broken, as we can't file_copy from an external stream, because file_exists returns FALSE for streams (which is called against the source uri in file_unmanaged_copy). thus, we have to use a raw copy() as in http://drupalcode.org/viewvc/drupal/contributions/modules/media/media.mo....

thus, i have no real way of knowing if this approach is sound or not, as the only place where it's going to even matter is for local file systems. boo.

aaron’s picture

Status: Needs review » Needs work

setting status back.

rfay’s picture

subscribe

Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
3.13 KB
chx’s picture

Status: Needs review » Reviewed & tested by the community

Given drewish's comment I think we are good to go. (Damien's patch does not change the approach, i ran an interdiff, it just fixes a braino.)

Dries’s picture

I believe pwolanin wrote a lot of this code so I'd like him to give it a thumbs up.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs work

Looks like this is reverting basically back to what we had earlier, so it seems fine to me.

One comment - why use substr() when elsewhere we do this:

function file_uri_scheme($uri) {
  $data = explode('://', $uri, 2);

  return count($data) == 2 ? $data[0] : FALSE;
}

We should be consistent, so CNW to make this code match more like:

function file_uri_target($uri) {
  $data = explode('://', $uri, 2);

  if (count($data) == 2) {
    return trim($data[1], '\\/');
  }
  return FALSE;
}
Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
3.1 KB

Rerolled, your honor.

Damien Tournoud’s picture

FileSize
3.1 KB

Matching the logic.

pwolanin’s picture

[edit] new patch fixes the problem

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

The logic in question is returning FALSE on failure, as the function did before.

This looks ok to me now.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.