Importing hundrets of articles

Author Message

andreas spahr

Monday 15 December 2003 2:43:52 am

Hi there,

can someone tell me how I can easily import hundrets of articles, all of them are of course in the same structure and should be in on folder.
Some hints?

Thanks in advance,
andreas

Claus Jensen

Monday 15 December 2003 4:57:52 am

Hello,
I've done a lot of this with custom objects. Look here for scripts: http://ez.no/developer/ez_publish_3/forum/developer/importing_data_into_ez
or search for 'import data' on this site for several scripts etc.

cheers,
claÜs

andreas spahr

Monday 15 December 2003 8:07:36 am

Hi Claus,
thx very much for your reply. It looks like a big set of trouble!
In your example code there is the function createMetaObj, which seems to make the whole work, but is missing in the forum.
And the other script is not running, it starts troubling on this line:
$nodeAssignment->store();

Do you have a running script for this tricky issue?

Thanks,
andreas

Claus Jensen

Monday 15 December 2003 8:23:56 am

Hi again,
Maybe this will help you further.

http://www.ez.no/developer/ez_publish_3/forum/developer/creating_a_simple_content_object_via_php

cheers,
claÜs

andreas spahr

Monday 15 December 2003 8:49:23 am

Hi Claus,
thanks again. Your script looks good, I copied it out but I got this error message:
Call to a member function on a non-object in myimport.php on line 62:
$nodeAssignment->store();

Whats wrong? I'm logged in as admin with the my IE instance. Do you have a clue?
best regards,
andreas

Jerry Jalava

Monday 15 December 2003 9:38:24 am

Hi Andreas,

I have done an import script from 3rd party software "ArticleManager".

Our old portal was using that as a news and article publishing interface and there was over 2000 articles and news in over 20 categories...

Now they are all safely inside eZ Publish with images, categories and everything... :)

It is done as an shell executable php script.

The code is still unclean and without documentation, but will publish it as soon as I have time.

Regards,
Jerry

Vincent Saulnier

Monday 15 December 2003 1:07:59 pm

Do you have an idea of when you will be able to publish your script. It would help me a lot.

Even if you don't document it, it would help me to get something like that.

Thanks in advance!

--
Vincent

andreas spahr

Monday 15 December 2003 10:51:35 pm

Hi Jerry,
sounds very good, so there is some hope for a solution.
As Vincent wrote, it would really help, even it is uncommented.
For me is the major problem to get a clue how to accomplish it, there is no need for a fully parameterised function or class.
As I wrote above I failed with the given hints, so some more hints could improve my attempts.
best regards,
andreas

Claus Jensen

Tuesday 16 December 2003 1:34:12 am

Hi again,
This script is used on 3.2-1 on a linux redhat 9 with apache 2, what version of ez and platform are you using? Could it have something to do with that?
And also publish your code then we might be able to debug it.

From what you write:
"Call to a member function on a non-object in myimport.php on line 62:
$nodeAssignment->store();

Whats wrong? I'm logged in as admin with the my IE instance. Do you have a clue?"

Its clear that there is $nodeAssignment is not instatiated as an object in some way.

cheers,
claÜs

andreas spahr

Tuesday 16 December 2003 1:55:13 am

Hello together,
i made some progress. I did the following:
First I followed Jerrys tutorial:
http://www.ez.no/developer/ez_publish_3/documentation/development/extensions/module/module_tutorial_part_1

Then I pasted inside the mymodulefunctioncollection.php the code from claus (thanks to both of you:)
this is the mymodulefunctioncollection.php:
---------------------
include_once( 'extension/mymodule/modules/mymodule/mymodule.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );

class MyModuleFunctionCollection
{

function MyModuleFunctionCollection()
{
}

function &fetchList( $offset, $limit )
{
$parameters = array( 'offset' => $offset,
'limit' => $limit );
$lista =& Mymodule::fetchListFromDB( $parameters );

while (list ($key, $val) = each ($lista)) {

// $contentClassId = 2; // For article (title (required), intro (required), body
$contentClassId = 10; // For info page (name (required), body
// $contentClassId = 14; // For ImportArticle (name (required), body

//fetch this class
$class =& eZContentClass::fetch( $contentClassId );
$userID = 1; //The userId creating it. Root = 1
// Instantiate the object with user $userID and put it in section 1.
$contentObject =& $class->instantiate( $userID, 1 );

$name = "Blah blablablablabla"; //What should this be?
//Answer: Object name

$contentObject->setAttribute( 'name', $name );

$parentNodeID = 2; // choose where to put the object

$nodeAssignment =& eZNodeAssignment::create( array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => $contentObject->attribute( 'current_version' ),
'parent_node' => $parentNodeID,
'sort_field' => 2,
'sort_order' => 0,
'is_main' => 1
)
);
$nodeAssignment->store();

$version =& $contentObject->version( 1 );

$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();

$contentObjectID = $contentObject->attribute( 'id' );
$contentObjectAttributes =& $version->contentObjectAttributes();

$attributeValue = $key . ' and ' . $val;

$contentObjectAttributes[0]->setAttribute( 'data_text', $attributeValue);
$contentObjectAttributes[0]->store();

$contentObjectAttributes[1]->setAttribute( 'data_text', $attributeValue);
$contentObjectAttributes[1]->store();

$contentObject->store();

// Publish it
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID,
'version' => 1 ) );
}

return array( 'result' => &$lista );
}

}
-----------------------------

Okey, this isn't a nice hack, but anyway. Now I can import the data from the tutorial db table via /index.php/news_admin/mymodule/list (as you can see, i'm working in the news sample installation)

The following problems are remaining:
1) I had to modify the xml textfield to textfield of the class 'info page', because the scriptlet above failes at xml fields.
2) a new created class runs into an error, so i had to use the info class.
3) there are errors remaining in the debug: Can't open file: 'ezsearch_object_word_link.MYI'

I'm going now to extend the db table from the tutorial.

best regards,
andreas

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