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) »
  • Hook doesn't run with v3 API extern REST interface
Pages: [1]

Author Topic: Hook doesn't run with v3 API extern REST interface  (Read 1142 times)

dennis

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: Drupal
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Hook doesn't run with v3 API extern REST interface
June 07, 2012, 09:22:18 pm
Hi,

I'm new to CiviCRM, so please forgive me if I use the lingo incorrectly.  I have experienced a problem that seems to have been seen before.  It seems a lot like the issue described at http://forum.civicrm.org/index.php/topic,21685.msg93964.html#msg93964 and http://forum.civicrm.org/index.php?topic=23345.msg98080#msg98080 (item #1).  Unfortunately, I don't see that an answer was ever provided.

I am using Drupal, I am using the v3 API through the extern REST interface, and I'm trying to get code in a custom hook to run.  But those don't seem to all work together.

In specific, I am trying to 'create' a 'CustomValue' using /sites/all/modules/civicrm/extern/rest.php.  This should result in the 'xxx_civicrm_custom' hook running when the database gets updated.  However, the hook does not run.  The hook does run properly when I create the custom values via other means, such as with the API explorer using the AJAX REST interface or by filling out the form that exposes these custom values.

I have traced the problem as far as CRM_Utils_Hook_Drupal::invoke() where the call to requireCiviModules() results in an empty array.  When the hook runs correctly requireCiviModules() provides an array of a bunch of modules, including our custom module.

I assume that this is most likely due to some sort of configuration problem.  However, many things are apparently configured correctly as our organization has been using CiviCRM for over a year now without problems.

Thanks for your help.

Dennis Cox

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Hook doesn't run with v3 API extern REST interface
June 07, 2012, 10:09:24 pm
If you were specifiying any other API I would suspect the API IS calling the hooks but that CustomValue api is a bit of a special beast - it's quite likely not calling the hooks :-(
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

dennis

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: Drupal
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Re: Hook doesn't run with v3 API extern REST interface
June 10, 2012, 11:17:30 pm
I looked at this some more, and it appears that the problem is not constrained to just the CustomValue api.  We are using other api calls including create contact, create phone, create email, create relationship, and it looks like all calls to CRM_Utils_Hook_Drupal::invoke() result in the same empty $allModules array, and the same behavior of the hook not being called (including civicrm_pre, civicrm_post, civicrm_postSave_civicrm_contact and others).

We are using CiviCRM version 4.1.2.  Thanks,

Dennis

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Hook doesn't run with v3 API extern REST interface
June 11, 2012, 12:36:21 am
Hi,

I haven't used hooks from the API when called from the REST interface (that should boostrap drupal like the others).

Could you investigate if rest is properly initialising drupal?

X+

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

dennis

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: Drupal
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Re: Hook doesn't run with v3 API extern REST interface
June 11, 2012, 02:44:39 am
I spent the day in debug, and I think I found the source of the problem.  In CRM_Utils_REST::loadCMSBootstrap(), the function CRM_Utils_System::loadBootStrap() never gets to run.  The reason seems to be that we were not including a 'q' parameter in the request.  We thought that was unnecessary since we were using the entity/action mechanism as supported in v3.  Since there was no 'q' parameter, the first if statement fails, as below:
Code: [Select]
    $q = CRM_Utils_array::value( 'q', $_REQUEST );
    $args = explode( '/', $q );
   
    // If the function isn't in the civicrm namespace or request
    // is for login or ping
    if ( empty($args) ||
      $args[0] != 'civicrm' ||
      ( ( count( $args ) != 3 ) && ( $args[1] != 'login' ) && ( $args[1] != 'ping') ) ||
      $args[1] == 'ping' ) {
        return;
      }

When I changed our code to include a 'q' parameter of 'civicrm/<entity>/<action>', the hooks fire like they should.  I suppose this is a reasonable work-around, but it also seems like the 'q' parameter shouldn't be required if entity and action are provided as separate parameters.

Dennis

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Hook doesn't run with v3 API extern REST interface
June 11, 2012, 02:54:34 am
Great work!

Could you create an issue, ideally with a patch ?

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: Hook doesn't run with v3 API extern REST interface
June 11, 2012, 02:35:10 pm
Just a quick note that there were some hook related changes in 4.1.3 compared to 4.1.2 so there may be a fix if you upgrade
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

dennis

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: Drupal
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Re: Hook doesn't run with v3 API extern REST interface
June 12, 2012, 02:05:43 am
I looked at the 4.1.3 release.  I didn't see anything that seemed to apply to this issue, but I didn't actually test it to confirm the problem still exists there.

I created CRM-10360 and attached a file based on the 4.1.3 release that includes a fix.  This fix allows me to remove the work-around of providing the 'q' request parameter.  With this fix, the system works the way we expect it to.  Thanks.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Hook doesn't run with v3 API extern REST interface

This forum was archived on 2017-11-26.