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) »
  • Argh - surveys
Pages: [1]

Author Topic: Argh - surveys  (Read 567 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Argh - surveys
May 29, 2011, 09:20:24 pm
It looks like instead of using the BAO:add or create functions the survey implementation bypasses the BAO & goes straight to the DAO - which means no hooks are called!

Arrghh - I think I've been going backwards for days.
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Argh - surveys
May 30, 2011, 02:58:34 am
Yeap, the pre/post hooks should be in the DAO to avoid all that.

What about

1) the hook is modified to set a $already_called [$hook][$action][$objectName][] = $id

and add in the DAO.php in the functions that test if the BAO has properly called the hook and calls it if not:

if (empty ( $already_called [$hook][$action][$objectName][$id])) {
        require_once 'CRM/Utils/Hook.php';
        CRM_Utils_Hook::pre( 'delete', 'Tag', $id, $tag );

        if ( $tag->delete( ) ) {
            CRM_Utils_Hook::post( 'delete', 'Tag', $id, $tag );
            CRM_Core_Session::setStatus( ts('Selected Tag has been Deleted Successfuly.') );
            return true;
        }


I'm not a big fan of yet another global variable, but we can't rely because some BAO don't use the parent DAO function but instanciate a new DAO (for some reason), eg for Tag BAO:


Code: [Select]
    static function del ( $id ) {
...

        // delete from tag table
        $tag = new CRM_Core_DAO_Tag( );
        $tag->id = $id;

        require_once 'CRM/Utils/Hook.php';
        CRM_Utils_Hook::pre( 'delete', 'Tag', $id, $tag );

        if ( $tag->delete( ) ) {
            CRM_Utils_Hook::post( 'delete', 'Tag', $id, $tag );
            CRM_Core_Session::setStatus( ts('Selected Tag has been Deleted Successfuly.') );
            return true;
        }
        return false;



The DAO has only the _tableName (eg. civicrm_tag), but I'm assuming that's trivial to add the name of the Entity/$objectName .

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Argh - surveys
May 30, 2011, 05:01:33 am
I stuck a hook in there where it is required for now.

Ideally it would be refactored to use the create function. Even more ideally it would just use a native api rest url for the ajax call since I think what is there would probably be supported but I don't have time to do either of those right now & your suggestion will have to be 4.1 anyway
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Argh - surveys

This forum was archived on 2017-11-26.