CLI script to create an object. Need help

Author Message

Andrew White

Monday 08 September 2008 7:38:56 am

Afternoon:

I'm working on creating a command line script to create an object. I seem to have the "create" part working. Unfortunately while the content is showing up in the DB, its not visible to the CMS. My script is below, I'd appreciate any help!

#!/Applications/MAMP/bin/php5/bin/php
<?php 

require 'autoload.php';

$cli =& eZCLI::instance();
$script =& eZScript::instance(); 
$script->startup();
$options = $script->getOptions();
$script->initialize();

$classID = 42; // ID of class new object will be (Resolution in this case)
$nodeID = 58; // ID of parent node (resolutions folder)

// Get class definition
if ( !$class = eZContentClass::fetch( $classID ) )
{
    $cli->output('Error: Could not fetch class');
}

// Get the parent node
$node = eZContentObjectTreeNode::fetch($nodeID);
if (!$node)
{    
    $cli->output('Error: no mapped parent node');        
}

// Instantiate a new resolution object
$object =& $class->instantiate();        
if (!$object)
{
    $cli->output('Error: could not create object');
}

$attributes = array(	'id'				=> '1090',
                        'type'				=> 'About type',
                        'subject'			=> 'About Subject',
                        'symptom'			=> 'This is the symptom',
                        'keywords'			=> 'these are the keywords',
                        'resolution_html'	=> 'The resolution goes here',
						'mod_date'			=> '09092008',
						'rank'				=> '1'
					);
$params = array();
$params['parent_node_id'] = $nodeID;
$params['class_identifier'] = 'resolution';
$params['attributes'] = $attributes;

$object = eZContentFunctions::createAndPublishObject( $params );

$script->shutdown();
 
?>

Gabriel Finkelstein

Monday 08 September 2008 11:34:52 am

Perhaps clearing the cache afterwards? (Replace [objectID])

eZContentCacheManager::clearContentCache( [objectID] );

Andrew White

Tuesday 09 September 2008 1:09:49 am

Thanks, Gabriel, I will! Other than that, I'm on the right track?

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

Main resources:

Total runtime0.7591 sec
Peak memory usage8,192.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 588.2578151.2266
Module start 'layout' 0.00480.0033 739.4844220.7188
Module start 'content' 0.00810.7501 960.20314,411.1641
Module end 'content' 0.75820.0008 5,371.367211.8281
Script end 0.7591  5,383.1953 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4320160.0002
Check MTime0.00130.1651160.0001
Mysql Total
Database connection0.00080.100410.0008
Mysqli_queries0.681989.8366570.0120
Looping result0.00050.0607550.0000
Template Total0.715194.220.3575
Template load0.00210.279820.0011
Template processing0.713093.922120.3565
Template load and register function0.00140.181710.0014
states
state_id_array0.00130.173910.0013
state_identifier_array0.00160.213020.0008
Override
Cache load0.00180.2370120.0001
Sytem overhead
Fetch class attribute can translate value0.00150.195320.0007
Fetch class attribute name0.00190.251240.0005
XML
Image XML parsing0.00510.667220.0025
class_abstraction
Instantiating content class attribute0.00000.001840.0000
General
dbfile0.00510.6734160.0003
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 11
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs