Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
file system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Jul 2013 at 23:04 UTC
Updated:
29 Jul 2014 at 22:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
quicksketchCould you describe what you mean by "UUID not added"? I think what you mean is that the UUID is not accessible via the return values of a manage_file element. All you're given is the FID. However I think if you need the UUID, you can still obtain it by loading the entity for the file and then checking $file->uuid. I definitely see where you're coming from that I would expect file_managed to give you UUIDs instead of FIDs, but given the FID you should be able to get the UUID even though it's not provided directly.
Comment #2
nirbhasa commentedI meant that the uuid value is NULL in the file_managed table after the file has been uploaded.
Comment #3
quicksketchOh. Dang well that's a big problem. :)
I'm looking into #1932652: Add image uploading to WYSIWYGs through editor.module right now (where this problem was discovered). I'll get into providing some actually useful code shortly.
Comment #4
quicksketchWell, this problem is beyond my skill level. I have no idea why the UUID isn't getting created. file_save_upload() creates the original $file variable with entity_create() just like everywhere else we have new entities, but for some reason the UUID isn't getting generated (apparently). Since you can not currently dpm() or debug() any entity variables, I can't tell what's going on in here. Such is D8. :P
Comment #5
berdirFileStorageController:baseFieldDefinitions() defines uuid as a string_field. That must be uuid_field, as that references the UuidItem class, which implements applyDefault(), which is the place where the default UUID is created.
The issue that changed this went in more or less in parallel with file ng conversion, that's why we missed it. Looks like we need test coverage there, shouldn't be too complicated.
@quicksketch: try debug($entity->getPropertyValues()) (weird name, I know). Also, PHP 5.4 is much better at that, it throws out some warnings, but doesn't go into an endless loop anymore.
Comment #6
quicksketchThanks @Berdir, you're spot-on. It's a one-line change to fix this problem. Tests should be trivial to write too.
Comment #7
berdirAs mentioned to @larowlan yesterday, we really need to update the UUID change notice, still mentiones hook_entity_info(), and we should document the differences between config entities and content/NG entities: https://drupal.org/node/1721572
Comment #8
quicksketchHere's a patch which fixes the problem and provides new tests, but for some reason the new test isn't passing on my local. We'll see if testbot thinks differently.
Comment #10
quicksketchWe must have a bigger problem here. This trivial bit of code fails:
Seems like entity_load_by_uuid() doesn't work within the same request for some reason. The UUID is definitely now getting created, but we can't load an entity by it. Very strange.
Comment #11
larowlan$this->createFile writes the record to file_managed direct, so it doesn't go through the normal hooks and the uuid isn't autocreated.
Added a $file->save() to trigger the full stack/write.
And then a file_test_reset(); to reset the load hooks.
Works for me locally™
Comment #12
tim.plunkettTwo insignificant nitpicks, but when you repost can you provide a test-only patch so we can see it fail? Thanks!
Loads
Can you add a blank line after the end of the method please?
Comment #13
larowlanDonesky
Comment #14
larowlanfail/pass
Comment #15
tim.plunkettIf #14 is red+green, RTBC.
Comment #16
alexpottCommitted 337b370 and pushed to 8.x. Thanks!