Clients are unable to install sites due to the following error (tested on a single server):
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'db_server' cannot be null: INSERT INTO {hosting_site} (vid, nid, client, db_server, db_name, platform, profile, language, last_cron, cron_key, status, verified) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array ( [:db_insert_placeholder_0] => 332 [:db_insert_placeholder_1] => 243 [:db_insert_placeholder_2] => 186 [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => 137 [:db_insert_placeholder_6] => 61 [:db_insert_placeholder_7] => en [:db_insert_placeholder_8] => 0 [:db_insert_placeholder_9] => [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 ) in hosting_site_insert() (line 267 of /var/aegir/hostmaster-7.x-3.7/profiles/hostmaster/modules/aegir/hosting/site/hosting_site.nodeapi.inc).
When looking at the 'Create Site' form, this makes sense as the 'Database server' option is not visible for clients, moreover contains an empty value. Because there is only a single database server in my setup. _hosting_side_field
makes this a hidden field (why not a value, that would completely hide it from the front-end?).
// snippet from hosting_site_form() in hosting_site.form.inc
_hosting_site_field($form, $node, 'db_server', array(
'#type' => 'radios',
'#title' => t('Database server'),
'#required' => TRUE,
'#description' => t('The database server the site will use to host its content.'),
'#options' => hosting_get_servers('db'),
'#default_value' => isset($node->db_server) ? $node->db_server : HOSTING_DEFAULT_DB_SERVER,
), '_hosting_node_link');
Now the problem is here; in _hosting_site_field()
the provided default value is ignored, but the first option (provided by hosting_get_servers('db')
) is picked:
// snippet from _hosting_site_field() in hosting_site.form.inc
if (($element['#type'] == 'radios') && !count($element['#options'])) {
$form[$item] = array(
'#type' => 'hidden',
'#value' => key($element['#options']),
);
}
In turn, hosting_get_servers()
performs a query with a node_access tag added to it:
function hosting_get_servers($service) {
$return = array();
$query = db_select('node', 'n');
$query->join('hosting_service', 's', 'n.vid = s.vid');
$query
->fields('n', array('nid', 'title'))
->condition('s.available', '1')
->condition('s.service', $service)
->addTag('node_access');
$result = $query->execute();
...
So summarizing, because the client has not access to servers, hosting_get_servers()
does not return any options, so _hosting_site_field()
gets no value at all. (I tried granting view access to servers, but in the end, only override all node access permission made it show up).
I suppose _hosting_site_field(
) should honor the default value if provided (and set it as a value rather than a hidden):
// snippet from _hosting_site_field() in hosting_site.form.inc
if (($element['#type'] == 'radios') && !count($element['#options'])) {
$form[$item] = array(
'#type' => 'value',
'#value' => !empty($element['#default_value']) ? $element['#default_value'] : key($element['#options']),
);
}
Comment | File | Size | Author |
---|---|---|---|
#2 | clients_cannot_create-2821365-2.patch | 766 bytes | Neograph734 |
Comments
Comment #2
Neograph734Comment #3
Neograph734In fact the patch still does not make much sense... if
!count($element['#options']))
evaluates true, there is an empty array and it is of no use to get the first element usingkey($element['#options'])
. So that might be omitted as well.I'll leave it up to you to decide.
Comment #4
helmo CreditAttribution: helmo at Initfour websolutions for Aegir Cooperative commentedThanks
The key() function returns NULL in such cases ... so I've adapted the patch and committed it to my review branch.
https://github.com/aegir-project/hosting/pull/8
Comment #6
helmo CreditAttribution: helmo at Initfour websolutions for Aegir Cooperative commentedmerged, thanks.
Comment #7
Neograph734No problem! :)