views:

210

answers:

1

Hello, all.

I need to migrate data from a Plone-based portal to Liferay. Has anyone some idea on how to do it?

Anyway, I am trying to retrieve data from Data.fs and store it in a representation easier to work, such as JSON. To do it, I need to know which objects I should get from Plone's Data.fs. I already got the Products.CMFPlone.Portal.PloneSite instance from the Data.fs, but I cannot get anything from it. I would like to get the PloneSite instance and do something like this:

>>> import ZODB
>>> from ZODB import FileStorage, DB
>>> path = r"C:\Arquivos de programas\Plone\var\filestorage\Data.fs"
>>> storage = FileStorage.FileStorage(path)
>>> db = DB(storage)
>>> conn = db.open()
>>> root = conn.root()
>>> app = root['Application']
>>> plone_site = app.getChildNodes()[13] # 13 would be index of PloneSite object
>>> a = plone_site.get_articles()
>>> for article in a:
...    print "Title:", a.title
...    print "Content:", a.content
Title: <some title>
Conent: <some content>
Title: <some title>
Conent: <some content>

Of course, it did not need to be so straightforward. I just want some information about the structure of PloneSite and how to recover its data. Has anyone some idea?

Thank you in advance!

A: 

Once you've got ahold of the Plone site object, you can do a catalog query to find all content items in the site:

 >>> brains = site.portal_catalog.unrestrictedSearchResults()

This returns a list of "catalog brains", each of which contains some metadata about the item. You can get the full item from the brain:

 >>> for b in brains:
 ...     obj = b.getObject()

Assuming your Plone site is using Archetypes-based content, you can then iterate through the fields of the item's schema and use each field's accessor to retrieve its value:

 >>> for field in obj.Schema().fields():
 ...     field_id = field.__name__
 ...     field_value = field.getAccessor(obj)()

Since the ZODB is an object database that stores pickled Python objects, you will need to have the correct version of Archetypes present in your Python environment, as well as the package that defines the class of the objects you're trying to retrieve.

David Glick