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) »
  • civicrm_custom hook not working as intended?
Pages: [1]

Author Topic: civicrm_custom hook not working as intended?  (Read 1643 times)

dragontree

  • Guest
civicrm_custom hook not working as intended?
November 13, 2009, 04:59:38 am
As I understand, the custom hook should fire before the database write. So that means I could access the old data before it is updated.
So, if I do this:
Code: [Select]
function joomla_civicrm_custom( $op, $groupID, $entityID, &$params ) {
    if ( ($op == 'edit') && $groupID == 7) {
        //get the current value from the DB
        $query = "SELECT joomla_kasutajakonto_32 FROM civicrm_value_muu_info_7 WHERE entity_id = {$entityID}";
        $dao =& CRM_Core_DAO::executeQuery( $query, CRM_Core_DAO::$_nullArray );
        $dao->fetch( );
        $db_value=$dao->joomla_kasutajakonto_32;
CRM_Core_Error::debug_var('TULEMUS', $db_value);
    }
}
But that code dumps the new value not the old one taken from the database. So it seems the new value is written before the hook is called.

Am I missing something here?

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_custom hook not working as intended?
November 13, 2009, 08:15:10 am

the hook is called after the DB call, so the custom values are written to the DB already

where did u get the info that the "hook is fired before the db write"?

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

dragontree

  • Guest
Re: civicrm_custom hook not working as intended?
November 15, 2009, 09:44:45 pm
Quote
Description

This hook is called before a db write on a custom table

This is from the hook specification page.

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_custom hook not working as intended?
November 16, 2009, 06:48:27 am

sorry about that. I've fixed the docs :)

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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • civicrm_custom hook not working as intended?

This forum was archived on 2017-11-26.