Apologies if this has been asked before. It's been a long day and I can't see anything similar in search results.

When using schedule follow up activity to create an activity, the follow up activity is deleted when the original is deleted. (Currently happening in 4.6)

I've not seen this happening on other installs (then again, I've never looked).

Is there a way to stop this happening, a magic button I'm overlooking?

  • Are the initial Activities being deleted on purpose - if so why - or accidentally?
    – petednz - fuzion
    Nov 20 '17 at 21:54
  • It's a mentoring service for ex offenders. Staff can view and update mentors and mentees Mentors can only update their own mentees (permissioned relationships) Some mentors are creating duplicate activities because they can't see/ update activities added by staff. Staff are then "tidying up records" by deleting one of the duplicated activities, which is causing follow up activities to disappear. I've not seen the issue elsewhere because the duplication of activities doesn't happen in the same fashion/ at the same rate. Nov 21 '17 at 16:27
  • 1
    The organisation has now decided to not delete duplicated activities but to use an additional status to take them out of reports. Nov 21 '17 at 16:28

This is coming from the db schema. There's a delete cascade constraint on parent_id. You could remove that constraint but it might be used elsewhere for different types of activity-pairing (not followup related) to enforce data consistency. Would have to review all the activity-related code that uses parent_id. It's also possible that parent_id for this pair of activities is never used again anywhere, so another possibility is remove that linking for followups (via some code, either override or extension), but again would need to review.

  • Thanks Demerit Where would I start looking for those settings? Cheers Craig Nov 21 '17 at 16:29
  • I see your comment about change of plans but for anyone else looking: To review, use for example "grep -r parent_id *" in the civi folder and see what comes up. If doing the first option to remove the constraint, "ALTER TABLE civicrm_activity DROP FOREIGN KEY FK_civicrm_activity_parent_id". For the second, one way is to write an extension and use hook_civicrm_post to set the parent_id to null when it's a followup. docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post
    – Demerit
    Nov 22 '17 at 0:01
  • Altering the schema for an individual database without reviewing all the activity-related code that uses parent_id sounds fairly risky. Using hook_civicrm_post to set the parent_id to null when it's a followup, or alternatively using a pre hook to null any parent ids in children before nulling the parent sounds less risky (off the top of my head). Nov 22 '17 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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