When deleting an image from a multiple imagefield, empty rows remain in the CCK data table.
The reason is, that the empty array is not removed from the &$node_field variable in the update hook, thus cck's hook_field removes the line marked for deletion from the table but certainly re-inserts it again while iterating through the &$node_field variable.

I created a patch that removes an empty, deleted file from the &$node_field array in the imagefield module.

Patch created for both 4.7 and 5.1 versions separately.

Comments

energie’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
StatusFileSize
new924 bytes

here is the 5-1 patch

dopry’s picture

Status: Reviewed & tested by the community » Fixed

tnx, committed to 4-7 and 5. I forgot all about the unset stuff making it into content.module. hooray for and older bug going away.

yched’s picture

Status: Fixed » Active

Actually I'd recommend keeping the empty value for $delta = 0, in order to actually store in the db that the field is empty.
Someting like if (empty($node_field[$delta]) && $delta >0) - see text.module or nodereference.module

With the patch above, empty fields are not consistently stored in the db :
no record if the field is stored in a field table (multiple or shared field)
a record with the 'default' value for the db column if the field is stored in a content-type table
And then for instance, you cannot accurately filter empty fields in a view.

Yet another aspect of multiple fields that would be better off handled in content.module...

dopry’s picture

@yched, How does that work out... I should have at least one value of 0 in a multivalue table? can you give me a quick recipe to test the effect?

yched’s picture

I should have at least one value of 0 in a multivalue table?
Yes - but content.module does not really enforce that, that's rather my personal opinion in order to have consistent db storage and views filtering.

If you do not do that, and the field is stored in a per-field table, then the field is not really empty, it simply does not exist for the node.

Sorry for paraphrasing my previous post, I'm not sure I understand your question ;-)

edrex’s picture

My content_field_images table has no record for some nodes, and the 0-record for some.

The first group renders fine, the second renders a broken img tag like

Only local images are allowed.

Some vids have up to 5 0-records in the table (deltas 0-4) and nothing else. AFAIK nodes with multiple zero-values render ok.

Basically, imagefield is keeping a very sloppy table, this needs some care.

edrex’s picture

Forgot to put my markup in a <code>, oops. I only noticed this because I use konqueror, which shows an icon for broken images. You all must be FF users :P

Only local images are allowed.

edrex’s picture

ah crap, I forgot to entify... that seems like alot of work. So when rendering it's treating the empty field as though it had a valid image path etc, so the path ends up being bogus.

jpetso’s picture

Status: Active » Closed (duplicate)

As far as I can see, this issue concerns the same database inconsistency that I tackled in issue #88136 with a pretty comprehensive patch. Also see the corresponding filefield issue (which is exactly the same problem as this one) on what's wrong, and how I tried to overcome it.

Given the patches and other attempts in the mentioned issues, I'll be frank and close this one as duplicate.