If you have a content type with an optional (not required) imceimage field, leaving the field empty then saving the node works fine. However, if you then try to edit the node but still leave the imceimage field empty, the update fails. This is because hook_content_is_empty only checks whether imceimage_path is set (which at first glance seems sensible because this is the only user-editable field - _width, _height and _alt are all hidden fields).
Here's what happens.
- On initial node creation, content.module (CCK) fires hook_content_is_empty, receives TRUE, so populates empty fields with default values from Schema. Default values of 0 are set for imceimage_width and _height.
- On node edit, hook_content_empty fires again. imceimage module checks imceimage_path, which is still not set, so reports again that all fields are empty. Only this time, it's not true. imceimage_width and _height now contain the default value, 0. CCK is told that the fields are empty so it populates the database UPDATE query with NULL for all four imceimage fields. The query fails because imceimage_width and imceimage_height are set to NOT NULL.
The solution is to tighten up the check in imceimage_content_is_empty to report FALSE if any field is not populated, not just imceimage_path:
/**
* implementation of hook_content_is_empty..
**/
function imceimage_content_is_empty($item, $field) {
$emptyCheck = ($item['imceimage_path'] === '' &&
$item['imceimage_width'] === '' &&
$item['imceimage_height'] === '' &&
$item['imceimage_alt'] === ''
);
return $emptyCheck;
}
A patch is attached.
As a side issue, I think CCK is also at fault here. Even if imceimage isn't being entirely honest about whether the field values are empty, CCK should still check for default values where NULL on UPDATE as well as INSERT queries.
| Comment | File | Size | Author |
|---|---|---|---|
| imceimage_content_empty_mods.patch | 564 bytes | rb7 |
Comments
Comment #1
yang_yi_cn commentedsorry but I will reject this. I've tried on my site and the old way works just fine.
I created a node, with multiple imceimage fields, all optional, initial save is fine, edit it, save again, still fine.
I think more details are needed here, as all my fields are having 'unlimited' numbers, not sure if it is causing any difference.
Details of how to reproduce the bug is needed, such as cck version, how did you setup the imceimage field, etc.
Comment #2
rb7 commentedCCK version 6.x-2.2
IMCE Image version 6.x-1.0-beta1
The problem only occurs with a single IMCE Image field. Any multiple, or unlimited, works fine.
To reproduce, create a content type with one IMCE Image field set to optional. Create a node of this type with any data you like but leave the IMCE image field unpopulated. Save the node. Now update the node making any changes you like but again, leave the IMCE Image field untouched. Now try to save. Drupal reports this error:
user warning: Column 'field_{fieldname}_imceimage_width' cannot be null query: UPDATE content_type_{type_name} SET vid = 67, nid = 67, field_{fieldname}_imceimage_path = NULL, field_{fieldname}_imceimage_width = NULL, field_{fieldname}_imceimage_height = NULL, field_{fieldname}_imceimage_alt = NULL WHERE vid = 67 in {path_to_module}\cck\content.module on line 1207.
Comment #3
sher1 commentedI can also verify that this error is occurring and more importantly that the patch fixes the problem.
Comment #4
mekhos commentedI had the same issue with the beta2 version. The patch fixed the problem. Thanks!
Comment #5
rb7 commented@yang_yi_cn: Please see #2. I believe I've supplied the information you requested. sher1 and mekhos have confirmed that the problem exists and the patch fixes it. Please let me know if you need anything else.
Comment #6
fivehimself commentedI can also confirm this issue. Please apply patch to module.
Comment #7
Renee S commentedHas this been committed yet?
Comment #8
panis commentedis committed in 6.x-1.x-dev.