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 work with v3 API extern REST interface
Pages: [1]

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

colbyw

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 14.14
  • PHP version: 5.3.6
Hook doesn't work with v3 API extern REST interface
October 24, 2012, 01:50:39 pm
We are having a problem with a civicrm_custom hook firing when we add petitions to our system using the REST interface. If I sign the petition through the civicrm interface, our custom module runs and the hook fires. However, if the petition is added through the REST interface, the custom hook doesn't fire. We are using a Drupal 7 system on 4.2.4. I have added the following line to make the REST interface work, but it is only a hack and not a solution to the problem:

      if (function_exists('module_list')) {
         $this->allModules = module_list();
       }
+      $this->allModules[] = "custom_module";
 
       $this->requireCiviModules($this->allModules);
     }

Any ideas of why the hook would only fail to fire when using the REST interface. There was a previous forum post by someone else who worked on our system (http://forum.civicrm.org/index.php?topic=24930.0), but I have checked and the CRM_Utils_System::loadBootStrap() code is running so I don't think that is the issue.

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 work with v3 API extern REST interface
October 26, 2012, 09:43:15 pm
Where is this code? Is it in drupal?

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

colbyw

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 14.14
  • PHP version: 5.3.6
Re: Hook doesn't work with v3 API extern REST interface
October 29, 2012, 12:00:12 pm
It is in CRM/Utils/Hook/Drupal.php

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 work with v3 API extern REST interface
October 29, 2012, 12:03:22 pm
Does the function module_list exists? does it returns your module?

did you define your module as being depends of civicrm?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

colbyw

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 14.14
  • PHP version: 5.3.6
Re: Hook doesn't work with v3 API extern REST interface
October 29, 2012, 03:09:50 pm
Yes, I have the line "dependencies[] = civicrm" in my module info file, and it doesn't work.
It appears that module_list() does not return my module when input via REST, but when input via the webpage it does.
Here is what the file looks like now:

if (!$this->first || empty($this->allModules)) {
      $this->first = TRUE;

      // copied from user_module_invoke
      if (function_exists('module_list')) {
        $this->allModules = module_list();
      }
      //$this->allModules[] = "custom_module";

      $this->requireCiviModules($this->allModules);
    }

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: Hook doesn't work with v3 API extern REST interface
October 29, 2012, 04:24:03 pm
seems like the CMS is not being bootstrapped. Might want to check and see if its ignoring an error and returning early.

the call is in extern/rest.php: $rest->loadCMSBootstrap();

is the authenticateKey call returning false and hence the code proceeds without loading the CMS? i suspect so

lobo
« Last Edit: October 29, 2012, 04:26:08 pm by Donald 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

colbyw

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 14.14
  • PHP version: 5.3.6
Re: Hook doesn't work with v3 API extern REST interface
October 30, 2012, 11:58:06 am
Okay, I just surrounded the authenticate key in printouts and loadBootstrap is not failing on the authenticateKey. Is there somewhere else to look next?

colbyw

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 14.14
  • PHP version: 5.3.6
Re: Hook doesn't work with v3 API extern REST interface
November 02, 2012, 04:26:42 pm
Okay, I have finally found the source of my problems. The $this->allModules list contains the entry [mte] (the Mandrill Transactional Email extension) every time the hook invoke function is called after the first time. This means in the code below, (!$this->first || empty($this->allModules) will never be true after the first time because of the extension, and the first time occurs before drupal is bootstrapped.

if (!$this->first || empty($this->allModules)) {
      $this->first = TRUE;

      // copied from user_module_invoke
      if (function_exists('module_list')) {
        $this->allModules = module_list();
      }

      $this->requireCiviModules($this->allModules);
    }

I disabled the extension and everything worked properly.
This looks like a problem with how extensions are handled.
Can someone with knowledge of extensions comment on this?

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Hook doesn't work with v3 API extern REST interface
November 02, 2012, 05:47:18 pm
Thanks for that diagnosis -- it's very helpful!

There's an issue now: http://issues.civicrm.org/jira/browse/CRM-11212 We're working on a patch for the next 4.2.x.

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 work with v3 API extern REST interface
November 03, 2012, 12:42:01 am
Thank colbyw,

Your hook is on civicrm module or on an extension?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

colbyw

  • I’m new here
  • *
  • Posts: 13
  • Karma: 1
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 14.14
  • PHP version: 5.3.6
Re: Hook doesn't work with v3 API extern REST interface
November 05, 2012, 08:56:05 am
The hook that is firing on the custom table is in a module.

The extension is for mandrill transactional emails.

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

This forum was archived on 2017-11-26.