Wednesday 25 February 2009 8:12:08 am
I'm writing a plugin, which I will use to publish content to eZ Publish via SOAP. The publishing goes fine, and I can articles with an image just like I want to. The next step is the ability to update the information, so what I do is create a new versions with the new variables. For all attributes (author, title, short_title, etc) this is working fine, but not for the image. So setting the image for new content is working fine and without any problems, but updating an article with a new image is not working.
//create new version
$newContentObjectVersion =& $contentObject->createNewVersion();
//publish new version
$operationResult = eZOperationHandler::execute('content',
'publish', array('object_id' => $contentObject->attribute('id'),
'version' => $newContentObjectVersion->attribute('version')));
//attributes of new version
$attributes =& $contentObjectVersion->contentObjectAttributes();
foreach($attributes as $attribute){
$data_type_string = $attribute->attribute("data_type_string");
$attribute_identifier = $attribute->attribute("contentclass_attribute_identifier");
if($data_type_string == "ezimage"){
if($attribute_identifier == "image"){
setImage($attribute, $filename);
}
}
//.... other attributes, like ezstring and ezxmlblock
}
The setImage function (partly, only the important part), mimetype, filename and all other varables are set correctly.
function setImage(&$attribute, $filename){
//everything is done, create an image, set attributes and save it
$image =& eZImage::create($attribute->attribute("id"), $attribute->attribute("version"));
$image->setAttribute("contentobject_attribute_id", $attribute->attribute("id"));
$image->setAttribute("filename", $targetname);
$image->setAttribute("original_filename", $filename);
$image->setAttribute("mime_type", $mime);
$image->store();
}
What does happen is that the image is added to the eZImageFile table, with all the correct settings, including the right contentobject_attribute_id. What I think goes wrong is the attribute is copies from the old version and isn't been updated to the new image. I don't know how to do that either, so I really appreciate any help!
|