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) »
  • We miss a hook, or the post hook is not at the right place?
Pages: [1]

Author Topic: We miss a hook, or the post hook is not at the right place?  (Read 1382 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
We miss a hook, or the post hook is not at the right place?
March 04, 2011, 04:20:20 am
Hi,

Right now, the pre/post hooks are strongly bound with the interface and that's only when you modify the Entity through the web interface that they are fired.

eg. if you modify a group, add a tag or create a contact via the API, you can't modify the behaviour.

The post hook is fired from the form,
http://wiki.civicrm.org/confluence/display/CRMDOC33/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmpost


I'd like to be able to alter the DAO object before and after the call. It seems to be enough to plug the call into the  function save of the DAO.

1) Does it make sense ?

2) Is calling a hook costly ? In that case, might be better to skip the pre and only do the post ?

3) Are we mostly sure that every modification/creation goes thought a save()? (happy to ignore the modules that write directly into the db)

X+




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

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: We miss a hook, or the post hook is not at the right place?
March 07, 2011, 01:43:45 am
It makes sense to have some way to add customized processing before and after a DB update?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: We miss a hook, or the post hook is not at the right place?
March 28, 2011, 05:36:18 pm
@lobo

THe problem is that the post hook is NOT in the DAO, but in the form:

CRM/Core/Form.php:        CRM_Utils_Hook::postProcess( get_class( $this ),

Can we introduce these hooks ?

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

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: We miss a hook, or the post hook is not at the right place?
March 28, 2011, 09:17:44 pm

xavier:

the post hook is different from the postProcess hook

for most objects where the post hook is implemented, all create/update of that object in the db, goes thru the same BAO function (typically create or add)

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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: We miss a hook, or the post hook is not at the right place?
March 28, 2011, 11:13:00 pm
My bad, never feed a grep after midnight ;)

So that's what I can find. I don't understand how that's called for the other entities. To be sure it's always called, shouldn't we move it to the DAO ?

CRM/Core/BAO/Tag.php:            CRM_Utils_Hook::post( 'delete', 'Tag', $id, $tag );
CRM/Core/BAO/Tag.php:            CRM_Utils_Hook::post( 'edit', 'Tag', $tag->id, $tag );
CRM/Core/BAO/Tag.php:            CRM_Utils_Hook::post( 'create', 'Tag', null, $tag );
CRM/Core/BAO/EntityTag.php:        CRM_Utils_Hook::post('create', 'EntityTag', $tagId, $object );
CRM/Core/BAO/EntityTag.php:        CRM_Utils_Hook::post( 'delete', 'EntityTag', $tagId, $object );
...


I'm asking because CaseActivity doesn't trigger the hook call, I'm assuming that's a bug, I'll fill an issue.
« Last Edit: March 28, 2011, 11:21:03 pm by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

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: We miss a hook, or the post hook is not at the right place?
March 29, 2011, 07:31:04 am

Not all entities call the hook and we need to add code to make it do so

so, adding it to the DAO is a move in the right direction. maybe a project for 4.1

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) »
  • We miss a hook, or the post hook is not at the right place?

This forum was archived on 2017-11-26.