[phpldapadmin] [ phpldapadmin-Bugs-1894498 ] run_hook in hooks.php doesn't call custom hooks

"SourceForge.net" <[email protected]>
Newsgroups gmane.comp.ldap.davedap
Message-ID <[email protected]>
Bugs item #1894498, was opened at 2008-02-16 02:07
Message generated for change (Settings changed) made by wurley
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=498546&aid=1894498&group_id=61828

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: 1.1.x
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Ryan Lane (rlane32)
Assigned to: Nobody/Anonymous (nobody)
Summary: run_hook in hooks.php doesn't call custom hooks

Initial Comment:
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.");


----------------------------------------------------------------------

>Comment By: Deon George (wurley)
Date: 2008-11-28 15:45

Message:
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

----------------------------------------------------------------------

Comment By: Ryan Lane (rlane32)
Date: 2008-03-04 06:17

Message:
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...

3. Check hook to see if it works.

----------------------------------------------------------------------

Comment By: Deon George (wurley)
Date: 2008-03-01 12:41

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=498546&aid=1894498&group_id=61828

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
______________________________________
phpLDAPadmin development mailing list.
To unsbuscribe: https://lists.sourceforge.net/lists/listinfo/phpldapadmin-devel
http://phpldapadmin.sourceforge.net/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.