Forums / Developer / New multiple location of class

New multiple location of class

Author Message

Siniša Šehović

Thursday 07 October 2004 6:51:26 am

Hi ppl

I have one problem.
I have 600 users in users section now I need to link them(new location) to standard section in predefined folder.(Could use template to show them but I need link)
I know how to do it by hand one by one:-)
How can I do it by php code?

Please help!

Best regards,
Sinisa

---
If at first you don't succeed, look in the trash for the instructions.

Gunnstein Lye

Monday 11 October 2004 4:07:53 am

Something like this should work:
(fill in for the question marks)

<?php

$currentParentNodeID = ?;
$extraParentNodeID = ?;

$nodeList =& eZContentObjectTreeNode::subTree( array( 'ClassID' => 4,
                                                      'Depth' => 1,
                                                      'AsObject' => false ),
                                               $currentParentNodeID );

foreach( $nodeList as $node )
{
    // Fetch object
    $contentObject =& eZContentObject::fetch( $node['contentobject_id'] );

    // Create extra node assignment
    $nodeAssignment =& eZNodeAssignment::create(
        array( 'contentobject_id' => $contentObject->attribute( 'id' ),
               'contentobject_version' => $contentObject->attribute( 'current_version' ),
               'is_main' => 0,
               'parent_node' => $extraParentNodeID ) );
    $nodeAssignment->store();

    // Publish the new object
    include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
    $operationResult = eZOperationHandler::execute( 'content', 'publish',
                                                    array( 'object_id' => $contentObject->attribute( 'id' ),
                                                           'version' => $contentObject->attribute( 'current_version' ) ) );
}

?>

Siniša Šehović

Monday 11 October 2004 5:23:57 am

Hi Lye,

How can I execute that script?
I tryied directly by calling it from http://website/script_name.php but nothing happend!?
Also tryied from command prompt(test server is on winblows) php script_name.php and still nothing.
I have changed

$currentParentNodeID = 63; //ID of user_group under users
$extraParentNodeID = 62; //ID of new direcotory

Not even error msg:)

What I'm dooing wrong?

Best regards,
Sinisa

---
If at first you don't succeed, look in the trash for the instructions.

Gunnstein Lye

Monday 11 October 2004 5:41:41 am

Well, I did not test this at all so there could be bugs in it. I suggest running it from the command line and using print() statements for debugging.

Siniša Šehović

Monday 11 October 2004 5:55:34 am

Hi

I did that but nothing happend.
What files(classes) I have to include_once?

I have for testing put simple echo but echo isn't shown on command line!??!

Sinisa

---
If at first you don't succeed, look in the trash for the instructions.

Siniša Šehović

Monday 11 October 2004 6:10:03 am

Hi

Here is what I get from php output:

<b>Warning</b>: Invalid argument supplied for foreach() in <b>D:\wwwroot\ezdemo
\lib\ezutils\classes\ezmoduleoperationinfo.php</b> on line <b>78</b><br />

What is wrong?
I use eZp 3.5alpha from svn

Sinisa

---
If at first you don't succeed, look in the trash for the instructions.

Gunnstein Lye

Monday 11 October 2004 6:25:09 am

If you miss an include_once, you will get a crash.
I don't know what could be wrong with your print/echo. Maybe a php setting.

The warning means that $nodeList is not an array, which probably means that the subTree() call returned false. That could be because some of the parameters are wrong.

Sorry, but that's all I can do to help.

Siniša Šehović

Wednesday 13 October 2004 2:07:47 am

Hi Lye

I have figured out what could be wrong.
I need to be authenticated to run that script.
But don't know how to do that.
Please help!

How to say to php that I'm administrator and have permisson to update database?

Best regards,
Sinisa

---
If at first you don't succeed, look in the trash for the instructions.

Gunnstein Lye

Wednesday 13 October 2004 5:23:23 am

This should do the trick:

<?php
include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
eZUser::loginUser( $login, $password );
?>

You need to add the user name and password, of course. And be careful, it is a security risk to put your plaintext admin password in a file like this.

Siniša Šehović

Wednesday 13 October 2004 5:50:49 am

Hi

Thanx for quick replay.
Still getting empty array in $nodeList?!?

$currentParentNodeID = 101 and $extraParentNodeID = 112 are existing one.

I want to make link form user class in users section of web into newly created section(eg. members) and that section has only one folder named members. Is it possible to do with that code?

Best regards,
Sinisa

---
If at first you don't succeed, look in the trash for the instructions.

Gunnstein Lye

Thursday 14 October 2004 5:03:27 am

Sorry, then I don't know what is wrong.