Forums / Developer / pb with ldapusermanage.php on ldap contrib

pb with ldapusermanage.php on ldap contrib

Author Message

Artturi Markko

Friday 26 May 2006 4:11:36 pm

Hello,

I have recently added a different way to map ldap groups to ez groups.
(see post http://ez.no/community/forum/developer/contrib_ldap_group_mappings)

It worked well on EZ 3.7.5 but I just upgraded to 3.8.0 and I get a "Fatal Error" message while running my modified ldapusermanage.php

Problem occurs when reaching this code

$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userID,
                                                                                             'version' => $newVersionNr ) );

at the end of the script.

As this is shared with the original code, I wondered if there could be something obvious an ez developper could see.
Any help would be greatly appreciated.

Thanks in advance,

Artturi

ldapusermanage2.php

<?php
//
// Definition of Ldapusermanage class
//
// Created on: <28-Jul-2003 15:12:08 wy>
//
// SOFTWARE NAME: eZ publish
// SOFTWARE RELEASE: 3.8.0
// BUILD VERSION: 15960
// COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
//   This program is free software; you can redistribute it and/or
//   modify it under the terms of version 2.0  of the GNU General
//   Public License as published by the Free Software Foundation.
// 
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
// 
//   You should have received a copy of version 2.0 of the GNU General
//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
//
//

/*! \file ldapusermanage.php
*/
function mapInEzGroups($filter, $LDAPBaseDN, &$ds, &$db, &$ldap2ez, &$extraNodeAssignments, $depth = 0)
{
    $retrieve = array("cn");
    $sr2 = ldap_search( $ds, $LDAPBaseDN, $filter, $retrieve );
    $info2 = ldap_get_entries( $ds, $sr2 );       
                           
    $newfilter = '(&(objectClass=group)(|';
    $max = count($info2);
    for ( $i = 0; $i < $max; $i++ )
    {
        if ( is_null( $info2[ $i ] ) ) continue;
        $ldapGroupName = $info2[$i]['cn'][0];
        if ( array_key_exists($ldapGroupName, $ldap2ez) )
        {
            $groupName = $ldap2ez[$ldapGroupName];
            $groupQuery = "SELECT ezcontentobject_tree.node_id
                             FROM ezcontentobject, ezcontentobject_tree
                            WHERE ezcontentobject.name like '$groupName'
                              AND ezcontentobject.id=ezcontentobject_tree.contentobject_id
                              AND ezcontentobject.contentclass_id=3";
            $groupObject = $db->arrayQuery( $groupQuery );

            if ( count( $groupObject ) > 0 )
            {
                $extraNodeAssignments[] = $groupObject[0]['node_id'];
            }
        }        
        $newfilter .= '(member=' . $info2[$i]['dn']  . ')';                        
    }
    if ( $depth < 30 && $max > 0 )
    {    
        $newfilter .= '))';
        mapInEzGroups($newfilter, $LDAPBaseDN, $ds, $db, $ldap2ez, $extraNodeAssignments, ( $depth + 1));
    }    
}

include_once( "lib/ezutils/classes/ezmodule.php" );
include_once( "lib/ezdb/classes/ezdb.php" );
include_once( 'lib/ezutils/classes/ezini.php' );
include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
include_once( 'kernel/classes/datatypes/ezuser/ezusersetting.php' );
include_once( 'kernel/classes/ezcontentobject.php' );
$user = eZUser::fetchByName('admin');
eZUser::setCurrentlyLoggedInUser( $user, $user->attribute( 'contentobject_id' ) );

eZModule::setGlobalPathList( array( "kernel" ) );
if ( !$isQuiet )
    $cli->output( "Checking LDAP users ..."  );
$db =& eZDB::instance();
$query = "SELECT contentobject_id, login
          FROM ezcontentobject, ezuser
          WHERE remote_id like 'LDAP%'
          AND ezcontentobject.id=contentobject_id";
$LDAPUsers = $db->arrayQuery( $query );
$ini =& eZINI::instance();
$LDAPIni =& eZINI::instance( 'ldap.ini' );
$LDAPVersion = $LDAPIni->variable( 'LDAPSettings', 'LDAPVersion' );
$LDAPHost = $LDAPIni->variable( 'LDAPSettings', 'LDAPServer' );
$LDAPPort = $LDAPIni->variable( 'LDAPSettings', 'LDAPPort' );
$LDAPBaseDN = $LDAPIni->variable( 'LDAPSettings', 'LDAPBaseDn' );
$LDAPBindUser = $LDAPIni->variable( 'LDAPSettings', 'LDAPBindUser' );
$LDAPBindPassword = $LDAPIni->variable( 'LDAPSettings', 'LDAPBindPassword' );
$LDAPLogin = $LDAPIni->variable( 'LDAPSettings', 'LDAPLoginAttribute' );
$LDAPSearchScope = $LDAPIni->variable( 'LDAPSettings', 'LDAPSearchScope' );
$LDAPFirstNameAttribute = $LDAPIni->variable( 'LDAPSettings', 'LDAPFirstNameAttribute' );
$LDAPLastNameAttribute = $LDAPIni->variable( 'LDAPSettings', 'LDAPLastNameAttribute' );
$LDAPEmailAttribute = $LDAPIni->variable( 'LDAPSettings', 'LDAPEmailAttribute' );
$LDAPUserGroupAttributeType = $LDAPIni->variable( 'LDAPSettings', 'LDAPUserGroupAttributeType' );
$LDAPUserGroupAttribute = $LDAPIni->variable( 'LDAPSettings', 'LDAPUserGroupAttribute' );
$LDAPUserGroupAML = $LDAPIni->variable( 'LDAPSettings', 'LDAPUserGroupAML' );
if ( $LDAPIni->hasVariable( 'LDAPSettings', 'LDAPSearchFilters' ) )
{
    $LDAPFilters = $LDAPIni->variable( 'LDAPSettings', 'LDAPSearchFilters' );
}
if ( $LDAPIni->hasVariable( 'LDAPSettings', 'LDAPUserGroupType' ) and  $LDAPIni->hasVariable( 'LDAPSettings', 'LDAPUserGroup' ) )
{
    $LDAPUserGroupType = $LDAPIni->variable( 'LDAPSettings', 'LDAPUserGroupType' );
    $LDAPUserGroup = $LDAPIni->variable( 'LDAPSettings', 'LDAPUserGroup' );
}

if ( $LDAPIni->hasVariable( 'LDAPSettings', 'Utf8Encoding' ) )
{
    $Utf8EncodingSetting = $LDAPIni->variable( 'LDAPSettings', 'Utf8Encoding' );
    if ( $Utf8EncodingSetting == "true" )
        $isUtf8Encoding = true;
    else
        $isUtf8Encoding = false;
}
else
{
    $isUtf8Encoding = false;
}

$LDAPEqualSign = trim($LDAPIni->variable( 'LDAPSettings', "LDAPEqualSign" ) );
$LDAPBaseDN = str_replace( $LDAPEqualSign, "=", $LDAPBaseDN );


$attributeArray = array( $LDAPFirstNameAttribute,
                         $LDAPLastNameAttribute,
                         $LDAPEmailAttribute );

$defaultUserPlacement = $ini->variable( "UserSettings", "DefaultUserPlacement" );


//connect to LDAP server
$ds = ldap_connect( $LDAPHost, $LDAPPort );
if ( $ds )
{
    ldap_set_option( $ds, LDAP_OPT_PROTOCOL_VERSION, $LDAPVersion );
    if ( $LDAPBindUser == '' )
    {
        $r = ldap_bind( $ds );
    }
    else
    {
        $r = ldap_bind( $ds, $LDAPBindUser, $LDAPBindPassword );
    }
    if ( !$r )
    {
        return false;
    }
    ldap_set_option( $ds, LDAP_OPT_SIZELIMIT, 0 );
    ldap_set_option( $ds, LDAP_OPT_TIMELIMIT, 0 );
}
else
{
    return false;
}

$db->begin();
foreach ( array_keys ( $LDAPUsers ) as $key )
{
    $LDAPUser =& $LDAPUsers[$key];
    
    $login = $LDAPUser['login'];
    $userID = $LDAPUser['contentobject_id'];

echo "a"; 

    $LDAPFilter = "( &";
    if ( count( $LDAPFilters ) > 0 )
    {
        foreach ( array_keys( $LDAPFilters ) as $key )
        {
            $LDAPFilter .= "(" . $LDAPFilters[$key] . ")";
        }
    }
    $LDAPFilter .= "($LDAPLogin=$login)";
    $LDAPFilter .= ")";
    $LDAPFilter = str_replace( $LDAPEqualSign, "=", $LDAPFilter );
    if ( $LDAPSearchScope == "one" )
        $sr = ldap_list( $ds, $LDAPBaseDN, $LDAPFilter, $attributeArray );
    else if ( $LDAPSearchScope == "base" )
        $sr = ldap_read( $ds, $LDAPBaseDN, $LDAPFilter, $attributeArray );
    else
        $sr = ldap_search( $ds, $LDAPBaseDN, $LDAPFilter, $attributeArray );
    $info = ldap_get_entries( $ds, $sr );
    if ( $info["count"] != 1 )
    {
        $cli->output( "Disable user " . $cli->stylize( 'emphasize', $login ) );
        // Disable the user
        $userSetting = eZUserSetting::fetch( $userID );
        $userSetting->setAttribute( "is_enabled", false );
        $userSetting->store();
    }
    else
    {
        echo "b";
        // Update user information
        $contentObject =& eZContentObject::fetch( $userID );

        $parentNodeID = $contentObject->attribute( 'main_parent_node_id' );
        $currentVersion = $contentObject->attribute( 'current_version' );

        $version =& $contentObject->attribute( 'current' );
        $contentObjectAttributes =& $version->contentObjectAttributes();

        if ( $isUtf8Encoding )
        {
            $firstName = utf8_decode( $info[0][$LDAPFirstNameAttribute][0] );
            $lastName = utf8_decode( $info[0][$LDAPLastNameAttribute][0] );
            $ldapEMail = utf8_decode( $info[0][$LDAPEmailAttribute][0] );
        }
        else
        {
            $firstName = $info[0][$LDAPFirstNameAttribute][0];
            $lastName = $info[0][$LDAPLastNameAttribute][0];
            $ldapEMail = $info[0][$LDAPEmailAttribute][0];
        }

        $contentObjectAttributes[0]->setAttribute( 'data_text', $firstName );
        $contentObjectAttributes[0]->store();

        $contentObjectAttributes[1]->setAttribute( 'data_text', $lastName );
        $contentObjectAttributes[1]->store();

        $contentClass =& $contentObject->attribute( 'content_class' );
        $name = $contentClass->contentObjectName( $contentObject );
        $contentObject->setName( $name );

        $existUser = eZUser::fetch(  $userID );
        $existUser->setAttribute('email', $ldapEMail );
        $existUser->setAttribute('password_hash', "" );
        $existUser->setAttribute('password_hash_type', 0 );
        $existUser->store();

        // If user has changed to another group, update it.
        if ( $LDAPUserGroupAML != null )
        {
            $republishRequired = false;
            $IsLDAPMain = true;
            $hasOtherNodeType = false;
            $hasLDAPNodeType = false;
            $otherNodeArray = array();
            $LDAPNodeArray = array();
            $newLDAPNodeArray = array();
            $parentNodes =& $contentObject->parentNodes( $currentVersion );  
echo "c";

            foreach(  array_keys( $parentNodes ) as $key )
            {
                $parentNode =& $parentNodes[$key];
                $parentNodeID = $parentNode->attribute( 'node_id' );                              
                $parentNodeName = $parentNode->attribute( 'name' );                
                $nodeAssignment = eZNodeAssignment::fetch( $contentObject->attribute( 'id' ), $currentVersion, $parentNodeID );                
              
                $isMain = $nodeAssignment->attribute( 'is_main' );                
                $remoteID = $nodeAssignment->attribute( 'parent_remote_id' );
                if ( preg_match( "/LDAP/i", $remoteID ) )
                {
                    $LDAPNodeArray[] = array( 'parent_node_name' => $parentNodeName, 'parent_node_id' => $parentNodeID, 'is_main' => $isMain );
                }
                else
                {
                    $otherNodeArray[] = array( 'parent_node_name' => $parentNodeName, 'parent_node_id' => $parentNodeID, 'is_main' => $isMain );
                    $hasOtherNodeType = true;
                    if ( $isMain )

                    {
                        $IsLDAPMain = false;
                    }
                }
                  
            }
            echo "d";
             
            foreach ( $LDAPUserGroupAML as $value)
            {
                $r = explode("--", $value);
                $ldap2ez[$r[0]] = $r[1];
            }

           
            $extraNodeAssignments = array();
            $LDAPUserGroupCount = count( $LDAPNodeArray );         

            $filter = "(&(objectClass=group)(member=" . $info[0]['dn'] . "))";

            mapInEzGroups($filter, $LDAPBaseDN, $ds, $db, $ldap2ez, $extraNodeAssignments);
            $groupCount = count( $extraNodeAssignments );    
            echo "e";
            for ( $i = 0; $i < $groupCount; $i++ )
            {
                $exist = false;
                foreach( $LDAPNodeArray as $LDAPNode )
                {
                    $existGroupName = $LDAPNode['parent_node_name'];
                    $existGroupID = $LDAPNode['parent_node_id'];
                    if ( strcasecmp( $existGroupID, $extraNodeAssignments[$i] )  == 0 )
                    {
                        $exist = true;
                        $hasLDAPNodeType = true;
                        if ( $IsLDAPMain and count( $newLDAPNodeArray ) == 0 )
                        {
                            $newLDAPNodeArray[] = array( 'parent_node_name' => $existGroupName, 'parent_node_id' => $existGroupID, 'is_main' => 1 );
                        }
                        else
                        {
                            $newLDAPNodeArray[] = array( 'parent_node_name' => $existGroupName, 'parent_node_id' => $existGroupID, 'is_main' => 0 );
                        }
                        $LDAPUserGroupCount--;
                    }
                }

                if ( $exist == false )
                {
                    $groupQuery = "SELECT ezcontentobject.name
                             FROM ezcontentobject, ezcontentobject_tree
                            WHERE ezcontentobject_tree.node_id=$extraNodeAssignments[$i]
                              AND ezcontentobject.id=ezcontentobject_tree.contentobject_id
                              AND ezcontentobject.contentclass_id=3";
                    $groupObject = $db->arrayQuery( $groupQuery );

                    if ( count( $groupObject ) > 0 )
                    {
                        $hasLDAPNodeType = true;
                        if ( $IsLDAPMain and count( $newLDAPNodeArray ) == 0 )
                        {
                            $newLDAPNodeArray[] = array( 'parent_node_name' =>  $groupObject[0]['name'], 'parent_node_id' =>  $extraNodeAssignments[$i], 'is_main' => 1 );
                        }
                        else
                        {
                            $newLDAPNodeArray[] = array( 'parent_node_name' =>  $groupObject[0]['name'], 'parent_node_id' =>  $extraNodeAssignments[$i], 'is_main' => 0 );
                        }
                        $republishRequired = true;
                    }
                }
            }    
            echo "f";            

            if ( $LDAPUserGroupCount != 0 )
            {
                $republishRequired = true;
            }
            

            if ( $republishRequired )
            {
                $newVersion = $contentObject->createNewVersion();
                $newVersionNr = $newVersion->attribute( 'version' );
                $nodeAssignmentList =& $newVersion->attribute( 'node_assignments' );
                echo "f1";
                
                foreach ( array_keys( $nodeAssignmentList ) as $key  )
                {
                    $nodeAssignment =& $nodeAssignmentList[$key];
                    $nodeAssignment->remove();
                }
                echo "f2";
                if ( $hasOtherNodeType )
                {
                    foreach ( $otherNodeArray as $otherNode )
                    {
                        $newVersion->assignToNode( $otherNode['parent_node_id'], $otherNode['is_main'] );
                    }
                }
                
                echo "f3";

                if ( $hasLDAPNodeType )
                {
                    foreach ( $newLDAPNodeArray as $newLDAPNode )
                    {
                        $newVersion->assignToNode( $newLDAPNode['parent_node_id'], $newLDAPNode['is_main'] );
                        $assignment = eZNodeAssignment::fetch( $contentObject->attribute( 'id' ), $newVersionNr, $newLDAPNode['parent_node_id'] );
                        $assignment->setAttribute( 'parent_remote_id', "LDAP_" . $newLDAPNode['parent_node_id'] );
                        $assignment->store();
                    }
                }
                echo "f4";
                if ( !$hasOtherNodeType and !$hasLDAPNodeType )
                {
                    $newVersion->assignToNode( $defaultUserPlacement, 1 );
                }
                echo "f5";
                var_dump($userID, $newVersionNr);
                var_dump($newVersion);
                include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
                $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $userID,
                                                                                             'version' => $newVersionNr ) );
                
                echo "f6";                                                                                             
                $cli->output( $cli->stylize( 'emphasize', $existUser->attribute('login') ) . " has changed group, updated." );
            }
            echo "g";
        }
    }
}

$db->commit();

if ( !$isQuiet )
    $cli->output( "All LDAP users have been updated!" );
?>

Kristof Coomans

Saturday 27 May 2006 1:39:49 am

Hi Markko

Can you give us the exact error message you got? Thank you.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Artturi Markko

Saturday 27 May 2006 6:36:22 am

With debug activated, here's the output I get :


C:\applisweb\ezpublish\ezpublish>rem se placer dans le répertoire ou se trouve le fichier runcronjobs.php 

C:\applisweb\ezpublish\ezpublish>cd C:\applisweb\ezpublish\ezpublish 

C:\applisweb\ezpublish\ezpublish>C:\applisweb\ezpublish\php\php.exe runcronjobs.php -d 
Running cronjobs/workflow.php
Checking for workflow processes
Status list

0 out of 0 processes was finished

Running cronjobs/notification.php
Starting notification event processing
Done

Running cronjobs/unpublish.php

Running cronjobs/rssimport.php

Running cronjobs/indexcontent.php
Starting processing pending search engine modifications
Done

Running cronjobs/hide.php

Running cronjobs/subtreeexpirycleanup.php

Running cronjobs/ldapusermanage2.php
Checking LDAP users ...
abcdeff1f2f3f4f5string(2) "79"
string(1) "8"
object(ezcontentobjectversion)(18) {
  ["PersistentDataDirty"]=>
  bool(false)
  ["CurrentLanguage"]=>
  bool(false)
  ["ContentObjectAttributeArray"]=>
  bool(false)
  ["DataMap"]=>
  bool(false)
  ["TempNode"]=>
  NULL
  ["VersionName"]=>
  NULL
  ["VersionNameCache"]=>
  array(0) {
  }
  ["ID"]=>
  int(1051)
  ["ContentObjectID"]=>
  &string(2) "79"
  ["CreatorID"]=>
  string(2) "14"
  ["Version"]=>
  &string(1) "8"
  ["Status"]=>
  &int(0)
  ["Created"]=>
  int(1148737176)
  ["Modified"]=>
  int(1148737176)
  ["WorkflowEventPos"]=>
  string(1) "0"
  ["UserID"]=>
  string(1) "0"
  ["LanguageMask"]=>
  int(3)
  ["InitialLanguageID"]=>
  string(1) "2"
}
Fatal error: eZ publish did not finish its request
The execution of eZ publish was abruptly ended, the debug output is present below.

Notice: (eZMySQLDB::query(0.000 ms) query number per page:0)
SET NAMES 'latin1'

Timing: ()
Script cronjobs/workflow.php starting

Timing: ()
Script cronjobs/workflow.php done

Timing: ()
Script cronjobs/notification.php starting

Warning: (ezi18n)
No translation for file(translation.ts) in context(lib/template): 'The maximum nesting level of 40 has been reached. The execution is stopped to avoid infinite recursion.' with comment()

Timing: ()
Script cronjobs/notification.php done

Timing: ()
Script cronjobs/unpublish.php starting

Timing: ()
Script cronjobs/unpublish.php done

Timing: ()
Script cronjobs/rssimport.php starting

Timing: ()
Script cronjobs/rssimport.php done

Timing: ()
Script cronjobs/indexcontent.php starting

Timing: ()
Script cronjobs/indexcontent.php done

Timing: ()
Script cronjobs/hide.php starting

Timing: ()
Script cronjobs/hide.php done

Timing: ()
Script cronjobs/subtreeexpirycleanup.php starting

Timing: ()
Script cronjobs/subtreeexpirycleanup.php done

Timing: ()
Script cronjobs/ldapusermanage2.php starting

Warning: (ezi18n)
No translation for file(translation.ts) in context(kernel/classes/datatypes): 'Text block' with comment(Datatype name)

Warning: (PHP)
Undefined offset:  6 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  5 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  1 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined offset:  0 in C:\applisweb\ezpublish\ezpublish\lib\ezutils\ldapgroups.php on line 21

Warning: (PHP)
Undefined index:  status in C:\applisweb\ezpublish\ezpublish\lib\ezutils\classes\ezmoduleoperationinfo.php on line 515

Warning: (PHP)
Undefined index:  status in C:\applisweb\ezpublish\ezpublish\lib\ezutils\classes\ezmoduleoperationinfo.php on line 515

Warning: (PHP)
Undefined index:  status in C:\applisweb\ezpublish\ezpublish\lib\ezutils\classes\ezmoduleoperationinfo.php on line 515

Warning: (PHP)
Undefined index:  status in C:\applisweb\ezpublish\ezpublish\lib\ezutils\classes\ezmoduleoperationinfo.php on line 515

Warning: (PHP)
Undefined index:  status in C:\applisweb\ezpublish\ezpublish\lib\ezutils\classes\ezmoduleoperationinfo.php on line 515

Warning: (ezi18n)
No translation for file(translation.ts) in context(kernel/workflow/event): 'Payment Gateway' with comment()

Script cronjobs/workflow.php starting 0.0000 sec0.2191 sec
Script cronjobs/workflow.php done 0.2191 sec0.0003 sec
Script cronjobs/notification.php starting 0.2195 sec0.1587 sec
Script cronjobs/notification.php done 0.3781 sec0.0004 sec
Script cronjobs/unpublish.php starting 0.3785 sec0.0112 sec
Script cronjobs/unpublish.php done 0.3898 sec0.0003 sec
Script cronjobs/rssimport.php starting 0.3901 sec0.0300 sec
Script cronjobs/rssimport.php done 0.4201 sec0.0005 sec
Script cronjobs/indexcontent.php starting 0.4206 sec0.0066 sec
Script cronjobs/indexcontent.php done 0.4272 sec0.0004 sec
Script cronjobs/hide.php starting 0.4276 sec0.0015 sec
Script cronjobs/hide.php done 0.4291 sec0.0004 sec
Script cronjobs/subtreeexpirycleanup.php starting 0.4295 sec0.0150 sec
Script cronjobs/subtreeexpirycleanup.php done 0.4445 sec0.0003 sec
Script cronjobs/ldapusermanage2.php starting 0.4448 sec
Total runtime: 2.6638 sec
Group ini_load: 
Load cache: 0.0598 sec (2.1808%), 0.0035 avg sec (17)
FindInputFiles: 0.0268 sec (0.9785%), 0.0016 avg sec (17)
Group Mysql Total: 
Mysql_queries: 0.3541 sec (12.9106%), 0.0008 avg sec (428)
Looping result: 0.0246 sec (0.8962%), 0.0001 avg sec (208)
Group TS translator: 
TS init: 0.0239 sec (0.8725%), 0.0080 avg sec (3)
TS cache load: 0.0125 sec (0.4547%), 0.0042 avg sec (3)
TS context load: 0.0085 sec (0.3112%), 0.0028 avg sec (3)
Group class_abstraction: 
Instantiating content class attribute: 0.1071 sec (3.9059%), 0.0016 avg sec (65)
Group : 
Check cache: 0.1066 sec (3.8875%), 0.0107 avg sec (10)
Node cleanup: 0.0149 sec (0.5446%), 0.0050 avg sec (3)
Generating view cache: 0.0124 sec (0.4511%), 0.0124 avg sec (1)
Group XML: 
Image XML parsing: 0.0075 sec (0.2744%), 0.0075 avg sec (1)
Group Search Total: 
remove object: 0.0013 sec (0.0492%), 0.0013 avg sec (1)
add object: 0.0000 sec (0.0000%), 0.0000 avg sec (0)
Group General: 
dbfile: 0.0061 sec (0.2235%), 0.0003 avg sec (20)
String conversion: 0.0003 sec (0.0122%), 0.0003 avg sec (1)
String conversion w/ mbstring: 0.0001 sec (0.0055%), 0.0001 avg sec (1)

Total script time: 2.7426 sec

Artturi

Kristof Coomans

Sunday 28 May 2006 1:32:36 am

Hi Artturi

Can you give us the fatal error message?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Artturi Markko

Sunday 28 May 2006 5:20:20 am

Hello Kristof,

I've added the "Fatal Error" message to the previous output.
However, it does not provide much useful informations...

I've followed the execution of the code and if I'm correct, it fails when reaching lib/ezutils/classes/ezmoduleoperationinfo.php, method "callClassMethod"
I've added

var_dump($this->UseOldCall, $classObject, $methodName, $parameterArray);

and it outputs :

bool(false)
object(ezcontentoperationcollection)(0) {
}
string(20) "registerSearchObject"
array(2) {
  [0]=>
  string(2) "79"
  [1]=>
  string(1) "8"
}

Fatal error: eZ publish did not finish its request
The execution of eZ publish was abruptly ended, the debug output is present below.

Artturi

Kristof Coomans

Sunday 28 May 2006 6:17:08 am

Mh strange...

Do you see any error messages in the error log?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Artturi Markko

Sunday 28 May 2006 7:00:58 am

Php's error log file gets this while executing the cronjob :

[28-May-2006 15:57:56] PHP Fatal error: Call to a member function on a non-object in C:\applisweb\ezpublish\ezpublish\kernel\search\plugins\ezsearchengine\ezsearchengine.php on line 74

I edited ezsearchengine.php and added this before line 74 :

        eZContentObject::recursionProtectionStart();
        echo "here";
        var_dump(get_class($contentObject), $currentVersion);

giving this output :

Checking LDAP users ...
herestring(15) "ezcontentobject"
bool(false)

Fatal error: eZ publish did not finish its request

Artturi Markko

Sunday 28 May 2006 1:37:43 pm

I thought I could get rid of this "Fatal Error" by removing the user that was concerned from EZ.
Now, I get the same kind of error for the others :

[28-May-2006 22:33:24] PHP Fatal error:  Call to a member function on a non-object in C:\applisweb\ezpublish\ezpublish\cronjobs\ldapusermanage2.php on line 223

line 223 is in bold :
foreach( array_keys( $parentNodes ) as $key )
{
$parentNode =& $parentNodes[$key];
$parentNodeID = $parentNode->attribute( 'node_id' );
$parentNodeName = $parentNode->attribute( 'name' );
$nodeAssignment = eZNodeAssignment::fetch( $contentObject->attribute( 'id' ), $currentVersion, $parentNodeID );

$isMain = $nodeAssignment->attribute( 'is_main' );
<b> $remoteID = $nodeAssignment->attribute( 'parent_remote_id' );</b>

Kristof Coomans

Sunday 28 May 2006 11:46:20 pm

I think your node tree is corrupted. Did you run the script on the same site, before you fixed the bug mentioned in this topic: http://ez.no/community/forum/developer/node_group_assignment_how_to_remove_correctly ?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Artturi Markko

Monday 29 May 2006 1:45:47 am

I'm thinking about this possibility too (having seen some inconsistencies in the "Users" section). I have indeed run the script before the bug was corrected (but the script runs fine on 3.7.5).

I'll test the script on a clean 3.8.0 install and keep you informed.

Thanks for your help.

Artturi

Artturi Markko

Monday 29 May 2006 12:42:06 pm

Hello Kristof,

I've just started from a new database and at first, things worked fine.
However, after some simple manipulations, I got the "Fatal error" again :-(

PHP Fatal error:  Call to a member function on a non-object in C:\[snip]kernel\search\plugins\ezsearchengine\ezsearchengine.php on line 74

Don't know what to think about that...

I end up in a loop like this

1) User logs in, only becomes member of "Guest Accounts" (ezldapuser.php around line 470 for me)

$nodeAssignment = eZNodeAssignment::create( 
  array( 'contentobject_id' => $contentObjectID,
  'contentobject_version' => 1,
  'parent_node' => $defaultUserPlacement,
  'is_main' => 1 ) );

Problem is that he is a candidate for 2 mappings and this loop

if ( $extraNodeAssignments != null )
{
  foreach( $extraNodeAssignments as $extraNodeAssignment )
  {    

should handle them.

2) firts run for ldapusermanage2.php ok : user becomes member of another group (there's no mapping for "Guest Account" in my setup).
Here, the problem is that the user should become member of 2 groups (I've checked the code, both groups are found from ldap but failure seems to happen when assignment is done)

3) second run for ldapusermanage2.php : Fatal error. My user disappears from the "Users" section (maybe because he was member of only one group)

Observation: Every time a user has to be assigned to n groups (n > 1), only the first assignment is done.

Kristof Coomans

Monday 29 May 2006 11:43:04 pm

As far as I can tell, the LDAP login handler that comes with eZ publish (ezldapuser.php) has the same bug as the ldapusermanage cronjob. Maybe that has something to do with it, but I'm not sure.

I'll try to write a test script, I don't have an LDAP server to test your script with.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Tuesday 30 May 2006 12:50:47 am

I've found the problem. In eZ publish 3.8, opcodes were introduced in the node assignment mechanism. A node assignment is not immediately removed anymore when calling the remove method on it.

Because the cronjob still calls the remove method on all node assignments, and creates new ones afterwards, there will be more then one node assignment with identical parent node id's for for the same object version in the database (with different opcodes).

The publish operation however, will use only one node assignment because it always fetches the first one ( see eZContentOperationCollection::publishNode ). It will always get the assignment with the remove opcode, and any existing locations will be removed and only new locations will be added. The next time you run the cronjob, the old locations will come back, but the new locations from the previous run will be removed.

This is a second bug (this time only for eZ 3.8) in both the LDAP cronjob and the LDAP login handler ( http://ez.no/bugs/view/8384 ).

Solution: don't remove node assignments that don't have to be removed. Only create the new ones and then republish.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Artturi Markko

Tuesday 30 May 2006 4:10:28 am

Again, you save me :) Thanks a lot !
Fortunately, I've already the code to calculate exactly which assignments have to be removed in this page (search for $removeAssignments).

http://ez.no/community/forum/developer/node_group_assignment_how_to_remove_correctly/re_node_group_assignment_how_to_remove_corre__5

I'll post a complete ldapusermanage2.php as soon as possible.

Artturi

Artturi Markko

Tuesday 30 May 2006 1:07:09 pm

I'm afraid things still don't work as they should.
I have brought some modifications to :
a) avoid removing assignments which have to be kept
b) only add new groups

When my user has to be added to a group, detection is ok, everything runs as it would be ok, but the user doesn't show up in the group (from the admin interface).

Artturi

Kristof Coomans

Tuesday 30 May 2006 10:59:24 pm

Does the new group show up in the locations window of the user object?

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Artturi Markko

Wednesday 31 May 2006 4:34:32 am

No, user doesn't get modified.
Have you received the post I submitted on your website ?

I've put my modified version of ldapusermanage2.php here :
https://breg.dyndns.org/~mikael/ldapusermanage2.phps

Best regards,

Artturi

Artturi Markko

Wednesday 31 May 2006 1:44:54 pm

Still facing the same problem, here's some debug output.
Test case is that user 'chirac' (object id 59) belongs to ldap group 'France' and should be added to ez group 'France' (node id 59).

In the end of ldapusermanage2.php, I have :

                        if ($login == "chirac") {
                                echo "assignment :";
                                var_dump($assignment,$contentObject->attribute(
'id' ), $newVersionNr);
                        }
                        $assignment->setAttribute( 'parent_remote_id', "LDAP_" ..
 $newLDAPNode['parent_node_id'] );
                        if ($login == "chirac") {
                                var_dump($assignment);
                        }

Which give the following output (is it logic that 'parent_remote_id' don't begin by 'LDAP' ?)

assignment :object(eznodeassignment)(14) {
  ["PersistentDataDirty"]=>
  bool(false)
  ["ID"]=>
  string(3) "113"
  ["RemoteID"]=>
  string(1) "0"
  ["ParentRemoteID"]=>
  string(0) ""
  ["ContentobjectID"]=>
  string(2) "59"
  ["ContentObjectVersion"]=>
  string(2) "18"
  ["ParentNode"]=>
  string(2) "59"
  ["SortField"]=>
  string(1) "2"
  ["SortOrder"]=>
  string(1) "0"
  ["Main"]=>
  string(1) "0"
  ["FromNodeID"]=>
  string(2) "-1"
  ["TempNode"]=>
  NULL
  ["Name"]=>
  bool(false)
  ["OpCode"]=>
  string(1) "3"
}
string(2) "59"
string(2) "18"
object(eznodeassignment)(14) {
  ["PersistentDataDirty"]=>
  bool(true)
  ["ID"]=>
  string(3) "113"
  ["RemoteID"]=>
  string(1) "0"
  ["ParentRemoteID"]=>
  string(7) "LDAP_59"
  ["ContentobjectID"]=>
  string(2) "59"
  ["ContentObjectVersion"]=>
  string(2) "18"
  ["ParentNode"]=>
  string(2) "59"
  ["SortField"]=>
  string(1) "2"
  ["SortOrder"]=>
  string(1) "0"
  ["Main"]=>
  string(1) "0"
  ["FromNodeID"]=>
  string(2) "-1"
  ["TempNode"]=>
  NULL
  ["Name"]=>
  bool(false)
  ["OpCode"]=>
  string(1) "3"
}

Kristof Coomans

Monday 05 June 2006 6:05:14 am

Hi Artturi

You should remove this code (it causes double node assignments for existing nodes):

                if ( $hasOtherNodeType )
                {
                    foreach ( $otherNodeArray as $otherNode )
                    {
                        $newVersion->assignToNode( $otherNode['parent_node_id'], $otherNode['is_main'] );
                    }
                }

And then there's another bug in eZ publish 3.8 ( http://ez.no/bugs/view/8438 ) which caused the publish operation to malfunction. Please try the patch included with the bug report. During my limited tests it solved the issue you described.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Sunday 18 June 2006 11:32:43 pm

Some news for others who are interested in this topic: last week I've mailed with Artturi and it seems that his cronjob works now with the kernel bugfixes applied.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org