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_civicrm_pre Seems to be Missing Parameters
Pages: [1]

Author Topic: hook_civicrm_pre Seems to be Missing Parameters  (Read 3604 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
hook_civicrm_pre Seems to be Missing Parameters
November 12, 2008, 02:54:03 am
Using Drupal 6.6 and CiviCRM 2.1.1, here is my code:

Code: [Select]
function civiaddresslog_civicrm_pre( $op, $objectName, $objectId, &$objectRef ) {
    print_r ($op);
    echo "\n\n";
    print_r ($objectName);
    echo "\n\n";
    print_r ($objectId);
    echo "\n\n";
    print_r ($objectRef);
    echo "\n\n";
    print_r ($_POST);
    echo "\n\n";
   
    die;
}

I edit an individual and I hope to see the form data displayed via this code. Whereas this code works if I use hook_civicrm_post or hook_civicrm_validate, with the 'pre' hook the objectId and objectRef are empty. Of course $_POST shows all of the data submitted, but it lacks the ids of the objects involved.

To explain why I am doing this, the task at hand is to keep a log of changes to Contact data only, with time stamps. The reason for this is because the Contact data is duplicated by another organization and they send their updated data twice a year to us. This log will then be used later to determine which address data is newer and update only that data.

So while the post or validate hooks give me all the data I need to create the log, they do that after the database was updated so I can't determine whether or not the address data was changed.

Is there something wrong with this hook code or am I using it incorrectly?

Thank you.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

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_civicrm_pre Seems to be Missing Parameters
November 12, 2008, 07:34:10 am

the pre hook is invoked BEFORE we construct the object, so we dont know the objectID or object itself. this gives a chance to various modules to modify the parameters if needed

in edit mode you should get the contact_id (according to the code, if not please check and debug: CRM/Contact/Form/Edit.php, line 620)

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

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: hook_civicrm_pre Seems to be Missing Parameters
November 12, 2008, 10:43:16 am
Quote from: Donald Lobo on November 12, 2008, 07:34:10 am
in edit mode you should get the contact_id (according to the code, if not please check and debug: CRM/Contact/Form/Edit.php, line 620)

My hook is being called in edit mode but I do not get the contact_id. If I edit \CRM\Utils\Hook.php and make the following change (starting at line 50--I simply replaced one line):

Code: [Select]
    static function pre( $op, $objectName, $id, &$params ) {
        $config =& CRM_Core_Config::singleton( );
        require_once( str_replace( '_', DIRECTORY_SEPARATOR, $config->userHookClass ) . '.php' );
        return   
            eval( 'return ' .
                  $config->userHookClass .
            //    '::invoke( 4, $op, $objectName, $objectId, $objectRef, $op, \'civicrm_pre\' );' ); 
                  '::invoke( 4, $op, $objectName, $id, $objectRef, $params, \'civicrm_pre\' );' ); 
    }

then I do get that id. I changed $objectId to $id but the truth is that I don't see where $objectRef is defined either--it comes thru as null for me so I think that may also be an error.

Let me know what you think.

Thank you.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

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_civicrm_pre Seems to be Missing Parameters
November 12, 2008, 01:11:11 pm

cool. thanx for doing the fix. We dont have the objectRef in the pre hook, so we send the params. I've fixed 2.1 for this. My code changes are:

Code: [Select]
--- CRM/Utils/Hook.php  (revision 17980)
+++ CRM/Utils/Hook.php  (working copy)
@@ -53,7 +53,7 @@
         return   
             eval( 'return ' .
                   $config->userHookClass .
-                  '::invoke( 4, $op, $objectName, $objectId, $objectRef, $op, \'civicrm_pre\' );' ); 
+                  '::invoke( 4, $op, $objectName, $id, $params, $op, \'civicrm_pre\' );' ); 
     }
 
     /**

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

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: hook_civicrm_pre Seems to be Missing Parameters
November 13, 2008, 02:54:19 am
> We dont have the objectRef in the pre hook, so we send the params

Makes sense.

> I've fixed 2.1 for this

Meaning this change will go out in 2.1.2?

> thanx for doing the fix.

My pleasure. :)

H
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook_civicrm_pre Seems to be Missing Parameters

This forum was archived on 2017-11-26.