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.