eZ Community » Forums » Developer » Import CSV in EZP 3.9 : Missing doc
expandshrink

Import CSV in EZP 3.9 : Missing doc

Import CSV in EZP 3.9 : Missing doc

Friday 22 December 2006 1:06:26 pm - 32 replies

EZP is great...but lack documentation...in fact you should put exemples in your doc instead of theorical principles.

After some work here is the correct syntax to use : /bin/php/ezcsvimport.php

This script is great and saved my life...and a lot of hours :p

Here is the synthax for the script call : Importing product under node_id 80

php -C ./bin/php/ezcsvimport.php -v --siteaccess=mysite -l myuser -p mypasswd  -d --class=product --creator=14 --storage-dir='media/images' 80 absolute_path_to_csv

Here is the syntax of the csv file i use for importing my products (87-88 is a relationlist datatype to images object_id and last value is the price)

Blind;PE06B;POXLK;0;POWELL CREAM;'Description of my product';87-86;BLK;XL;1;7,00|1|1

Hope it will help.

Modified on Monday 25 December 2006 5:12:06 pm by H-Works Agency

Monday 25 December 2006 5:13:17 pm

How to import a ezxml datatype attribute ?

I tried a lot of different syntax but doesn't work.

Second thing is : What is the aim of the 'storage-dir' argument ?

Thanx

Tuesday 26 December 2006 9:29:59 am

Hi Martin

You need to use the XML format as it will be stored in the data_text database field. First try to create an object with the desired content manually, then lookup the value in the database in order to have an example.

The storage-dir option is prepended to the relative file path of ezmedia, ezimage and ezbinaryfile attributes. You can for example make absolute paths by using it.

Monday 29 January 2007 11:18:36 am

Hi,

I'm looking for a similar solution in order to import sql data in my ezpublish site.

I have the following structure :

Artist (artiste_id, name)
Album (album_id, name, year, #artiste_id)
Song (song_id, title, text, #album_id)

It's a very simple schema, and I would like to import this data in my ezpublish tree by automatically create :

1 Artiste class (container) instance by artist
1 Album class (container) instance by album and place them in her artist
1 Song class instance by song and place them in her album.

So I need your help because I don't know how to make link between artists, albums ans songs.

Thanks in advance !

Modified on Monday 29 January 2007 11:19:14 am by Sébastien Antoniotti

Monday 29 January 2007 1:26:25 pm

Hi,

When we have multiple relations, we uses the xml import.

For the relation, the problem is to make the link between the external relation and the internal object id. I doubt there is a universal solution, and we modify the import script (not a big deal, but needs to know php...

X+

Monday 29 January 2007 1:40:37 pm

Hi,

So I have to install the xml import contribution and custom it.

Thanks and good dev blunk.gif Emoticon

Monday 29 January 2007 2:05:00 pm

Hi,
another extension you can use is
http://pubsvn.ez.no/community/trunk/extension/import/

this is a framework to import any kind of data to ez.
But you have to write php code to use it.

Some Features:
- create contentobjects of any classes with attributes e.g. images, objectrelation, objectrelationlist, text ...
- you can create object or update it ( create new versions ) if your import script run more than one times

Have a look to the example.

Best Regards
Felix Woldt

Monday 29 January 2007 4:00:25 pm

Hi,

Thanks for this tip, but how can I download this contrib ?

Monday 29 January 2007 4:49:53 pm

<b>Use Subversion!</b>

<i>http://svnbook.red-bean.com/
http://ezpedia.org/wiki/en/ez/usi...vn_subversion_repositories</i>

<i>//kracker

Monty Python - Alzheimer Answering Machine
Gibbs, Richard and Jonathan Davis - Queen of the Damned - Air Lestat</i>

Modified on Monday 29 January 2007 4:56:09 pm by // kracker

Monday 29 January 2007 5:15:50 pm

Thanks, I don't know subversion at all !

Modified on Monday 29 January 2007 5:16:19 pm by Sébastien Antoniotti

Monday 29 January 2007 11:55:47 pm

You could learn the little you need to know if you really cared at all.

I have shared with you, links to the best documentation and teaching information available.

Those who fail to change will find themselves unable to communicate with those who have ...

Download Tortuous SVN a GUI to Subversion and get the code already happy.gif Emoticon
Or you can download the files one by one by hand :\

//kracker

<i>Cowboy Bebop - Blue 3

Any sympathy for the ***** in the crowd tonight?</i>

Modified on Monday 29 January 2007 11:56:41 pm by // kracker

Tuesday 30 January 2007 12:24:51 am

Here's also some subversion documentation the eZ crew have made:
http://ez.no/ezpublish/documentat...coming/the_community_server/help/svn

Tuesday 30 January 2007 9:24:54 am

Thanks for your help, I'm downloading tortoise blunk.gif Emoticon

Tuesday 30 January 2007 1:33:35 pm

The import script in the 3.9 install uses toString() or fromString() for export & import.

Those function are only available from 3.9+ so if you are in 3.8 my syntax won't apply.

You could use the import csv function but possible datatypes are limited.

Wednesday 07 February 2007 6:31:15 pm

I'm using the ezcsvimport.php script to import almost all kind of data with sucess, including product prices. I'm only having problems when I try to import data wich should be stored at a ezuser datatype.

I checked the toString and fromString documentation [1] and it seams that to import to a ezuser datatype you should have at the .csv file a field with the following configuration:

login|email|password hash|password hash type

I'm generating the password hash with md5 and I'm using the password hash type equal to 1.

When I import the data everything gets imported except the ezuser data. I'm I doing something wrong?

[1] http://pubsvn.ez.no/nextgen/trunk...om_string_datatype_functionality.txt

Modified on Wednesday 07 February 2007 6:32:34 pm by Rodrigo Pinheiro

Wednesday 07 February 2007 8:29:20 pm

I didn't try to import user data but i don't think the password hash is a md5...its has to be confirmed. And maybe you should try other password types.

Sorry for the poor help.

Martin

Thursday 08 February 2007 7:41:18 pm

I've managed to import the users by modifying the script.

    $attributes =& $contentObject->contentObjectAttributes();

    while ( list( $key, $attribute ) = each( $attributes ) )
    {
        $dataString = $objectData[$key];
        switch ( $datatypeString = $attribute->attribute( 'data_type_string' ) )
        {
            case 'ezimage':
            case 'ezbinaryfile':
            case 'ezmedia':
                $dataString = $storageDir . $dataString;
                break;
            case 'ezprice':
                $dataString = $dataString . '|1|0';
                break;
            case 'ezuser':
                $userAccountObject = eZUser::fetch($attribute->ContentObjectID);
                $username = 'client' . $objectData[0];
                $email = $objectData[7];
                $password = eZUser::createPassword(6, 0);
                $confirmPassword = $password;
                $password_hash = md5( "$username\n$password" );

                $userAccountObject->setInformation($contentObject->attribute('id' ), $username, $email, $password, $confirmPassword);
                $userAccountObject->store();
                break;
        }
        $attribute->fromString( $dataString );
        $attribute->store();

    }

What I'm doing above is getting the internal client number and email so I can generate a username + password to store at a ezuser datatype. It works, but it imports the .csv very slowly.

Friday 09 February 2007 12:15:02 pm

Hi,

Precedently I wrote this :

<i>
I have the following structure :

Artist (artiste_id, name)
Album (album_id, name, year, #artiste_id)
Song (song_id, title, text, #album_id)

It's a very simple schema, and I would like to import this data in my ezpublish tree by automatically create :

1 Artiste class (container) instance by artist
1 Album class (container) instance by album and place them in her artist
1 Song class instance by song and place them in her album.
</i>

And today I haved downloaded the importXML extention, and inspected the importXMLDatafunctioncollection.php.
I understand a little the import procedure with Ez libs, and I would like to write a script that
- make connection to a mysql database
- query all the albums in album_table
- for each album, create an instance of my ezpublish Album class in a parent_node "hard coded"
- query all the songs related to the current album
- for each song create an instance of my ezpublish Song class into the album instance created precedently
-etc.

So I have to modify the importXMLDatafunctioncollection.php, but before start I would like to know if I can place this script into the ezpublish root directory, and call it by the shell.

I ask you that because I think in my case a module is not necessary (this import will be run a single time).

Thanks in advance !

Friday 09 February 2007 3:07:07 pm

Can you tell me what you think about this ?

include_once ('lib/ezlocale/classes/ezdate.php');
include_once ('lib/ezutils/classes/ezoperationhandler.php');

eZINI::setIsDebugEnabled( true );

/* ############## Fonction qui ajoute un album dans un artiste  ################## */

function ajouterAlbum( $titre, $annee, $remove, $idArtisteParent)
{ 
	// identifiant de la classe album
	$identifiantClasse = "10";
	$class =& eZContentClass::fetchByIdentifier( $identifiantClasse );
	// ID du noeud de l'artiste parent de cet album 
	$node_id=$idArtisteParent;
	
	// fetch parent node 
		$node =& eZContentObjectTreeNode::fetch($node_id);
	// set associated object to parent node (folder object) 
	if ( !is_object( $node ) ) {
		eZDebug::writeDebug( "node_id=$node_id doesn't seem to be a valid node id", 'importSQLData' );
		return array( 'result' => array('statut' => "erreur"), 'msg' => "node_id=$node_id doesn't seem to be a valid node id" );  
	}
	$parentContentObject =& $node->attribute( 'object' );
	
	/* --------- ici mettre mon id d'user en dur ------- */
	// set user = current user 
	$user =& eZUser::currentUser();
	// set user ID 
	$userID =& $user->attribute( 'contentobject_id' );
	// set section ID =  parent object section
	
	$sectionID = $parentContentObject->attribute( 'section_id' );
	if ($remove) {
		$children =& $node->subTree( array( 'Limitation' => array() ) );
		$deleteIDArray = array();
		foreach ($children as $child) {
			array_push ($deleteIDArray, $child->attribute( 'node_id' ));
		}
		eZContentObjectTreeNode::removeSubtrees( $deleteIDArray, $movetotrash );
	}

	if ( !is_object( $class ) ) {
		eZDebug::writeDebug( "DefaultClassIdentifier=$identifiantClasse doesn't seem to be a valid class identifier", 'importSQLData' );
		return array( 'result' => array('statut' => "erreur"), 'msg' => "DefaultClassIdentifier=$identifiantClasse doesn't seem to be a valid class identifier" );  
	}
		
	// Crée une instance d'album
	$contentObject =& $class->instantiate( $userID, $sectionID );

	// La ratache à son artiste en créant le noeud
	$nodeAssignment =& eZNodeAssignment::create( array(
			 'contentobject_id' => $contentObject->attribute( 'id' ),
			 'contentobject_version' => $contentObject->attribute( 'current_version' ),
			 'parent_node' => $node->attribute( 'node_id' ),
			 'is_main' => 1 ));
	$nodeAssignment->store();

	// Spécifie la version de l'objet
	$contentObjectVersion =& $contentObject->version($contentObject->attribute( 'current_version' ) );
	$contentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT);
	$contentObjectVersion->store();

	// Enumere les attributs du nouvel objet (album) pour les renseigner
	$contentObjectAttributes =& $contentObjectVersion->contentObjectAttributes();
	foreach ($contentObjectAttributes as $attribute)
	{
		$identifiantAttribut=$attribute->attribute("contentclass_attribute_identifier");			
		 
		switch( $identifiantAttribut ) {
			case 'titre':
				$attribute->setAttribute("data_text",trim($titre));
				break;				
			case 'annee':
				$attribute->setAttribute("data_int",$annee);
				break;				
			default :					
		}	
		$attribute->store();			
	}			
		
	//publish the newly created node
	$operationResult = eZOperationHandler::execute( 'content', 
													'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
													'version' => $contentObject->attribute( 'current_version' ) ) );
	return $nodeAssignment->attribute('id');			
}

This fonction create an album instance under the parent node id given by parameter.

For the moment I cant test them because first I need to install a test version of ezpublish to avoid a trouble in my website.

So if this fonction is good, did you think that I can execute this script by the unix shell ?

Friday 09 February 2007 3:27:33 pm

It's still me !

I have tried to run my script by "php script.php" and I got this :

Fatal error: Undefined class name 'ezcontentclass' in /var/www/eztest/importSQLData_seb.php on line 21

I think I must include one or many library but I don't know wich...

Friday 09 February 2007 3:29:25 pm

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.

Modified on Friday 09 February 2007 3:49:17 pm by Kristof Coomans

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from