|
Monday 15 May 2006 9:41:27 am
Comment46034
Tried in Apache instance... as a simple script.
But, the script runs well as a cronjob (i.e. no execution errors) and try now to <b>INSERT NEW CONTENT in the CMS</b>. Cheking the database, I can see that there is more data in the <i>ezcontentobject</i> table ; but I can't never see my changes from the Admin Interface. I've tried to complete my script with a publish result check with this code block (found in the existing rssimport cronjob) :
<b><i>
$operationResult = eZOperationHandler::execute( 'content', 'publish', $pupProps );
echo "Publish result : " . print_r( $operationResult ) . "\n";
if ( !isset( $operationResult['status'] ) || $operationResult['status'] != EZ_MODULE_OPERATION_CONTINUE )
{
if ( isset( $operationResult['result'] ) && isset( $operationResult['result']['content'] ) )
$failReason = $operationResult['result']['content'];
else
$failReason = "unknown error";
$cli->error( "Publishing failed: $failReason" );
unset( $failReason );
} </i></b> The publish operation allways failed with an 'Unkown reason' :-( Thank's for any complementary good advice !
--------------------------------------------------------------------- Here the new version of my Cronjob Script :
<i>
<?php
include_once( "kernel/classes/ezpersistentobject.php" );
include_once( "kernel/classes/ezcontentclass.php" );
include_once( "kernel/classes/ezcontentobjecttreenode.php" );
include_once( "kernel/classes/eznodeassignment.php" );
include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
include_once("lib/ezutils/classes/ezoperationhandler.php");
// FETCH INJECTING USER
$injectUser = eZUser::fetchByName('admin', true);
$userID = $injectUser->attribute('contentobject_id');
echo "Have user : " . $userID . "\n";
// FETCH CONTENT CLASS
$noteClass = eZContentClass::fetchByIdentifier('lecture_note');
echo "Note class : " . $noteClass->attribute('name') . "\n";
// GET PARENT NODE AND SECTION
$parentNodeID = 2;
$parentTreeNode = eZContentObjectTreeNode::fetch( $parentNodeID );
echo "Parent node : " . $parentTreeNode . "\n";
$parentContentObject = $parentTreeNode->attribute('object');
$sectionID = $parentContentObject->attribute('section_id');
echo "Inserting in section ID " . $sectionID . "\n";
// INSTANCIATION
$contentObject = & $noteClass->instantiate( $userID, $sectionID );
// ASSIGNATION
$assignProps = array(
'contentobject_id' => $contentObject->attribute('id'),
'contentobject_version' => $contentObject->attribute('current_version'),
'parent_node' => $parentTreeNode->attribute('node_id'),
'is_main' => 0
);
print_r( $assignProps );
$nodeAssignment = & eZNodeAssignment::create( $assignProps );
$nodeAssignment->store();
// STORE EMPTY OBJECT
$contentObject->setAttribute('name', 'Note de lecture');
$contentObject->store();
// SET ATTRIBUTES
$attribs = & $contentObject->contentObjectAttributes();
foreach( $attribs as $anAttr )
{
$attID = $anAttr->attribute('contentclass_attribute_identifier');
echo "IDENT : " . $attID . "\n";
$anAttr->setAttribute('data_text', "ZZZZZZZZZZZZZZZZZZZZZZZZZZ");
$anAttr->store();
}
$contentObject->setAttribute('status', EZ_VERSION_STATUS_DRAFT);
$contentObject->store();
// PUBLISH
$pubProps = array(
'object_id' => $contentObject->attribute('id'),
'version' => 1
); eZOperationHandler::execute( 'content', 'publish', $pupProps );
?> </i>
|