Updating image in article via SOAP

Author Message

Michael de Vries

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!

Michael de Vries

Thursday 26 February 2009 2:50:30 am

Ok, I "solved" this myself. What I do now is in the setImage method call the following:

$attribute->setAttribute("data_text", "");
$attribute->store();

After this, the image is automagically set right by the following line of code.

$image =& eZImage::create($attribute->attribute("id"), $attribute->attribute("version"));

Not sure I this is the right way, but it works for me.

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 16:22:32
Script start
Timing: Jan 18 2025 16:22:32
Module start 'layout'
Timing: Jan 18 2025 16:22:32
Module start 'content'
Timing: Jan 18 2025 16:22:33
Module end 'content'
Timing: Jan 18 2025 16:22:33
Script end

Main resources:

Total runtime0.7893 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 589.0391152.6250
Module start 'layout' 0.00470.0027 741.664139.4609
Module start 'content' 0.00740.7807 781.1250431.7266
Module end 'content' 0.78810.0011 1,212.851612.1563
Script end 0.7893  1,225.0078 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3993160.0002
Check MTime0.00130.1634160.0001
Mysql Total
Database connection0.00070.093510.0007
Mysqli_queries0.752995.3903520.0145
Looping result0.00040.0464500.0000
Template Total0.763796.720.3818
Template load0.00200.258720.0010
Template processing0.761696.489920.3808
Template load and register function0.00010.017110.0001
states
state_id_array0.00080.106910.0008
state_identifier_array0.00090.112920.0004
Override
Cache load0.00170.2164170.0001
Sytem overhead
Fetch class attribute can translate value0.00120.151810.0012
Fetch class attribute name0.00080.099220.0004
XML
Image XML parsing0.00010.012110.0001
class_abstraction
Instantiating content class attribute0.00000.000820.0000
General
dbfile0.00060.0752100.0001
String conversion0.00000.000840.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
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs