Share » Forums » Developer » deleteing a node tree via PHP

deleteing a node tree via PHP

deleteing a node tree via PHP

Thursday 05 February 2004 5:06:48 am - 11 replies

Author Message

Wenyue Yu

Thursday 05 February 2004 5:39:39 am

Hi,

Doing $node->remove() will only remove the content object from ezcontentobject_tree table. To completely remove this object, you need to do the following:
$objectID = $node->attribute( 'contentobject_id' );
$node->remove();
$object =& eZContentObject::fetch( $objectID );
$object->purge();

Regards,
wenyue

Jim Reverend

Thursday 05 February 2004 5:49:41 am

Thank you kindly for your quick response.

I tried what you said in the past, and I tried it again now, to no avail.

It seems that $node->subTree() isn't returning any items when there clearly ARE items in that node.

In one "folder" I have nothing but "folder"s. And they all seem to remove just fine. However, in another folder, I have objects belonging to a custom class... those items are not being returned by SubTree nor are they being removed. I built the custom class using the Admin interface. Could this be the problem?

Jim Reverend

Thursday 05 February 2004 5:52:46 am

To make things more interesting, I just added a "folder" to the node that it full of objects of a custom class. When I ran the script, the folder was deleted, yet the other items remained.

Jim Reverend

Thursday 05 February 2004 5:57:45 am

A few more tests.

I added a whole bunch of objects to the folder and then tried to delete them. And only one item type will not delete.

One of the items was "comment". I edited it via the admin interface, and it deleted just fine. The item that wont delete is "blog". I made it from a copy of "article" that I edited to suit my needs (got rid of Intro and Thumbnail and renamed Body). I hope this helps you figure out what is going on here.

Wenyue Yu

Thursday 05 February 2004 7:51:57 am

Hi,

I think the problem is of permission. When you run this script, you are treated as anoymous user, so you need to give content read * permission to anoymous user.

Regards,
wenyue

Jim Reverend

Thursday 05 February 2004 10:53:00 am

I gave read * to Anonymous user. This didn't seem to help. However, I believe that I must not be running the script as Anonymous. If I were, I don't think I would be capable of deleting ANYTHING at all. At least... that doesn't seem right.

I installed PLAIN system. That's what I've been editing to create the system I have now. And I've only made the changes I laid out to you earlier. I am convinced that it has something to do with the creation of new classes of content and the ability for those items to appear in the default data listed by subTree().

Is there anything more you can think of?

Wenyue Yu

Friday 06 February 2004 2:41:19 am

Hi,

Could you added print( "Here is my sql query-" . $query ); in function subTree() of class eZContentObjectTreeNode around line 1090 before "if ( !$offset && !$limit )"?

What sql query do you get when you run your script?

Regards,
wenyue

Jim Reverend

Friday 06 February 2004 4:19:45 am

Yesterday evening I figured it out. Or rather, you figured it out. It was a permissions issue, like you said. I wasn't pushing the right button to make the permissions changes active. It looked like they were... but they weren't. AS soon as I made them active, the script started working just fine.

Of course, this brings a whole host of new worries... like... if the script runs as an anonymous user... why is that anonymous user capable of deleting anything?? They didn't have any kind of edit permissions. Just "read" and "login".

I'd still really like to see some sample code for working with the different Objects in EZ (Node, Object, Attribute, Version, DataType, etc).

Thank you again, for all of your help. It really is appreciated.

Wenyue Yu

Friday 06 February 2004 6:03:09 am

Hi,

Actually, if you can run a script in your system, you can do everything. The permission issues in your script is only because you used function subTree() which will check current user ( this function is used in admin interface ) . Since you are not logged in, you are anonymous user. The actual deleting function you called will not check permissions and that is why you can delete anything. Permission will be checked in admin/user interface, so don't worry about that. There is no security hole.

Best regards,
wenyue

Jim Reverend

Friday 06 February 2004 6:44:49 am

Wenyue--

Thank you again for all of your help. I have 2 more questions:

1) Are any of the permissionless methods exported to the templates in any way?

2) Is there another function I can use that does the same thing as subTree() but without the permissions checking? I'd rather not have to make everything that is going to be removed by this script "readable" by anonymous.

3) In case there isn't another option for #2, is there a way that I can make my script "login" as a different user?

Thanks, again!

Wenyue Yu

Friday 06 February 2004 8:11:00 am

Hi,

To escape permision check in subTree function, use following:

$node->subTree( array( 'Limitation' => array() ) );

Regards,
wenyue

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu