editing non-og2list group causes error "The chosen address is already in use by another group", even when recipient blank
| Project: | Organic groups list manager |
| Version: | HEAD |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | damien_vancouver |
| Status: | needs review |
This error began appearing on a production site with lots of groups. It was caused by a row of bad data that ended up in og2list_groups, with nid=0 and a blank recipient.
deleting this row of bad data with "DELETE FROM og2list_groups WHERE nid = 0;" solves the problem and users were able to edit and save non-og2list groups again.
Checking this in the code, there are only two spots where a row can be inserted into og2list_groups - on new group creation in og2list_nodeapi() $op='insert', and on a group update where a mailing list is being set, in og2list_nodeapi() $op='update'.
The 'insert' op already has a check for $node->nid existing before it can run its insert statement:
<?php
if (isset($node->recipient) && strlen($node->recipient) && $node->nid) {
?>But the 'update' op does not check for $node-nid != 0 before its insert:
<?php
if ($node->recipient && (db_num_rows(db_query("SELECT recipient FROM {og2list_groups} WHERE nid = %d", $node->nid)) == 0)) {
db_query("INSERT INTO {og2list_groups} (nid, recipient, status) VALUES(%d, '%s', 1)", $node->nid, $node->recipient);
}
?>I am still un-sure of quite how Drupal managed to pass the $node->recipient and run the query and end up with a blank recipient in the DB, but in any case it should never be inserting with nid=0.
The attached patch just adds a check for $node->nid in the update branch as well, to (hopefully) prevent these rows from going in. This fix is live on my og2list-after.postcarbon.org test site, and I have tested it by creating a new non-og2list group, editing that group, then editing it again and setting the recipient to make an og2list_groups row, then editing it a final time with that recipient. That should have tested all the logic in 'insert' and 'update' branches of og2list_nodeapi().
If anyone has an install they can apply and test on too, they could then mark this reviewed and tested by the community. Or I can create you a group on og2list-after to test on, just contact me directly.
| Attachment | Size |
|---|---|
| og2list_no_og2list_groups_insert_on_update_0.patch | 888 bytes |
