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 ez publish 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' => ( "eZ publish 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 eZ publish 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.

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

eZ debug

Timing: Jan 31 2025 01:30:01
Script start
Timing: Jan 31 2025 01:30:01
Module start 'layout'
Timing: Jan 31 2025 01:30:01
Module start 'content'
Timing: Jan 31 2025 01:30:02
Module end 'content'
Timing: Jan 31 2025 01:30:02
Script end

Main resources:

Total runtime0.0651 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0065 588.1016151.1953
Module start 'layout' 0.00650.0106 739.2969220.6563
Module start 'content' 0.01710.0427 959.95311,013.7734
Module end 'content' 0.05980.0052 1,973.726649.9922
Script end 0.0650  2,023.7188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00477.1428140.0003
Check MTime0.00121.8289140.0001
Mysql Total
Database connection0.00233.538810.0023
Mysqli_queries0.008212.656730.0027
Looping result0.00000.061510.0000
Template Total0.00477.210.0047
Template load0.00446.829310.0044
Template processing0.00030.401010.0003
Override
Cache load0.00182.806410.0018
General
dbfile0.00030.523380.0000
String conversion0.00000.017240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0037 secs