CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • "orphan" activities after merge
Pages: [1]

Author Topic: "orphan" activities after merge  (Read 1659 times)

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
"orphan" activities after merge
September 04, 2010, 04:04:57 pm
Event participations are mirrored in Activities; when an event participation is deleted, the matching Activity is also deleted.  This makes sense and works fine.

Here's something a little unexpected:

Merge Contact A, who has some events, into Contact B, who has none.  Contact A is the duplicate, and Contact B is the record to keep.  When merging, check the box to "Move related..." Activities, but not move related events.  (Maybe you know all the Event records for Contact A are bogus, but some of the Activity records are good and you want to keep them.)

After the merge, Contact B still has no Participations, which makes sense.  But she does have an Activity for every one of the participations that Contact A had. That's unexpected.

Is this something we'd consider a bug?  Is the solution just to delete those orphaned records from civicrm_activity, or does that cause more problems?  As an admin I could do that as a workaround in hook_civicrm_merge(), but is this something we shoudl address in core?

Thanks,
TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: "orphan" activities after merge
September 04, 2010, 04:41:36 pm

can u check the merge code? might be worth checking the code and process all the components first and finally the activities

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: "orphan" activities after merge
September 04, 2010, 06:07:49 pm
Hi Lobo,

Looking at the code, it happens that in this case the merge code doesn't specifically process participations at all.  It leaves them alone because they're not selected for moving.  Then when it's done moving all data, it calls civicrm_contact_delete() for the "other" (to-be-deleted) contact, which then goes about deleting that contact's various related data.

One solution might be to do some clean-up of Activity records, within the transaction that happens at the end of CRM_Dedupe_Merger::moveContactBelongings().  We could add some sql statements to that transaction to check for, and delete, orphaned Activities.  I'm guessing this is probably not just for CiviEvent participations; there are probably other components that would be similarly handled, right?

Here's another interesting thing:  That activity that was copied over to Contact B is actually still pointing to a participation record for Contact A.  That activity record is a bit of a mongrel, tied to Contact B in contact_id column, but tied to Contact A via the source_record_id column.  And there of course is no proper activity record for that participation of Contact A.  This will make it pretty hard to restore this record for Contact A if he is ever "undeleted."

Here's an idea: Perhaps we shouldn't be copying activities that are connected to participations (or similar record for other component).  Instead of copying, we could create new Activity records for whatever component records are moved over.  This way we're sure that Contact A's activities are still in order in case of his ever being undeleted, and avoids having activity records for Contact B that don't have matching component records.   This might be done in moveContactBelongings(), since it deals with that related data.

- TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: "orphan" activities after merge
September 04, 2010, 09:38:20 pm

for the short term, cleaning up via a hook is probably the best thing

for the medium/long term, i think we need to address this at the code level and transfer non-component activities when activities is checked and component activities when the respective component is transferred (or not). i suspect this might be a non-trivial fix. its also a edge case, IMO

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: "orphan" activities after merge
September 05, 2010, 08:05:59 am
Yes, probably an edge case. Not too many people will be moving Activities and not moving Events/Registrations. 

But it's good to remember the current behavior does leave corrupted data in the system.  Don't know if there's a cheap fix to prevent that, though.

In my case I can handle it with the hook.

Thanks,
TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • "orphan" activities after merge

This forum was archived on 2017-11-26.