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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API Changes for 2.2.3
Pages: [1]

Author Topic: API Changes for 2.2.3  (Read 4576 times)

cap10morgan

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 9
API Changes for 2.2.3
May 04, 2009, 09:06:37 am
As part of the API documentation & cleanup project coming out of the recent Dev Camp, I (and hopefully others) are working on standardizing the API for 2.2.3. Our goal is to get it stable and complete enough by 2.3 that we can freeze it for the rest of the 2.x series after that.

In general, when something must be changed to conform to the new API standard (documented here: http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=15401593), we're deprecating the old format but leaving it otherwise intact. However, this isn't always possible. When an API function's name and signature already conform to the standard but its behavior does not, then we have to make a decision between 100% backward compatibility and moving in the right direction for the future.

One such case has already come up in the Contact.php API file (api/v2/Contact.php): The civicrm_contact_get function that was there behaves incorrectly according to the new API standard (specifically the part about merging get and search into the same op where the presence of an id determines whether you're getting or searching). What I've done at this point is add an optional parameter to the function called $deprecated_behavior. By default it is false, but if you pass true there instead (like this: civicrm_contact_get($params, true);) then you'll get the old behavior.

I still need to work out how to make the REST interface work with this so you can request deprecated behavior via that. We already discussed adding a version parameter to the REST interface so you could request a specific API version with each call. Maybe that's how we should handle this? I kind of didn't want to create yet another api/vX directory in the source tree, but maybe that's the better solution. What do other folks think?

So if you have code that uses civicrm_contact_get, you'll need to either update it to conform to the new API standard (basically for this, you just need to expect to get an array of contacts back, even if you're just getting one by passing in a contact_id) or else start passing true for the $deprecated_behavior parameter. Obviously the much better path is to conform to the new standard whenever possible since the deprecated behavior will go away in a future release.

If folks think this is an acceptable way to go forward, then we should follow this convention everywhere we encounter a situation where the old function is already using the correct name and signature but we need to alter its behavior. That is, add a 2nd parameter after $params called $deprecated_behavior that dictates which "mode" the function operates in.

abrookins

  • I’m new here
  • *
  • Posts: 21
  • Karma: 5
    • Redspire (Blog)
Re: API Changes for 2.2.3
June 02, 2009, 01:02:05 am
This is an interesting change.  I appreciate the effort toward standardisation, and I'll be updating my code to expect the new array structure on return from civicrm_contact_get().

On the flip side, it took me a while to find this information.  So far as I can see, it isn't mentioned yet in the API docs. 

What is the best way to keep updated on API changes such as this, other than the API docs?  Currently, I check the Civi blog(s) pretty regularly, subscribe to at least one newsletter, occasionally hit the forums, and receive commits.  Should I also subscribe to notifications from this forum?  Is there anywhere else that changes to the API may be posted? 

Thanks,
Andrew

cap10morgan

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 9
Re: API Changes for 2.2.3
June 02, 2009, 08:31:06 am
Quote from: redspire on June 02, 2009, 01:02:05 am

On the flip side, it took me a while to find this information.  So far as I can see, it isn't mentioned yet in the API docs. 


That's because we're still working on it. It hasn't been released in any production version of CiviCRM yet. Once it is, you'll see those docs updated.

If you want to help out, we could really use a "prime mover" on this effort. I've been distracted by other $day_job responsibilities, so I've been slack in this role lately. I'd love to return to it soon, but if someone else took up the mantle in the meantime, that would be great. You wouldn't have to understand everything, just know who was involved, who knows what, who is working on what, etc. and bug us until we get things done. :) I can help you get up to speed in that regard.

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: API Changes for 2.2.3
June 02, 2009, 10:42:46 am
In order for the new standard to actually be a useful API standard, it needs to define exactly what param does what.  Currently one of the problems is that in many cases $params is passed into the DAO where DAO::copyValues() just copies whatever is in $params to a column of the same name.  Therefore, any change to the schema (which changes in every minor release) results in a change to the API.  So as the author of uc_civicrm, I'm forced to respond to the schema change by trying to figure out what changed and what to do about it.  To make matters worse, I have to then write and test code to assure that my module works with every minor release.  This just isn't viable.

So what we need to do to produce a stable API is to write a contract which defines exactly what each key in $params represents, and what values it may take on, then document this independently of the schema.  Then we can write a regression test to guarantee that the contract is met, and fail the release until the API code is adjusted to conform to the contract.

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

cap10morgan

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 9
Re: API Changes for 2.2.3
June 02, 2009, 06:48:37 pm
Walt,

I agree. That's something we should add to the list of things to standardize. But I'm thinking we could do it by "freezing" the params around the 2.3 (or whatever version gets the first standardized API release) schema and then coding interpretation layers when and if the schema changes down the road so that the API params do not. Does that seem like an OK approach or will it cause us more problems later?

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: API Changes for 2.2.3
June 02, 2009, 08:12:46 pm

I think the "no backward compatibility" policy (but great documentation on how to migrate) has served Drupal very well

To be realistic, our resources to manage a frozen API / keep it compatible etc are limited. So the Drupal policy makes more sense to me than the SF policy

Walt, still waiting to hear details on what API change broke uc_civicrm. If i had to guess, it was more a bug than a schema change

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: API Changes for 2.2.3
June 03, 2009, 05:01:03 am
Quote from: Donald Lobo on June 02, 2009, 08:12:46 pm
Walt, still waiting to hear details on what API change broke uc_civicrm. If i had to guess, it was more a bug than a schema change

It was Wes's change to conform to the new policy.
http://dharmatech.org
oss@dharmatech.org
801.541.8671

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: API Changes for 2.2.3
June 03, 2009, 06:11:47 am
Quote from: Donald Lobo on June 02, 2009, 08:12:46 pm
I think the "no backward compatibility" policy (but great documentation on how to migrate) has served Drupal very well

To be realistic, our resources to manage a frozen API / keep it compatible etc are limited. So the Drupal policy makes more sense to me than the SF policy

The Drupal policy of "no backward compatibility" means that, for example, the change from Drupal 5 to Drupal 6 was seismic.  It took months for the contributed modules to adapt to the change.  Some never did.  We delayed rollout of D6 to some clients for months waiting for the contributed modules to catch up.  In the case of contributed modules that never caught up and needed to be replaced, there was expensive hand labor involved.  We have a lot of clients still on old releases of Drupal because it is so expensive to upgrade.  So the incompatible seismic events define which version of Drupal people use.  That's one reason people were anxious to find a way to run CiviCRM 2.1 on Drupal 5.

Right now the lack of a frozen CiviCRM API is so expensive for developers that hardly anyone can afford to contribute to CiviCRM.  Contributions that are developed to use the unstable API tend to break with every point release, so why bother?  The one real user of uc_civicrm that we have is still on Drupal 5, for example.

-- 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: API Changes for 2.2.3
June 03, 2009, 06:58:56 am

disclaimer: most of this does not apply to DT as an org, since you'll are great open source citizens (IMO) and participate/give back

while at some level your response makes sense, at some other levels it does not.

If you treat open source purely as a product it does make complete sense. Unfortunately i dont think folks should treat it purely as a product. We just dont have enough resources etc to keep it moving without a LOT MORE community support. Some examples:

* CiviCRM 2.1 on D5. Lots of folks wanted it. No one was willing to sponsor it or even help work on it. We were willing to assist significantly. Bottom line: talk is cheap, action is a lot more expensive

* D5 -> D6 upgrade. Similar situation to above. Lots of folks want to use D6 but not many folks willing to help pay / upgrade modules. If some/all of them chipped in to help make it happen, i suspect things would have moved faster. However changing the mentality of the herd is a much harder problem

my 2 cents.

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: API Changes for 2.2.3
June 03, 2009, 08:56:42 am
Here's a practical example of the Drupal approach, from our logs: after Drupal 6 kernel was stable (with the new, backward-incompatible API), we had to wait roughly 7 months for the views contributed module to become stable before we could actually deliver a real site.  I think this is pretty typical of how Drupal changes propagate.

So if the Drupal API changes every two or three years, figure that the new version will be useful for real world applications after a delay of six months or a little more.  If the Drupal API changed more often, probably the contributed modules would never catch up.

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

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: API Changes for 2.2.3
June 04, 2009, 11:10:25 am
Since the Drupal API has been so successful at drawing community contributions (literally thousands of contributed modules, with more contributed every day), let's look at how they manage their API for whatever lessons we can learn.

When you click on the link above, you see a page with 5 tabs at the top.  Each tab represents one (incompatible) version of the API.  The current (Drupal 6) tab is selected by default.  If you click on, for example, "Module system (Drupal hooks)" you get a page with a list of API calls.   Clicking on, for example, "hook_access" you see that there are actually only two versions of this call, a version for Drupal 4.6-5 and a different version for Drupal 6-7.  The most important feature of this page for me, as a community contributor trying to write code for Drupal, is that the calling sequence and the parameters that may be passed are spelled out in sufficient detail that I can actually program from this information.  Notice also that there are links to examples and related discussions.

Going back to the Drupal API home page, we notice that there is a tab for Drupal 7.  This is the next incompatible API change.  Drupal 7 is expected to be released sometime this Fall, but the API changes have been available for public discussion for months.  This allows developers (well, those developers that plan ahead  ;) ) to prepare for the next release.  For those developers that DON'T plan ahead, they have obviously had plenty of warning so Dries can say "I told you so"  :) .

So how does this affect us in practice?  Well obviously, each incompatible API version represents a major hurdle to upgrade.  Now that Drupal 6 has been out for over a year, we have: five client sites live on Drupal 6 (plus our own site since we eat our own dogfood), eleven sites live on Drupal 5 and one live on Drupal 4.7.  Some of the Drupal 6 sites were converted from Drupal 5, and there was a significant effort involved in some cases, because of the need to deal with some special situation where a Drupal 5 module wasn't available for Drupal 6.

So that's one very successful example of an API that supports community contributions.  We could do much worse than to imitate it.

-- Walt


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

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Re: API Changes for 2.2.3
July 01, 2009, 02:06:46 pm
+1 Walt.
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • API Changes for 2.2.3

This forum was archived on 2017-11-26.