Forums / Developer / PHP remove objects script ?

PHP remove objects script ?

Author Message

H-Works Agency

Saturday 14 July 2007 12:28:31 pm

Hi all,

I am using a cron task to run a php script to synchronize the ezpublish product database with my client real shop.

Part of this script is made to remove objects that are no longer available. For doing this i use :

eZContentObjectTreeNode::removeSubtrees($deleteIDArray, $moveToTrash=false);

Where deleteIDArray is an array holding all node_id that need removal.

The problem is that this function doesn't work. It doesn't remove the nodes.

Why that ? Is this the good process to remove my objects in a php script ?

EZP is Great

Kristof Coomans

Sunday 15 July 2007 5:10:41 am

Hello Martin

You probably need to log in as a user that haves the right policies to remove the nodes.

See http://ezpedia.org/wiki/en/ez/command_line_scripts for a generic script example. One option is to use

$useStandardOptions = array( 'user' => true );

Afterwards, you can specify login and password on the command line with --login and --password

If you want to run the script from cron, you're probably better off with the second option:

include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
$user = eZUser::fetchByName( 'admin' );
$userID = $user->attribute( 'contentobject_id' );
eZUser::setCurrentlyLoggedInUser( $user, $userID );

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

H-Works Agency

Monday 16 July 2007 5:08:26 am

Thanks - in fact it has to do with the rights management thru cronjobs.

I putted this code at the start of my script and it seems to work :

include_once('kernel/classes/datatypes/ezuser/ezuser.php');

$ini =& eZINI::instance();     
$userCreatorID = $ini->variable( "UserSettings", "UserCreatorID" );
$user = eZUser::fetch($userCreatorID);

if(!$user)
{
    $cli->error("Cannot get user object by userID = '$userCreatorID'. See site.ini[UserSettings].UserCreatorID");
    $script->shutdown(1);
}
                               
// Login
eZUser::setCurrentlyLoggedInUser($user, $userCreatorID);

EZP is Great

eZ debug

Timing: Jan 18 2025 15:14:10
Script start
Timing: Jan 18 2025 15:14:10
Module start 'content'
Timing: Jan 18 2025 15:14:10
Module end 'content'
Timing: Jan 18 2025 15:14:11
Script end

Main resources:

Total runtime0.3465 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.0072 587.7109180.8359
Module start 'content' 0.00720.0057 768.546997.8984
Module end 'content' 0.01280.3336 866.4453526.5234
Script end 0.3465  1,392.9688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00381.0847200.0002
Check MTime0.00140.4037200.0001
Mysql Total
Database connection0.00110.321010.0011
Mysqli_queries0.293884.78071410.0021
Looping result0.00180.52491390.0000
Template Total0.333196.110.3331
Template load0.00110.308210.0011
Template processing0.332195.824910.3321
Override
Cache load0.00080.229910.0008
Sytem overhead
Fetch class attribute can translate value0.00140.399910.0014
XML
Image XML parsing0.00020.063410.0002
General
dbfile0.00230.6645200.0001
String conversion0.00000.001430.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