removing objects by class [SOLVED]

Author Message

Jean-Luc Nguyen

Tuesday 19 August 2008 8:14:20 am

Hello,

I created a function in my extension to remove objects by classID :

function delete_eZ_node( $classID )
{	
    // Remove all objects
    $contentObjects = eZContentObject::fetchSameClassList( $classID );
    
    foreach ( $contentObjects as $contentObject )
    {
        eZContentObjectOperations::remove( $contentObject->attribute( 'id' ) );
    }
}

I get no errors at all, even when I error_log() in the definition of remove() function, I don't understand what is wrong... Do I have to do something else? Thanks a lot!

http://www.acidre.com

Jean-Luc Nguyen

Tuesday 19 August 2008 9:44:21 am

I found the solution, I execute my script with

php runcronjobs.php toto

And I have to be a eZ user to have the right to remove objects :

// Get user creator
$ini = eZINI::instance();
// Get user's ID who can remove subtrees. (Admin by default with userID = 14)
$userCreatorID = $ini->variable( "UserSettings", "UserCreatorID" );
$user = eZUser::fetch( $userCreatorID );
if ( !$user )
{
    error_log("Subtree remove Error!\nCannot get user object by userID = '$userCreatorID'.\n(See site.ini[UserSettings].UserCreatorID");
}
eZUser::setCurrentlyLoggedInUser( $user, $userCreatorID );

http://www.acidre.com

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.