0

Scenario is - contacts had been added to a Group (in this case for subsequent deletion) but a user then incorrectly deleted the Group, rather than the contacts in the Group.

1 Answer 1

1

Achieved this via SQL

Step 1. Identify contacts who the log_civicrm_group_contact table shows were added to the group (and who are not now in Trash, since we can add Trashed contacts to a Group) with a query that includes the value of the new group they will be added to (in this case 893) and filters for the Group that was deleted (764)

select 893, contact_id, log_civicrm_group_contact.status FROM log_civicrm_group_contact LEFT JOIN civicrm_contact cc ON cc.id = log_civicrm_group_contact.contact_id WHERE group_id = 764 AND status = "Added" AND log_action = "Insert" AND cc.is_deleted = 0 ORDER BY contact_id;

Then we grab the result as an SQL insert as follows

INSERT INTO civicrm_group_contact (group_id, contact_id, status) VALUES

with rows like

(893, 76639, 'Added')

Note we ORDERED by contact_id as we had too bit a sql insert so it got cut off, and by ordering by id we could rerun the insert scrip for those which got dropped from previous run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.