Closed (fixed)
Project:
Phone
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
8 Apr 2013 at 16:50 UTC
Updated:
24 Apr 2013 at 20:40 UTC
Jump to comment: Most recent file
When saving a user entity with user_save and with a phone field defined, phone_field_presave() tries to call phone_libphonenumber_clean() which is defined in phone.libphonenumber.inc and not yet loaded.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | phone-libphonenumber-unit-test-1964670-10.patch | 1.54 KB | cdale |
| #9 | 1964670_9-fix-library-loading.patch | 942 bytes | cweagans |
| #1 | 1964670.patch | 516 bytes | sylvain lecoy |
Comments
Comment #1
sylvain lecoy commentedThis patch fix it.
Comment #2
sylvain lecoy commentedSorry you have to add:
module_load_include('inc', 'phone', 'includes/phone.libphonenumber');
instead of
module_load_include('inc', 'phone', 'phone.libphonenumber');
Comment #3
cdale commentedThis is incorrect.
the phone_libphonenumber() call should take care of loading up the required include files via the libraries module.
If this file is not loaded, then something else has gone wrong somewhere, and I'd much rather try and track that issue down.
Do you have steps to replicate this from a clean D7 install with just phone and libraries enabled?
Comment #4
sylvain lecoy commentedYes, put this in a unit test:
Of course you might also create a field type phone called 'phone' on the 'user' entity.
And you are right because I get another problem which is: can't load libphonenumber/PhoneNumberUtil.
Comment #5
sylvain lecoy commentedComment #6
cdale commentedI've tried to replicate this, but cannot. I've added a phone field to the user entity, created a new user, saved/updated an existing user, I even deleted an account, all worked fine and as expected.
Have you tried with the latest 7.x-2.x branch and the latest libphonenumber code?
Comment #7
sylvain lecoy commentedAre you reproducing the code via the Drupal UI ? Because with the drupal UI and user form editing it works.
Reproduce the step using the user_save() function. I gave you a sample of a Unit Test function, do you want a full class to execute ?
Yes I use the -dev version.
Comment #8
sylvain lecoy commentedIt is not loading the library because:
In a testing context, the module is installed and then executed in the same thread.
The function phone_libphonenumber() caches a boolean value called $success which remains true once checkings are done at module installation (e.g. with libraries_detect() function).
Thus, when calling again the phone_libphonenumber() function in the phone_field_presave function on user_save(), $success is already set to TRUE and the loading of php files never happen.
To resolve the problem I had to write these lines of code in save() method of the user controller:
This work-around fixed my test case.
To reproduce the steps, I guess you just call phone_libphonenumber(TRUE) once somewhere in your code, then calling phone_libphonenumber() wont load the library.
This is easily fixable by changing the way this function works, and cache another static variable which indicates whether or not the library has been loaded.
Comment #9
cweagansSomething like this?
Comment #10
cdale commentedAhh, I didn't click that is was not through the UI, and that is was being run by unit tests.
The patch in #9 won't work, as it will trigger a hook_requirements error I think as $library['loaded'] is only true after libraries_load I believe.
A better approach is not to statically cache the success call for detect only.
Something like the following?
Comment #11
sylvain lecoy commentedIt not only break unit test, but possibly a client request which first checks if the library exists (with detect) before loading it.
The patch in #10 is working for me.
Comment #12
cweagansLooks good to me too. Committed and pushed to 7.x-2.x.