Forums / Developer / Import CSV in EZP 3.9 : Missing doc

Import CSV in EZP 3.9 : Missing doc

Author Message

Kristof Coomans

Friday 09 February 2007 6:29:25 am

Hi Sébastien,

Include kernel/classes/ezcontentclass.php

a little bit off topic but maybe this one can be useful for you too: http://pubsvn.ez.no/community/trunk/extension/cddb. I'll upload the content classes I use this weekend.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Sébastien Antoniotti

Friday 09 February 2007 7:10:41 am

Hi Kristof ,

Thanks for your help, I have looked your module, but you don't include the library who contains the eZContentClass declaration. I think this is because you are into a module, but I'm not into a module (I execute my script by the shell).

I have included this files :

include_once( 'kernel/classes/ezcontentclass.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/eznodeassignment.php' );

And running this :

$newAlbumId=ajouterAlbum($album1_name,$album1_year,true,64);
print_r($newAlbumId);

I get this error :

Array
(
    [result] => Array
        (
            [statut] => erreur
        )

    [msg] => node_id=64 doesn't seem to be a valid node id
)

But 64 is a valid node id, so I think that this instruction : $node =& eZContentObjectTreeNode::fetch($node_id);
is not executed properly, but I don't know why =(

eZ Publish Freelance
web : http://www.webaxis.fr

Kristof Coomans

Friday 09 February 2007 7:25:30 am

Hi Sébastien

It's better to write a real eZ command line script by using the eZScript class, so your eZ environment gets initialized properly. Take a look at the scripts in bin/php as an example. There are also some related code snippets on eZpedia: http://ezpedia.org/wiki/en/content/search?SearchText=script

Some other useful forum topics:
http://ez.no/community/forum/developer/php_script_problem
http://ez.no/community/forum/developer/launching_a_script

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Sébastien Antoniotti

Friday 09 February 2007 7:42:33 am

This links are very good !!

I think I can succes with this, thanks ;)

eZ Publish Freelance
web : http://www.webaxis.fr

Kristof Coomans

Friday 09 February 2007 7:48:36 am

Stub node on eZpedia: http://ezpedia.org/wiki/en/ez/command_line_scripts

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Sébastien Antoniotti

Friday 09 February 2007 8:00:43 am

dev evening in perspective !

eZ Publish Freelance
web : http://www.webaxis.fr

Daniele Nocentini

Wednesday 28 February 2007 12:54:43 am

Hello!
I try the ezcvsimport function with a simple class with only eztextline datatype, now I would like to try with date or date/time datatype, what is the right syntax in cvs file for this datatype?

Antica Bottega Digitale srl
http://www.abd.it

H-Works Agency

Thursday 08 March 2007 7:21:45 am

What is the correct syntax to import 'ezoption' datatype ?

Thanx

EZP is Great

Stefan de Bruijn

Sunday 15 July 2007 11:17:38 am

When trying to import data into a custom class, which contains an ezuser type, i get the following error:

# php bin/php/ezcsvimport.php -d -v --creator=14 --class=ow_persoon 203 teztuser.csv
Going to import objects of class ow_persoon under  node 203 from file teztuser.csv

Fatal error: Call to a member function on a non-object in /.../kernel/classes/datatypes/ezuser/ezusertype.php on line 393

With the modification from Rodrigo Pinheiro i got the same result, maybe because this only works for the standard 'user' class. With a mod of his mod, i can now import ezusers:

At line ' switch ( $datatypeString = $attribute->attribute( 'data_type_string' ) ) { '
Add the following case:


		case 'ezuser':
		// create array of userdata
		$csvUserData = explode( '|', $dataString );
	   	$userAccountObject = eZUser::fetch($attribute->ContentObjectID);
		
		// only first 2 items are used
		$username = $csvUserData[0];
               	$email = $csvUserData[1];
               	
               	// password is created by ez publish, not from csv
               	$password = eZUser::createPassword(6, 0);
               	$confirmPassword = $password;
               	$password_hash = md5( "$username\n$password" );
               	$userAccountObject->setInformation($contentObject->attribute('id' ), $username, $email, $password, $confirmPassword);
               	$userAccountObject->store();
               	// echo user and created password 
               	echo "user: " . $username . " password: " . $password;
               	break;

Kristof Coomans

Wednesday 18 July 2007 5:49:36 am

The error you get is probably related to this bug report: http://issues.ez.no/11092

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Daniele Nocentini

Monday 30 June 2008 9:01:08 am

When I try to import string that contain a special char such as "è à ì ò" frequent in italian's words, the import script truncate the string before the special char.

Antica Bottega Digitale srl
http://www.abd.it

H-Works Agency

Tuesday 01 July 2008 3:10:52 am

Hello,

I think this is a charset problem between your string and ezp.

You should try to make both compatible. Maybe using a utf8_encode(), or another charset conversion php function, before passing your string to the toString() import function.

EZP is Great

Daniele Nocentini

Tuesday 01 July 2008 3:31:08 am

I have modified the line 163 from:

$attribute->fromString( $dataString );

to:

$attribute->fromString( utf8_encode($dataString) );

now work fine and import also string with special chars.

Thanks.

Antica Bottega Digitale srl
http://www.abd.it