Importing data into ez

Author Message

Claus Jensen

Wednesday 02 April 2003 11:59:12 pm

Hello,
is it possible to import data into content classes, and how do you do it if yes.

claÜs

Bård Farstad

Thursday 03 April 2003 12:06:52 am

Import of content classes and objects is not implemented in eZ publish at this time. So, to do imports you will need to write a script which does the job.

General imports are planned in future releases.

--bård

Documentation: http://ez.no/doc

Xavier Dutoit

Sunday 06 April 2003 3:37:52 am

Dear Bard,

I guess you've written some scripts to migrate the users from the previous ez site (2.x) to this new one (much bettter IMHO).

Would it be possible to publish these scripts as examples ?

Another point: how can you with the new interface reply to a reply post (eg. I wanted to reply to Bard post, but I could only do it with Claüs's one).

Thanks,

Xavier

http://www.sydesy.com

Jørgen Skogstad

Thursday 01 May 2003 3:28:28 am

Hi ..

Have you guys managed to write decent import scripts for Ez v3 yet? Would love to have some examples .. and see if I can contribute something. This is another area which is really important!

Kindest,
Jørgen Skogstad

Claus Jensen

Wednesday 15 October 2003 5:56:32 am

Hi again,
Im currently able to import a CSV file into ez-objects. The problem is that the whole file isnt imported. It runs to 249 or 250 objects every time, and then it stops...without any error. Does anybody have any ideas?? The script is based this:http://ez.no/developer/ez_publish_3/forum/developer/creating_a_simple_content_object_via_php

Here is part of the script. I didnt include the function createMetaObj(), since its working. I think the problem is elsewhere...

<?php
echo "Starting..." . time();
set_time_limit( 2500 ); //2500 sekunder, ca 41 minutter
//print( "Starting metadata import\n" );
include_once( "lib/ezutils/classes/ezdebug.php" );
//eZDebug::setHandleType( EZ_HANDLE_FROM_PHP );
include_once( "lib/ezutils/classes/ezmodule.php" );
eZModule::setGlobalPathList( array( "kernel" ) );
include_once( 'lib/ezutils/classes/ezexecution.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
eZDebug::setHandleType( EZ_HANDLE_TO_PHP );
eZDebug::setLogFileEnabled( false );
eZINI::setIsCacheEnabled( false );
function eZDBCleanup()
{
if ( class_exists( 'ezdb' )
and eZDB::hasInstance() )
{
$db =& eZDB::instance();
$db->setIsSQLOutputEnabled( false );
}
// session_write_close();
}
function eZFatalError()
{
eZDebug::setHandleType( EZ_HANDLE_NONE );
print( "Fatal error: eZ publish did not finish it's request\n" );
+
print( "The execution of eZ publish was abruptly ended." );
}
eZExecution::addCleanupHandler( 'eZDBCleanup' );
eZExecution::addFatalErrorHandler( 'eZFatalError' );
$db =& eZDB::instance();
$db->setIsSQLOutputEnabled( false );

//KLASSEID
$contentClassId = 28;
$userID = 15; //AUTHOR

//INPUTFILA
$handle = fopen ('importdata/WMO-Europe-stations_opencsv.xls', 'r');
//$handle = fopen ('importdata/stations_test', 'r');
//READING FILE
$counter = 0;
while ( !feof( $handle ) )
{
//$line = fgets( $handle, 4096 );
$line = fgets( $handle, 8192 );
//$columns = explode( ';', $line );
//SPLITTER PAA Tab
$columns = explode("\\t",preg_replace("/\t/","\\t",$line));

//REMOVING ALL "" FROM START AND END
foreach ($columns as $key => $val)
{
$val = rtrim($val, '"');
$val = ltrim($val, '"');
$columns[$key] = $val;
//print 'VERDI: ' . $val . ' ';
}

// Check that the line contains enough elements
//$columnCount = count( $columns );
// Get klubb
$strTitle = $columns[5] . ' - ' . $columns[7];
createMetaObj( $strTitle, $columns, $contentClassId, $userID );
//print '\n\n';
$counter++;
flush();
}
fclose( $handle );
eZExecution::cleanup();
eZExecution::setCleanExit();
echo "Done! " . time();
echo "Objects created: " . $counter;

Any ideas?

regards,
claÜs

Jan Borsodi

Thursday 16 October 2003 1:42:40 am

Do you know where it stops (which line/functioncall)?

--
Amos

Documentation: http://ez.no/ez_publish/documentation
FAQ: http://ez.no/ez_publish/documentation/faq

Claus Jensen

Monday 15 December 2003 4:56:15 am

Hi,
Sorry for answering late. Nope it gives no error or anything. Quite strange still.

regards,
claÜs

James Packham

Friday 30 January 2004 7:21:16 am

Hi,

I have a legacy system based on a Third party product called ArticleManager (some reference has been made to this in the forums before, I know), from which I need to output all the data for my new EZ Publish based website.

At the moment I've been staring at code and reading various documentation and forum posts for a few hours. I've also been toying with a bash script that basically extracts all the data to a text file and then to a csv (I have a number of these, one for each object class, each containing upto about 100 records). Since I'm a bit new to php and I'm still not sure what I'm doing, I was wondering if someone could explain a few parts of the Claus's script to me - so that I know what I have to change for my needs.

Looking at sections of Claus's code I think these are the bits I have to customise:

$contentClassId = 28;
$userID = 15;
$handle = fopen ('importdata/WMO-Europe-stations_opencsv.xls', 'r');
$columns = explode("\\t",preg_replace("/\t/","\\t",$line));

I just wanted to know:

a) am I right - is there anything else I need to change?

b) How do I define the delimiter for my csv file (which is like so "text","more text","....)?

c) How do I run the script (I assume it's just something like "php script.php" from the ez publish root directory)?

d) I've looked in the suggested places and I can't find the createMetaObj function, could anyone point me in the right direction?

Thanks in advance!

James

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.