Forums / Developer / Import image process into kernel

Import image process into kernel

Author Message

thibaut colin

Thursday 25 June 2009 6:08:14 am

Hi everybody,

I'm developping a xml import script who create and publish object on eZ database. There are many link to image on these files and I search into the kernel what are the methods and classes I have to use in order to insert correctly all image as well as I make all this process into Admin interface.

I see that the datatype ezimage is link to the ezPersistentObject class like an ezString but ezimage have to be declared with a xml matrix in data_text.

I suppose it will be more complicated that only use this kind of code :

$objDataMap=$this->current_eZ_object->dataMap();
$imageAttr=$objDataMap['image'];
$imageAttr->setAttribute('data_text',$tag->nodeValue);
$nameAttr->store();

In fact, I search for all process that eZ use for create an object with ezimage attribute without the Admin interface.

Have you any idea who could help me ?

Thanks

Jérôme Vieilledent

Saturday 27 June 2009 3:22:25 am

Hi Thibault.

First, know that it already exists extensions to import data (<b>Data Import</b>, and I'm about to release mine, <b>NovenImportXMLStream</b>).

Now for your question, you should use the <i>fromString()</i> method of the <i>ezimage</i> datatype. Every datatypes (well at least the built-in ones) have this very useful method since eZ Publish 3.9.
So if you want to grab an external image, you must first grab it in a temporary folder on your local filesystem (in your <b>var/</b> directory for instance, check your <b>VarDir</b> directive in site.ini), and then you pass the full path (use <b>realpath</b> PHP function) of your image to the <i>fromString()</i> method.

Damien Pobel

Monday 29 June 2009 3:48:00 am

Hi,

In addition, you can have a look to ezcsvimport.php script [1] bundled with eZ Publish which is a quite simple example of what Jérôme explains.

[1] http://pubsvn.ez.no/nextgen/trunk/bin/php/ezcsvimport.php

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

thibaut colin

Tuesday 30 June 2009 2:38:18 am

Thanks for your help. I'm going to test all this.