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) »
  • Proposal, introduce a new "top be validated" protected tag
Pages: [1]

Author Topic: Proposal, introduce a new "top be validated" protected tag  (Read 1522 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 01:19:27 pm
Hi,

Just had a long mail about api and dedupe, and one of the issue is that sometimes, civicrm can't know what is the right solution.

One example if that when you have two contacts with the same name (duplicates) and that you need to pick one up automatically, it can't know which one to take. Say that you import John doe with the current employer ACME, but you have two organizations ACME in your database, it can't know if that's the first or the second one.

Right now, it does create a 3rd ACME organization, put it as the employer and don't put any error message.

Among the different options, that's probably the one that is longer to fix (you multiply the number of merges), but it has the benefit of not corrupting any existing data or exposing any information.

I would suggest that at minima when civi is faced to a choice it can't solve automatically, it adds the tag "to be validated" to the contact(s), so that's easier to spot for humans that something needs to be fixed.

As a second rule, avoid to destroy/corrupt/compromise data (that one is already applied).

but otherwise, when that's about adding content vs. modifying it, I'd as a user prefer to add the individual as employee to the oldest acme  instead of creating yet another duplicate.

What do you think ?
X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 01:37:48 pm
So, we use a helper function that gives us the extra options we need (by using get & then create). The missing options being:

1) match with lowest number
2) only create if you can find a match & error otherwise

Currently CiviCRM copes with situations where 0 or one match exist.

I do think that in general we need to be able to pass back additional information other than is_error - yes/ no. We also want to be able to pass back if a function is deprecated.

Payment processors tend to have at least two fields for this success vs fail & a specific code that may qualify the success as 'yes, but they want you to ship a $5000 product to an empty warehouse in Detroit and they live in the Cayman Islands'

api_message as an extra field (array)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 01:49:45 pm
Wasn't specifically about the api, eg. for the import as well. (this being said, the import should use the api indeed ;)

Agree, we need to be able to return more info (eg error code, as opposed to error messages on, array of the params in error....).

For calls to api v2, pretty sure we return already a deprecated, but can't see it right now...

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 01:56:36 pm
error_code? success_code, result_code result_message

For v2 deprecated I think we just went for the low-tech approach of dispatching a thug to turn up on their doorstep with warm beer
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 02:30:51 pm
Quote from: xavier on April 26, 2011, 01:19:27 pm
Among the different options, that's probably the one that is longer to fix (you multiply the number of merges), but it has the benefit of not corrupting any existing data or exposing any information.

I would suggest that at minima when civi is faced to a choice it can't solve automatically, it adds the tag "to be validated" to the contact(s), so that's easier to spot for humans that something needs to be fixed.

As a second rule, avoid to destroy/corrupt/compromise data (that one is already applied).

but otherwise, when that's about adding content vs. modifying it, I'd as a user prefer to add the individual as employee to the oldest acme  instead of creating yet another duplicate.

In general, i think we should use a sensible default (in this case we do and we dont destroy/corrupt/compromise data), BUT allow the user to override the behavior via a hook.

different users / orgs have different opinions :) Allowing them to modify what civi does is probably a good path forward.

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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 03:05:56 pm
Quote from: Donald Lobo on April 26, 2011, 02:30:51 pm

In general, i think we should use a sensible default (in this case we do and we dont destroy/corrupt/compromise data), BUT allow the user to override the behavior via a hook.

different users / orgs have different opinions :) Allowing them to modify what civi does is probably a good path forward.


I see hooks as adding extra behaviour, not replacing the existing one.

How would it work ? seek_contact (array ("organization_name" => xxx [id=>42)) that would return an id+name (and decides how hard it tries to re-use an existing contact vs. creating a new one ?)

Also, probably necessary to add extra info about the context (that's an import, and trying to match the current employer) or (that's an event registration using profile X, trying to find if the contact already exists).

How does it work today when several modules implement the same hook that should accept only one (eg hook_civicrm_contactListQuery) ? how's the winning query chosen ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 04:08:02 pm

I think hooks are evolving and the newer hooks "modify" behavior (which could mean adding or changing current behavior). We've done this pretty nicely with some gift aid related hooks and changed existing behavior.

All the hooks get a chance to modify the behavior. hopefully they behave nicely and dont overwrite each other

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

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 05:01:54 pm
On a related note, wasn't sure if you all were aware that there is logic in the code today to alert organizational admin staff when we are creating a duplicate organizational contact during "On behalf of" online contributions / membership signup. This is triggered if the dedupe rule check finds > 1 matching organization. There's a system message template for this : "Contributions - Duplicate Organization Alert"
Protect your investment in CiviCRM by  becoming a Member!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 05:07:42 pm
No, I wasn't aware - but good to know! Maybe it should be a RULES event.

I was pondering the fact that we seem to be in a transition from basically all interaction with CiviCRM being through the CiviCRM forms (a while ago now) to one where other forms of interaction are becoming more & more common.

Re the de-dupe behaviour - I'm not sure in what circumstances it takes place so it's hard to comment - I suspect that if there were a site-wide setting that allowed you to also match oldest contact on de-dupe we would set it on most sites we use
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 08:35:12 pm

seems like we are converging on a solution here :)

Maybe in all cases when the ideal scenario we expect either no contact or 1 contact, if we get more than 1, we invoke a hook. If the hook does not do anything we create a new contact (and send email to the admin). else the hook can return the contact id that the code should use.

That way, the default behavior is maintained and xavier can implement the hook to use the first id that is found and tag it at the same time!

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 08:40:14 pm
Quote
xavier can implement the hook to use the first id that is found and tag it at the same time!

Can we please ship Xavier's module with core!
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Proposal, introduce a new "top be validated" protected tag
April 26, 2011, 10:33:25 pm
Quote from: Donald Lobo on April 26, 2011, 08:35:12 pm

seems like we are converging on a solution here :)

Maybe in all cases when the ideal scenario we expect either no contact or 1 contact, if we get more than 1, we invoke a hook.


I'd see quite a few reasons to invoque it all the time:

Invoque if 0 match found, so my hook can search on the domain name of the email
Invoque if 0 so my hook can search on the nickname/accronym of the organisation or the legal name
Invoque if 1 so anonymous user can't choose my org or can't have "two girls on cup" as the organisation name...

In a nutshell, I think the hook should be called first,
function hook_set_employer (&$params) {
  //search with $params['current_employee'], $params['organization_id']
  // the hook is in charge of creating an org if you want and set
  // if your hook has done the needed, return true, else false
}

and in the Individual contact creation (the BAO), call the hook, if it returns false, put the default behaviour (run fuzzy default match, if 1 use it, otherwise create an org)

X+
« Last Edit: April 27, 2011, 04:35:18 am by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Proposal, introduce a new "top be validated" protected tag
April 27, 2011, 04:51:35 am
If this is controversial, let's go with hooks, but had an idea.

Background: I find that hooks a clever hack, but a hack, put that in the monkey patching category.
What about using OO and the "hook" is in charge of defining what class to instantiate ?

eg (pseudo codish, the existing classes/functions have likely different names):

the BAO contains
Code: [Select]
function saveIndividual ($params) {// or whatever that's named

  $dedupeClass=hookHandler::getClassName ('dedupeOrg') // returns "dedupeOrg" by default, the hook can overwrite it
  $dedupe = new $dedupeClass (__FUNCTION__,"online registration");// set info about the context
  $dedupe->setEmployer ($params);
}


class dedupeOrg { // that's the default class implementing the default behaviour

  function setEmployer (&$params) {
     if ($params['current_employer'])
       if findOne ($params['current_employer'])
         $params['organization_id'] =  findOne ($params['current_employer']
      else {
         $neworg=civicrm_api ('Contact','create', array ('organization_name' =>$params['current_employer'])
         $params['organization_id'] = $neworg[id];
      }
  }
  return true;
}


Then in my module as a regular drupal/joomla one:
--------------- my module -----------


Code: [Select]
mymodule_getClassName ($className) {
  if ($className == 'dedupeOrg')
    return "mySmarterDedupeOrg";
}

class mySmarterDedupeOrg  extends dedupeOrg{
    function setEmployer (&$params) {
      //do whatever, tag, search on this and search on that...
      if (happy with the dedupe){
        $params['organization_id] = 42;
        return true;
     }
     parent::setEmployer($params); // fallback on the default behaviour
   }
}

I have extended an activity using the various class hooks, the approach described above would have been much easier and would have allowed me to put it as a separate module.

It would be as well a better alternative/complement for the contactListQuery hook: I would have been able to bypass all the code around the query and directly provide the list of 25 contacts. That would allow smarter searches that you can't do today: search on "$q%", if <20 results, search on "%q%", if <20 results, split on words and OR search...

X+
« Last Edit: April 27, 2011, 05:30:13 am by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Proposal, introduce a new "top be validated" protected tag
April 27, 2011, 05:49:09 am
Without even remotely suggesting I oversee all implications or know what I am talking about.............

Xavier's hook idea seems like a sound one. One reason for this is that I get it!

In general the current way of dealing with hooks is far too focused on the form loop IMO (see other forum discussion on pre / postProcess hooks) , and that needs a kind of common sense approach that is not unlike this principle or the principle used in API v3.....meaning there is a straight forward generic function that takes care of some of the peculiarities or inconsistencies of the individual API's, or hooks.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Proposal, introduce a new "top be validated" protected tag
April 29, 2011, 09:44:09 am
The discussion about introducing that new OO Hook as been postponed, we will do a regular hook now.

 
Note for me: CRM_Dedupe_Finder::dupesByParams($dedupeParams, $contactType, 'Fuzzy', array( $contactID ) );

adding more context (probably in dedupeParams)

Otherwise the test id is matching the name of the employer is unuseful in the API, that's handled already (and better) in CRM/Contact/BAO/Contact.php

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Proposal, introduce a new "top be validated" protected tag

This forum was archived on 2017-11-26.