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 postProcess no longer sufficient since edit-in-place?
Pages: [1] 2

Author Topic: Hook postProcess no longer sufficient since edit-in-place?  (Read 2129 times)

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
Hook postProcess no longer sufficient since edit-in-place?
October 08, 2012, 09:55:50 am
Since CiviCRM 4.2.2 we have the edit-in-place, which I really like. However, I think it also means that I can no longer trust the postProcess hook to catch all my contact updates, is that right? And if that is right, what alternative approach do I have? If my assumption that postProcess does not 'catch' the edit-in-place then I think we are coming to a point where the form related hooks need to be replaced with database action hooks?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Hook postProcess no longer sufficient since edit-in-place?
October 08, 2012, 10:06:09 am
To answer my own post: I will replace the form related civicrm_postProcess hook with the DB oriented civicrm_post hook. This is being called after a DB record has been updated. For example, the individual is an object, containing phone and email in arrays within the object (although one could argue these are objects too).
The bad news is that the edit-in-place does not seem to call the civicrm_post hook either?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Hook postProcess no longer sufficient since edit-in-place?
October 08, 2012, 10:14:02 am
I have done a little more testing, looks like most edit-in-place actions actually do call the civicrm_post hook. At least the communication preferences link to the Individual (or other contact types) objectName, the address comes with objectName Address. Adding or deleting an emailaddress or phone however does not do anything, and this is actually what I need for my current project!
The code to call the hook is actually in the BAO code, so I can see
Code: [Select]
if (!empty($params['id'])) {
      CRM_Utils_Hook::post('edit', 'Email', $email->id, $email);
    }
    else {
      CRM_Utils_Hook::post('create', 'Email', $email->id, $email);
    }
    return $email;
When I debug it looks like the code is not executed though...the execution is actually processed by Core/BAO/Block.php and I will do more debugging there. First glance seems to suggest however no call to the CRM_Utils_Hook and no call to the CRM_BAO_Email either.
« Last Edit: October 08, 2012, 10:29:31 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Hook postProcess no longer sufficient since edit-in-place?
October 08, 2012, 01:26:07 pm
Ok - no real input here - I just don't want you to feel like you are talking to yourself :-)

In general the pre & post hooks should be called but there are some places in the code where the relevant add / create functions are skipped (eg direct sql / dao class)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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 postProcess no longer sufficient since edit-in-place?
October 08, 2012, 04:24:24 pm

it also calls the postProcess hook, but for the Inline forms :)

CRM/Contact/Form/Inline/*.php

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

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: Hook postProcess no longer sufficient since edit-in-place?
October 09, 2012, 12:18:24 am
I will have a go with that Lobo, and if I get the postProcess hook from the Inline form it will solve my issue. From a conceptual point of view, should it not call the civicrm_post hook anyway though?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Hook postProcess no longer sufficient since edit-in-place?
October 09, 2012, 01:24:31 am
@Eileen, thanks! Made me feel much better (although a warm beer did help too)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Hook postProcess no longer sufficient since edit-in-place?
October 09, 2012, 04:31:33 am
Discussing this briefly with Michael McAndrew and we thought the following approach might be best:

in the appropriate spot in the code (which is directly after the DB action for email or phone has been done) we do a API Email Get or Phone Get, and expose the returned values from the API to the _post hook. This seems to us a fairly straightforward approach that is easy to duplicate at several spots in the CiviCRM code if required.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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 postProcess no longer sufficient since edit-in-place?
October 09, 2012, 09:57:33 am

1. yes the post hook should also be called in addition to the postProcess hook

2. I'd vote a -1 to do a get on a record before calling the hook. Making yet another DB call for all save operations is expensive and makes things slower. The hook implementor should decide what info they want and make the right DB calls

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

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: Hook postProcess no longer sufficient since edit-in-place?
October 09, 2012, 10:00:27 am
Agree on the making things slower, but that is assuming all required data is there. This is the case in the current way of implementing hooks, and all required data is available either in the form or in the object. Will have a look into it and check back, point taken.
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Hook postProcess no longer sufficient since edit-in-place?
October 15, 2012, 05:33:44 am
Lobo,
the Inline Email does NOT call the postProcess hook as far as I can establish on 4.2.2. Here is my little bit of code that gives me no debug whatsoever:
Code: [Select]
function silcivi_civicrm_postProcess($formName, &$form) {
if ( $formName != "CRM_Contact_Form_Search_Basic") {

CRM_Core_Error::debug("formName", $formName );
CRM_Core_Error::debug("form", $form );
exit();
}
}
When I delete an email address using the edit-in-place, I do not get to this point.
I have changed the postProcess for CRM/Contact/Form/Inline/Email.php to:
Code: [Select]
  public function postProcess() {
    $params = $this->exportValues();

    // need to process / save emails
    $params['contact_id'] = $this->_contactId;
    $params['updateBlankLocInfo'] = TRUE;

    // save email changes
    CRM_Core_BAO_Block::create('email', $params);
    // temp Erik Hommel
    CRM_Utils_Hook::postProcess( "CRM_Contact_Form_Inline_Email", $this );

    // make entry in log table
    CRM_Core_BAO_Log::register( $this->_contactId,
      'civicrm_contact',
      $this->_contactId
    );

    $response = array('status' => 'save');
    echo json_encode($response);
    CRM_Utils_System::civiExit();
  }
So it now calls the postProcess hook. I will do the same to my Phone.php. Do you want me to raise an issue and commit these changes?
« Last Edit: October 15, 2012, 05:45:54 am by Erik Hommel »
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: Hook postProcess no longer sufficient since edit-in-place?
October 15, 2012, 06:26:45 am
Hey,

But if the post hook on email/phone was working, could you use it instead of postProcess?

Given that we will have more an more UI that don't go through the normal form, we should try to get the post working in all the cases, and use this one instead of PostProcess in most of the cases, Me think.

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: Hook postProcess no longer sufficient since edit-in-place?
October 15, 2012, 06:33:32 am
I agree that the post should be working. The problem is that it is not working for the email and phone either :-) It should if I look at the Block processing but somehow it does not. So if it becomes a core issue, we should really fix it in the Block and get the _post working. I was just doing this as a temp hack because I need the hook to get any further. I will come back to the issue once I have at least a temp solution for the project :-)
« Last Edit: October 15, 2012, 06:37:24 am by Erik Hommel »
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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: Hook postProcess no longer sufficient since edit-in-place?
October 15, 2012, 06:46:20 am
If we are going to use the post, which makes sense, we would expect an 'create', 'edit' or 'delete' in the $op parameter, which is not the way in which the Block processing seems to happen. In the Block idea you repace the total picture of phones or emails with the new picture in one go. In theory, that would result in multiple calls of the post hook as it deals with one entity at a time?
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: Hook postProcess no longer sufficient since edit-in-place?
October 15, 2012, 06:54:25 am
Quote from: Erik Hommel on October 15, 2012, 06:46:20 am
If we are going to use the post, which makes sense, we would expect an 'create', 'edit' or 'delete' in the $op parameter, which is not the way in which the Block processing seems to happen. In the Block idea you repace the total picture of phones or emails with the new picture in one go. In theory, that would result in multiple calls of the post hook as it deals with one entity at a time?

Are you sure? Seems to be a pretty suboptimal implementation.

From a user pov (as in, haven't looked at the code might be far away), I'd expect one create for each new phone, or edit for each modified phone and one delete for each deleted phone.

But if the implementation deletes everything, it would be coherent to have n delete followed by n create
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Hook postProcess no longer sufficient since edit-in-place?

This forum was archived on 2017-11-26.