#781 run_hook in hooks.php doesn't call custom hooks

1.1.x
closed
nobody
None
5
2012-09-06
2008-02-15
Ryan Lane
No

It seems it doesn't get the hooks array properly. The following seems to fix it (and makes the function look similar to the rest of the file):

--- hooks.php.old 2008-02-15 09:06:31.000000000 -0600
+++ hooks.php 2008-02-15 09:07:03.000000000 -0600
@@ -50,7 +50,9 @@
* @return true if all procedures returned true, false otherwise.
*/
function run_hook($hook_name,$args) {
- $hooks = isset($_SESSION[APPCONFIG]) ? $_SESSION[APPCONFIG]->hooks : array();
+ global $config;
+
+ $hooks = $config->hooks;

    $debug = 0;
    syslog_debug("Running hook $hook_name.");

Discussion

  • Deon George
    Deon George
    2008-03-01

    Logged In: YES
    user_id=417635
    Originator: NO

    You shouldnt need to do this - what hooks call are you making (and thus failing)? Can you give me steps to reproduce this...

    $_SESSION[APPCONFIG] == $config when config is finished initialisation.

     
  • Ryan Lane
    Ryan Lane
    2008-03-03

    Logged In: YES
    user_id=1541781
    Originator: YES

    Steps to reproduce:

    1. create file: hooks/functions/custom_functions.php
    2. Add hooks and functions in previously created file:

    Function to change the user's homeDirectory attribute when we change their uid

    function modifyHomeDirectoryOnUIDChange( $server_id, $old_dn, $new_rdn ) {
    global $ldapserver;

        //is this a user?
        if ( preg_match( "/^uid=(\w+),/", $old_dn, $old_user_name ) ) {
    
                //get the uid without the syntax
                $old_uid = $old_user_name[1];
                $new_uid = $new_rdn;
    
                $homedir = $ldapserver->getDNAttr( $old_dn, 'homeDirectory', false );
                $update_array["homeDirectory"] = preg_replace("/" . $old_uid . "/", $new_uid, $homedir);
    
                $res = $ldapserver->modify( $old_dn, $update_array );
    
                //Sanity check
                if ( $homedir == '' ) {
                        pla_error(_('homeDirectory attribute was empty, cowardly refusing to modify attribute.'));
    
                        return false;
    
                }
    
                //did it succeed?
                if ( $res ) {
                        echo "Modified the user's home directory: $homedir<br/>";
                } else {
                        pla_error(_('Could not perform ldap_modify operation on homeDirectory attribute.'),$ldapserver->error(),$ldapserver->errno());
    
                        return false;
                }
        } //end if
    
        return true;
    

    } //end function

    // the rest of the functions go here...

    add_hook( 'pre_rename_entry', 1, 'modifyHomeDirectoryOnUIDChange', false );
    // the rest of the hooks go here...

    1. Check hook to see if it works.
     
  • Deon George
    Deon George
    2008-11-28

    A fix was submitted to CVS for this (in BRANCH-1_1_0):

    lib/common.php 1.80.2.14
    lib/functions.php 1.303.2.29
    lib/hooks.php 1.10.2.3