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

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 18 2025 18:31:43
Script start
Timing: Jan 18 2025 18:31:43
Module start 'layout'
Timing: Jan 18 2025 18:31:43
Module start 'content'
Timing: Jan 18 2025 18:31:43
Module end 'content'
Timing: Jan 18 2025 18:31:43
Script end

Main resources:

Total runtime0.0177 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 587.9141152.6250
Module start 'layout' 0.00790.0039 740.539139.4453
Module start 'content' 0.01180.0038 779.984493.3516
Module end 'content' 0.01560.0020 873.335934.3047
Script end 0.0177  907.6406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002715.4310140.0002
Check MTime0.00126.5650140.0001
Mysql Total
Database connection0.002313.041110.0023
Mysqli_queries0.003821.670030.0013
Looping result0.00000.095710.0000
Template Total0.00179.710.0017
Template load0.00094.859410.0009
Template processing0.00084.779910.0008
Override
Cache load0.00063.442110.0006
General
dbfile0.00031.554780.0000
String conversion0.00000.045840.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.0001 secs