First it fails in user_service_save_access, then after explicitly casting to array, it fails again in user_service_save. The attached patch to user_service.inc solves the problem (2 lines).

Comments

kylebrowning’s picture

Status: Active » Needs review

Testing

IncrediblyKenzi’s picture

Setting to needs review so the test bot will pick it up.

Status: Needs review » Needs work

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

IncrediblyKenzi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.09 KB

Trying the patch again from the root of the project.

Status: Needs review » Needs work

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

voxpelli’s picture

IncrediblyKenzi’s picture

In a sense, yes, but I can't see a way of handling this ubiquitously.. It's more-or-less a problem upstream; drupal sometimes requires an object (e.g. node) and other times requires an array.

IncrediblyKenzi’s picture

Status: Needs work » Needs review

#4: user_save_array_2.patch queued for re-testing.

Status: Needs review » Needs work

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

qawsed’s picture

Hi, I'm trying to use user.save to change the user location from a mobile application and would really like to see user.save working.

When I test the user.save with JSON in the account parameter, (ex: {"uid":"3","name":"jon","mail":"jon@mail.com","mode":"0","location":{"lid":"5","name":"Jon's Place"}}, I have get the following:

warning: array_keys(): The first argument should be an array in /hsphere/local/home/c149246/orderhub.ca/modules/block/block.module on line 385.
warning: array_fill(): Number of elements must be positive in /hsphere/local/home/c149246/orderhub.ca/includes/database.inc on line 253.
warning: implode(): Invalid arguments passed in /hsphere/local/home/c149246/orderhub.ca/includes/database.inc on line 253.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') OR r.rid IS NULL) ORDER BY b.weight, b.module' at line 1 query: SELECT DISTINCT b.* FROM blocks b LEFT JOIN blocks_roles r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN () OR r.rid IS NULL) ORDER BY b.weight, b.module in /hsphere/local/home/c149246/orderhub.ca/modules/block/block.module on line 386.
Location field is required.

It looks Drupal wants to use arrays on the upstream (why can't they just stick to objects…)

However, if I give it as an JSON array, then I get the following:

Username field is required.
E-mail address field is required.
Password field is required.

Because all elements of the array are treated the same and we can't distinguish element is username, email etc.

Would it help if we converted the JSON array into stdclass in user_services.inc?

kylebrowning’s picture

Status: Needs work » Closed (duplicate)