Forums / Setup & design / Remove all contents of a class

Remove all contents of a class

Author Message

Ted Striker

Monday 15 May 2006 12:35:11 am

Hi there,

I have a large site (that runs ezp 3.4.2) wich a I have to duplicate, but "clean", that is remove all contents. It has rons of articles, images, links....

Is there any way to authomatically remove all contents (artcles for instance) all site wide without needing to remove then 1 by 1 ?? Some scipt..

Really need help on this....

Thanks in advance!!!

Can you feel it Mr. Anderson? Closing in on you? Oh I can, I really should thank you after all. It was, after all, it was your life that taught me the purpose of all life. Purpose of life is to end.

Ɓukasz Serwatka

Monday 15 May 2006 1:13:45 am

You can use SQL script which comes with eZ publish, look on kernel/sql/mysql/cleandata.sql. This script contains default installation information. Before run you need to clear tables. Useful might be also /bin/php/ezsqlinsertschema.php.

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

Xavier Dutoit

Monday 15 May 2006 1:22:57 am

Hi,

No "out of the box" functionnalities for that. It is quite simple to develop one. We are working on an extension to ease the admin of a website (so far focussing on the creation of content), it looks like a nice add on.

This being said, that's not my priority so far, unless you persuade me otherwise ;)

Plan B: export the class definitions as a package, delete the classes (it's going to delete the content too) and import the package containing the classes. It <b>should</b> work.

Let us know...

X+

http://www.sydesy.com

Kristof Coomans

Monday 15 May 2006 2:31:47 am

Hi Ted

I once wrote such a command line script. I haven't used it for a long time, but it will probably still work with the latest eZ publish releases.

#!/usr/bin/env php
<?php

// include needed kernel classes
include_once( 'kernel/classes/ezscript.php' );
include_once( 'kernel/classes/ezcontentclass.php' );
include_once( 'kernel/classes/ezcontentobject.php' );

// include needed library classes
include_once( 'lib/ezutils/classes/ezcli.php' );

$cli = &eZCLI::instance( );

$script = &eZScript::instance( array( 'description' => 'this script automates the removal of objects, usefull when removing corrupt items or cleaning up test data on development portals',
                                      'use-session' => false,
                                      'use-modules' => false,
                                      'use-extensions' => true ) );

$script->startup( );
$options =& $script->getOptions( '[classidentifier:][objectid:][exclude:][preview]', '', array( 'classidentifier' => 'class identifier of the objects you want to remove', 'exclude' => 'comma seperated list of object id\'s to exclude from removal', 'preview' => 'don\'t really remove objects, just show what would happen', 'objectid' => 'comma seperated list of the object id\'s you want to remove' ), false, array( 'user' => true ) );

$script->initialize( );

$objects = array( );

if ( $options['classidentifier'] or $options['objectid'] )
{
    // get the objects according to specified options
    if ( $options['classidentifier'] )
    {
        $class = &eZContentClass::fetchByIdentifier( $options['classidentifier'] );

        if ( $class )
        {
            $objects = &eZContentObject::fetchSameClassList( $class->attribute( 'id' ) );
        }
        else
        {
            $cli->output( 'could not find class' );
        }
    }
    elseif ( $options['objectid'] )
    {
        $idList = explode( ',', $options['objectid'] );

        if ( is_array( $idList ) )
        {
            $objects = &eZContentObject::fetchIDArray( $idList );
        }
        else
        {
            $objects[] = &eZContentObject::fetch( $idList );
        }
    }

    if ( count( $objects ) > 0 )
    {
        $removedCount = 0;
        $excludes = array( );
    
        if ( $options['exclude'] )
        {
            $excludes = explode( ',', $options['exclude'] );
        }

        foreach( array_keys( $objects ) as $key )
        {
            if ( in_array( $objects[$key]->attribute( 'id' ), $excludes ) )
            {
                $cli->output( 'excluding object ' . $objects[$key]->attribute( 'id' ) . ': ' . $objects[$key]->attribute( 'name' ) );
            }
            else
            {
                $cli->output( 'removing object ' . $objects[$key]->attribute( 'id' ) . ': ' . $objects[$key]->attribute( 'name' ) );

                if ( $options['preview'] !== true )
                {
                    if ( $objects[$key]->attribute( 'status' ) == EZ_CONTENT_OBJECT_STATUS_PUBLISHED )
                    {
                        $assignedNodes = $objects[$key]->attribute( 'assigned_nodes' );

                        $nodeIdArray = array( );
                        foreach ( array_keys( $assignedNodes ) as $assignedNodeKey )
                        {
                            if ( $assignedNodes[$assignedNodeKey]->attribute( 'can_remove' ) )
                            {
                                $nodeIdArray[] = $assignedNodes[$assignedNodeKey]->attribute( 'node_id' );
                            }
                            else
                            {
                                $nodeIdArray = false;
                                break;
                            }
                        }

                        if ( $nodeIdArray )
                        {
                            eZContentObjectTreeNode::removeSubtrees( $nodeIdArray, false );
                        }
                        else
                        {
                            $cli->output( 'you have insufficient rights to remove this object' );
                        }
                    }
                    else
                    {
                        $objects[$key]->remove( );
                        $objects[$key]->purge( );
                    }
                }
                $removedCount++;
            }
        }

        $cli->output( 'removed items: ' . $removedCount );
    }
    else
    {
        $cli->output( 'no objects of this class were found' );
    }
}
else
{
    $script->showHelp( );
}

$script->shutdown( );

?>

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

eZ debug

Timing: Jan 31 2025 00:40:44
Script start
Timing: Jan 31 2025 00:40:44
Module start 'content'
Timing: Jan 31 2025 00:40:44
Module end 'content'
Timing: Jan 31 2025 00:40:44
Script end

Main resources:

Total runtime0.1994 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0076 587.9453370.2969
Module start 'content' 0.00760.0155 958.24221,009.5469
Module end 'content' 0.02310.1762 1,967.78913,897.7188
Script end 0.1993  5,865.5078 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00442.2111200.0002
Check MTime0.00130.6661200.0001
Mysql Total
Database connection0.00080.380110.0008
Mysqli_queries0.100950.58981410.0007
Looping result0.00150.74291390.0000
Template Total0.175888.210.1758
Template load0.00080.393710.0008
Template processing0.175087.762610.1750
Override
Cache load0.00050.270310.0005
Sytem overhead
Fetch class attribute can translate value0.00221.086210.0022
XML
Image XML parsing0.00030.152610.0003
General
dbfile0.01015.0618200.0005
String conversion0.00000.002030.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