Forums / General / Help with delete script

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.

eZ debug

Timing: Jan 18 2025 11:28:12
Script start
Timing: Jan 18 2025 11:28:12
Module start 'content'
Timing: Jan 18 2025 11:28:12
Module end 'content'
Timing: Jan 18 2025 11:28:12
Script end

Main resources:

Total runtime0.2624 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 587.6016180.8516
Module start 'content' 0.00700.0077 768.4531109.8359
Module end 'content' 0.01470.2475 878.2891537.6719
Script end 0.2623  1,415.9609 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00401.5293200.0002
Check MTime0.00170.6434200.0001
Mysql Total
Database connection0.00120.453510.0012
Mysqli_queries0.207679.14081410.0015
Looping result0.00160.62271390.0000
Template Total0.247294.210.2472
Template load0.00100.366310.0010
Template processing0.246293.833210.2462
Override
Cache load0.00070.255710.0007
Sytem overhead
Fetch class attribute can translate value0.00070.279310.0007
XML
Image XML parsing0.00040.157410.0004
General
dbfile0.00250.9712200.0001
String conversion0.00000.002230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

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

Time used to render debug report: 0.0001 secs