I was getting Invalid argument supplied for foreach() hosting.ip.inc:39 when saving a server node, and I noticed that my IPs were not getting saved.
On line 39, you're checking $node->new_ip_addresses but using $node->ip_addresses, which is undefined. If I'm understanding the code correctly, you meant to have $ips = is_array($node->new_ip_addresses) ? $node->ip_new_addresses : array();.
On line 51, you were not checking that $node->ip_addresses exists in hosting_ip_validate(), and I was getting another invalid argument error here, too. I fixed both errors, and my IPs saved to the server node correctly.
I'm attaching a patch, but I welcome any feedback. I'm relatively new to the Hostmaster codebase, just trying to help out. :)
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | hostmaster-ip-foreach-1994028-2.patch | 1.51 KB | benclark |
| #1 | hostmaster-ip-foreach-1994028-1.patch | 981 bytes | benclark |
| hostmaster-ip-foreach.patch | 981 bytes | benclark |
Comments
Comment #1
benclark commentedThe patch file I submitted was wrong; serves me right for rushing through it without testing the patch file itself. The one I'm attaching now will correctly address the
Invalid argument supplied for foreach() hosting.ip.inc:39error.Comment #2
benclark commentedSorry for the flood of patches here, but I think I stumbled upon the source of the problem, at least for new server nodes.
The ip_addresses key is missing from the node form, and that's the only way that $node->ip_addresses becomes available inside the hosting_server_validate() callback. The node load callback is not loaded before hook_validate(), and the $node->ip_addresses property that is added in hook_form() does not carry forward into hosting_server_validate().
My patch adds a hidden value element on the node form containing $node->ip_addresses, which will either be an empty array for new nodes, or the current ip_addresses for that server. Either way, it appears to be ignored/replaced by the validate and presave hooks, anyway.
I'm attaching a patch that includes my earlier patches, and this new form change. If it's not the right solution, just let me know -- just trying to help out the project!
Comment #3
anarcat commentedthe IP addresses are managed by the SSL module, are you sure you have enabled that module? Maybe we just need to silence the warnings, and not add a new form!
Comment #4
anarcat commentedi think this was fixed in a simpler way in #2000946: Unable to allocate IP address for certificate.