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

Offline xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 3729
  • Karma: 133
    • 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?
« on: 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+





Offline Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1255
  • Karma: 44
    • EE-atWork
  • CiviCRM version: from 3.3.5 to 4.3
  • CMS version: Drupal 6.20 and Drupal 7
  • MySQL version: 5.5.29-0ubuntu0.12.10.1
  • PHP version: PHP 5.3.10-1ubuntu3 with Suhosin-Patch (cli)
Re: We miss a hook, or the post hook is not at the right place?
« Reply #1 on: March 07, 2011, 01:43:45 am »
It makes sense to have some way to add customized processing before and after a DB update?
Make sure you check the latest Make It Happen initiatives!

Offline xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 3729
  • Karma: 133
    • 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?
« Reply #2 on: 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+

Offline Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 14700
  • Karma: 440
    • 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?
« Reply #3 on: 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
Found this reply helpful? Contribute NOW and help improve CiviCRM with the Make it Happen! initiative.

Offline xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 3729
  • Karma: 133
    • 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?
« Reply #4 on: 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 »

Offline Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 14700
  • Karma: 440
    • 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?
« Reply #5 on: 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
Found this reply helpful? Contribute NOW and help improve CiviCRM with the Make it Happen! initiative.