Forums / Developer / Updating image in article via SOAP

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.

eZ debug

Timing: Jan 30 2025 22:21:36
Script start
Timing: Jan 30 2025 22:21:36
Module start 'content'
Timing: Jan 30 2025 22:21:36
Module end 'content'
Timing: Jan 30 2025 22:21:37
Script end

Main resources:

Total runtime0.3331 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 587.9531370.2891
Module start 'content' 0.00840.0147 958.24221,001.4531
Module end 'content' 0.02310.3100 1,959.69533,891.9609
Script end 0.3330  5,851.6563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00481.4454200.0002
Check MTime0.00150.4442200.0001
Mysql Total
Database connection0.00070.219210.0007
Mysqli_queries0.232369.72921410.0016
Looping result0.00150.43681390.0000
Template Total0.309692.910.3096
Template load0.00080.226710.0008
Template processing0.308892.715310.3088
Override
Cache load0.00050.160910.0005
Sytem overhead
Fetch class attribute can translate value0.00220.661710.0022
XML
Image XML parsing0.00030.079510.0003
General
dbfile0.01153.4643200.0006
String conversion0.00000.001830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs