eZ Community » Forums » Developer » Importing hundrets of articles
expandshrink

Importing hundrets of articles

Importing hundrets of articles

Monday 15 December 2003 11:43:52 am - 9 replies

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

Monday 15 December 2003 1:57:52 pm

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

cheers,
claÜs

Monday 15 December 2003 5:07:36 pm

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

Modified on Monday 15 December 2003 5:08:11 pm by Andreas S

Monday 15 December 2003 5:23:56 pm

Hi again,
Maybe this will help you further.

http://www.ez.no/developer/ez_pub...ting_a_simple_content_object_via_php

cheers,
claÜs

Monday 15 December 2003 5:49:23 pm

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

Monday 15 December 2003 6:38:24 pm

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... happy.gif Emoticon

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

Monday 15 December 2003 10: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

Tuesday 16 December 2003 7:51:35 am

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

Tuesday 16 December 2003 10: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

Tuesday 16 December 2003 10:55:13 am

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

Then I pasted inside the mymodulefunctioncollection.php the code from claus (thanks to both of youhappy.gif Emoticon
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

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from