Forums / General / Help with delete script

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Help with delete script

Author Message

Jack Rackham

Wednesday 28 September 2005 5:18:10 am

I have been searching the forums for a delete script that deletes all nodes of specific class, but with no luck. Can someone share a script that has this function?

Łukasz Serwatka

Wednesday 28 September 2005 11:55:43 pm

Hi,

Here is the simple function which delete nodes of specyfic class

/**
 * @param array $classID
 * @param int $parentNodeID
 * @param int $depth
 */
function deleteNodes ( $classID, $parentNodeID, $depth )
{

	$deleteIDArray = array();

	$nodeArray =& eZContentObjectTreeNode::subTree(  array(
	'ClassFilterType' => 'include',
	'ClassFilterArray' => $classID,
	'Depth' => $depth,
	), $parentNodeID
	);
	foreach ( $nodeArray as $node )
	{
		$deleteIDArray[] = $node->attribute( 'main_node_id' );
	}

	eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );
}

//Delete all articles from root folder, only from first level. 
deleteNodes ( array( 2 ), 2, 1 );

This function will not move to trash, not check permissions. If you need that features, feel free to edit;)

Good luck!

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Jack Rackham

Thursday 29 September 2005 3:53:33 am

It's not working!

I tried this

<?php
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentobject.php' );
/**
 * @param array $classID
 * @param int $parentNodeID
 * @param int $depth
 */

 function deleteNodes ( $classID, $parentNodeID, $depth )
{

	$deleteIDArray = array();

	$nodeArray =& eZContentObjectTreeNode::subTree(  array(
	'ClassFilterType' => 'include',
	'ClassFilterArray' => $classID,
	'Depth' => $depth,
	), $parentNodeID
	);
	foreach ( $nodeArray as $node )
	{
		$deleteIDArray[] = $node->attribute( 'main_node_id' );
	}

	eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );
}

//Delete all rss from root folder, all level???. 
deleteNodes ( array( 35 ), 2, 0 );
?>

php rssrm.php from Exponential folder: error on line 21

line 21; foreach ( $nodeArray as $node )

Łukasz Serwatka

Thursday 29 September 2005 4:30:04 am

Of course that will not work like this, you will have to make it as cli script, look in to bin/php/ or as extension or tpl operator.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Jack Rackham

Thursday 29 September 2005 4:50:43 am

so something like this

<?php
include_once( 'lib/ezutils/classes/ezcli.php' );
include_once( 'kernel/classes/ezscript.php' );

$cli =& eZCLI::instance();
$script =& eZScript::instance( array( 'description' => ( "Exponential Content Cache Handler\n" .
                                                         "Allows for easy clearing of Content Caches\n" .
                                                         "\n" .
                                                         "Clearing node for content and users tree\n" .
                                                         "./bin/ezcontentcache.php --clear-node=/,5\n" .
                                                         "Clearing subtree for content tree\n" .
                                                         "./bin/ezcontentcache.php --clear-subtree=/" ),
                                      'use-session' => false,
                                      'use-modules' => false,
                                      'use-extensions' => true ) );

$script->startup();
$options = $script->getOptions();
$script->initialize();

set_time_limit( 0 );


include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentobject.php' );
/**
 * @param array $classID
 * @param int $parentNodeID
 * @param int $depth
 */

 function deleteNodes ( $classID, $parentNodeID, $depth )
{

	$deleteIDArray = array();

	$nodeArray =& eZContentObjectTreeNode::subTree(  array(
	'ClassFilterType' => 'include',
	'ClassFilterArray' => $classID,
	'Depth' => $depth,
	), $parentNodeID
	);
	foreach ( $nodeArray as $node )
	{
		$deleteIDArray[] = $node->attribute( 'main_node_id' );
	}

	eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );
}

//Delete all rss from root folder, only from first level. 
deleteNodes ( array( 35 ), 2, 0 );

$script->shutdown();
?>

Łukasz Serwatka

Thursday 29 September 2005 5:07:25 am

Use this, set correct login and password, since you need user with remove access, and set depth 1 if you remove from class which is container.

#!/usr/bin/env php
<?php
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentobject.php' );
include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );

include_once( 'lib/ezutils/classes/ezcli.php' );
include_once( 'kernel/classes/ezscript.php' );

$cli =& eZCLI::instance();
$script =& eZScript::instance();

$script->startup();

$script->initialize();

/**
 * @param array $classID
 * @param int $parentNodeID
 * @param int $depth
 * @param string $login
 * @param string $password
 */
function &deleteNodes ( $classID, $parentNodeID, $depth, $login, $password )
{
	eZUser::loginUser( $login, $password );

	$deleteIDArray = array();

	$nodeArray =& eZContentObjectTreeNode::subTree(  array(
	'ClassFilterType' => 'include',
	'ClassFilterArray' => $classID,
	'Depth' => $depth,
	), $parentNodeID
	);
	foreach ( $nodeArray as $node )
	{
		$deleteIDArray[] = $node->attribute( 'main_node_id' );
	}

	eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );
}

deleteNodes ( array( 2 ), 2, 1, 'admin', '1234' );

$script->shutdown();
?>

Run from Exponential root.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Jack Rackham

Thursday 29 September 2005 6:05:09 am

It's a praise error on line 46 in your latest version of this script

"v 2" works

#!/usr/bin/env php
<?php
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentobject.php' );
include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );

include_once( 'lib/ezutils/classes/ezcli.php' );
include_once( 'kernel/classes/ezscript.php' );

$cli =& eZCLI::instance();
$script =& eZScript::instance();

$script->startup();

$script->initialize();

/**
 * @param array $classID
 * @param int $parentNodeID
 * @param int $depth
 */
function &deleteNodes ( $classID, $parentNodeID, $depth )
{	
	eZUser::loginUser( 'admin', '1234' );
	
	$deleteIDArray = array();

	$nodeArray =& eZContentObjectTreeNode::subTree(  array(
															'ClassFilterType' => 'include',
															'ClassFilterArray' => $classID,
															'Depth' => $depth,
															), $parentNodeID
													);
	foreach ( $nodeArray as $node )
	{
		$deleteIDArray[] = $node->attribute( 'main_node_id' );
	}

	eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );
}


deleteNodes ( array( 2 ), 2, 1 );

$script->shutdown();
?>

Łukasz Serwatka

Thursday 29 September 2005 6:08:50 am

It's a praise error on line 46 in your latest version of this script

Hmm, are sure? My editor display correct syntax.

Correct version is, tested and works.

#!/usr/bin/env php
<?php
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentobject.php' );
include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );

include_once( 'lib/ezutils/classes/ezcli.php' );
include_once( 'kernel/classes/ezscript.php' );

$cli =& eZCLI::instance();
$script =& eZScript::instance();

$script->startup();

$script->initialize();

/**
 * @param array $classID
 * @param int $parentNodeID
 * @param int $depth
 * @param string $login
 * @param string $password
 */
function &deleteNodes ( $classID, $parentNodeID, $depth, $login, $password )
{
eZUser::loginUser( $login, $password );

$deleteIDArray = array();

$nodeArray =& eZContentObjectTreeNode::subTree(  array(
'ClassFilterType' => 'include',
'ClassFilterArray' => $classID,
'Depth' => $depth,
), $parentNodeID
);
foreach ( $nodeArray as $node )
{
$deleteIDArray[] = $node->attribute( 'main_node_id' );
}

eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, false );
}

deleteNodes ( array( 2 ), 2, 1, 'admin', '1234' );

$script->shutdown();
?>

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Jack Rackham

Thursday 29 September 2005 6:15:33 am

Ok it works :-) This function must bee included in EZ, because old rss feeds are useless unless you are running some kind of feed archive.