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) »
  • civicrm_contact_add() changed functions between 1.9 and 2.0
Pages: [1]

Author Topic: civicrm_contact_add() changed functions between 1.9 and 2.0  (Read 3551 times)

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
civicrm_contact_add() changed functions between 1.9 and 2.0
May 16, 2008, 02:07:32 pm
I'm trying to add a contact with an address.  In 1.8 and 1.9, civicrm_contact_add() will store one address for the contact.  In 2.0, a call to civicrm_contact_add() doesn't store an address.

What's the plan?  Did the functional spec of this API change?  Or was the omission just an oversight?  I need to have the address added, so what should I do?  Port the 1.9 logic to 2.0?  There is a bug in the issue tracker about failure to update the address, which is marked "closed" and "won't fix" (???) but that bug doesn't mention the original insert issue.

I'm tempted to do the 1.9=>2.0 port to finish my work while the gurus ponder this question.

Thanks  -- Walt
http://dharmatech.org
oss@dharmatech.org
801.541.8671

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: civicrm_contact_add() changed functions between 1.9 and 2.0
May 16, 2008, 07:13:22 pm

1. so we had asked for feedback on api usage a few months back and got a minimal response. we assumed (rightly) that not too many people were using it. However there is a small group of folks using it, who failed to give us feedback.

2. internally we call BAO functions in most places instead of the API. We also replaced all internal calls to CRM_Contact_BAO_Contact::createProfileContact and stopped using crm_create_contact. due to schema changes etc, we decided not to upgrade the api (see reason 1 above)

3. It is a bit hard for us to write and test api code since we are not users of the api AND we dont get feedback from the community. Going forward we need to address both points

4. your best bet in 2.0 is to port the 1.9 code over. The 2.0 schema is simpler but similar to 1.9, so the porting task might not to too hard

lobo

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

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: civicrm_contact_add() changed functions between 1.9 and 2.0
May 19, 2008, 09:34:44 am
I guess the attraction of the API vs. direct calls to the various internal objects is that I would hope the API would offer more stability from release to release.  For example, between 1.9 and 2.0 the calls to CRM_Contact_BAO_Contact required to insert or update a contact row changed because the schema changed, but the nominal calling sequence of civicrm_contact_add() didn't change.  This is significant to me as I am trying to write an interface between the Drupal Ubercart module and CiviCRM, and ideally the interface should work with as many releases of CiviCRM as possible.  In the case of adding a 'Purchase' activity to the contact's activity history I was stuck with writing two lines of execution because there was not a stable API available.  It would seem more useful to have a stable API to minimize this sort of thing.

-- Walt
http://dharmatech.org
oss@dharmatech.org
801.541.8671

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: civicrm_contact_add() changed functions between 1.9 and 2.0
May 19, 2008, 02:00:44 pm

walt:

All of us do agreee with you on the goals and rationale behind an API. However, when we did ask folks how they are using the API and some use cases, we got very few (zero??) replies. This was when we had the mailing list (9 months ago).

I think for us internally the BAO functions serve as a pretty good API. We need to do a better job documenting them, making them consistent and exposing them so folks can start using it. I suspect we'll take this on as a project in 2.2 or so

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

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: civicrm_contact_add() changed functions between 1.9 and 2.0
May 19, 2008, 03:19:08 pm
OK, here is a patch to api/v2/Contact.php in release 2.0.3 to have civicrm_contact_add store the primary address for the contact:

*** 385,394 ****
--- 385,405 ----
          $params['contact_id'] = $contactID;
      }
      require_once 'CRM/Contact/BAO/Contact.php';
      $contact = CRM_Contact_BAO_Contact::create( $params );
 
+     //  store primary address for the contact
+     require_once 'CRM/Core/BAO/Address.php';
+     $addr_params = array();
+     $addr_params['address'] = array();
+     $addr_params['address']['contact_id'] = $contact->id;
+     $addr_params['address']['1'] = $params;
+     $addr_params['address']['1']['location_type_id'] = 1;
+     $addr_params['address']['1']['is_primary'] = 1;
+
+     CRM_Core_BAO_Address::create( $addr_params, true );
+
      $transaction->commit( );
 
      if ( $contactID ) {
          CRM_Utils_Hook::post( 'edit', 'Individual', $contact->id, $contact );
      } else {


-- Walt
http://dharmatech.org
oss@dharmatech.org
801.541.8671

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: civicrm_contact_add() changed functions between 1.9 and 2.0
May 20, 2008, 09:35:44 am
Hi,

I think that's a good idea indeed to get rid of the api, that are mostly for what I've seen a very think layer around the BAO calls anyway

My feeling about the documentation is that you have good simple examples and more importantly up to date in the tests, but these should be better promoted (generating doc automatically from them ?)

Last but not the least, no matter how few responses you get, if you change an api or anything public, the release note should mention that in red blinking. That's more than painful to update, have a running new version and to realise that the apis have changed when the end users scream because the custom function developed on the top of the apis don't work anymore ;)

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

joachim

  • Guest
Re: civicrm_contact_add() changed functions between 1.9 and 2.0
July 25, 2008, 09:18:49 am
I guess the developers have to decide whether to have an API or the BAO functions.
Speaking as someone trying to develop modules around CiviCRM, the API functions look cleaner and simpler -- providing functionality doesn't get ripped out and the documentation keeps pace ;)

Maybe if Civi used its own API internally (like Drupal does) it would be easier to keep it maintained.

greenmachine

  • I post occasionally
  • **
  • Posts: 58
  • Karma: 6
Re: civicrm_contact_add() changed functions between 1.9 and 2.0
July 25, 2008, 07:33:32 pm
This may be an inappropriate place for the discussion, but since it was mentioned and I came across it: I vote for keeping the API.

The internals of CiviCRM are very confusing to me. I do not have a background in computer science, object oriented programming, etc.. The bulk of my experience is the Drupal context which has a heavy emphasis on clean and relatively easy to use and well documented API functions. There are several developers I've run into in the last year in the Twin Cities (Minnesota) area who have done CiviCRM work and now want to avoid it due to the multiple layers of abstraction of the internal programming and perceived resulting density (also Drupal-oriented developers).

However, I like CiviCRM and I have found the API to be useful and something I am capable of figuring out. The Drupal modules that integrate with CiviCRM that I've used all use the API - I think that's an indicator that the API is being used. I don't think it's too much of a leap to say that many Drupal-oriented developers will prefer the API to figuring out the internal objects/classes/methods of CiviCRM.

There are quirks about the API that can pose challenges, but overall I think it's mostly aimed in the right direction as-is.

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: civicrm_contact_add() changed functions between 1.9 and 2.0
July 26, 2008, 11:32:13 am

This is a fine place to have the discussion. We might move it to the "General Discussion" board if the thread gets big

I think its a good time for the developer community to think about how they can contribute to building and maintaining an effective CiviCRM API. This could be multiple things, from figuring out what set of functions are needed to make a complete and effective API, to writing unit tests and documentation.

Anyone from the community wants to play the lead on this and pull a group of civicrm developers to help tackle this issue?

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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: civicrm_contact_add() changed functions between 1.9 and 2.0
July 27, 2008, 09:51:36 pm
My vote would be for keeping the API able, stable and available (sorry, couldn't resist) where possible. I'm with greenmachine - the API should offer us a clean method of interacting with CiviCRM, and one which allows the developer to remain ignorant of the inner workings of CiviCRM specifically.

Not that understanding CiviCRM is a bad thing (not at all) but IMO this is a primary reason for using a published interface rather than interacting directly with internals. If CiviCRM decided in future to change the use of internal methods significantly, the API could maintain a compatible interface for older code. I think this offers advantages for both third party devs AND the CiviCRM team, for whom a published API offers the freedom to change internal code without such repercussions.

If CiviCRM chooses instead to publish documented approaches for using internal methods, that's fine too - but currently the docs tend to encourage use of the API, so that's the approach we've preferred to date.

We've been bitten somewhat by the API changes also during 1.9 - 2.0 migration - especially when some API code was removed from 2.0 after the early developer releases of that version. That said, I was really delighted with how helpful the CiviCRM team were in getting us up and running again, using either the v2 API or the internal code.

But I'd prefer if the API could have stayed stable to start with : )

@dharmatech - nice patch. I had worked around the same problem by using first civicrm_contact_add(), then civicrm_location_add(), but I'd be glad to see this process simplified back to how it worked in 1.x.
« Last Edit: July 27, 2008, 09:54:46 pm by xurizaemon »
@xurizaemon ● www.fuzion.co.nz

joachim

  • Guest
Re: civicrm_contact_add() changed functions between 1.9 and 2.0
July 31, 2008, 02:53:43 am
I don't know if this is something that used to work in 1.9, but phone values aren't getting added.

I'm wrestling with the CRM_Core_BAO_Phone object, but its creation method is completely different from the CRM_Core_BAO_Address one, which I was hoping to base my approach on:

// in Phone:
    static function add( &$params )
 // in Address:
    static function create( &$params, $fixAddress, $entity = null )

It looks like these expect different data structures in $params too...

Any light that could be shed on this would be very gratefully welcomed!

This is why an API is important!

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: civicrm_contact_add() changed functions between 1.9 and 2.0
July 31, 2008, 11:28:29 am

We do agree that the API is important. We also feel that the community needs to step up and help play a lead role with the design, development, documentation, testing, maintainance of this. My post: http://forum.civicrm.org/index.php/topic,3400.msg18013.html#msg18013 did not get any volunteers. Folks might also want to read: http://www.dogstar.org/drupal/node/450 to get a better idea on how to effectively contribute to open source projects. Its a bit disheartening that folks will complain about the API but not step up and help

I think you can base phone creation similar to address creation. You just need to pass in the phone fields

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • civicrm_contact_add() changed functions between 1.9 and 2.0

This forum was archived on 2017-11-26.