How I import and export content

Over the time i've been looking for a way to import and export content from Plone to Plone or AnyData to Plone with the minimal specific programming possible.
Every time we had (in the business I work) to do an export/import of content we used to create an external method which handles the task, so over time I tried different ways to automate the process and the solutions I finished implemented are python classes which, with minimum configuration, handle all the process by themselves.
Right now I got 2 classes one for the exporter and other for the importer:



Exporting

The exporter takes as parameters the portal object, the schema of the archetype to export (never needed to export dexterity for the moment) and the metatype of the content type.
It generates a XML with all the info needed to the other class about the fields and a log file of the process.

def my_external_method(self):
  portal_url = getToolByName(self, 'portal_url')
  portal     = portal_url.getPortalObject()
  
  export = Exporter(
            portal,
            MyContentType.schema,                  # My Archetype schema
            MyContentType.MyContentType.meta_type) # meta_type name for query catalog

Importing

The importer takes as parameters the portal object, the path to the xml file, and the path of the folder where you want to store the objects. Thats all, if you want/need you can define a mapping of the attributes and filters for the values (everything explained at the repo).

def my_external_method(self):
  portal_url = getToolByName(self, 'portal_url')
  portal     = portal_url.getPortalObject()

  Importer(
    portal = portal,
    xml_path = '/tmp/import/Event.xml',
    folder_path = '/fs-mysite/mysite/activity-schedule')

I've been thinking about turning it into a product with an ajax UI and add to the exporter the ability to export all the data in a nested way, and by this way reproduce all the tree structure from one Plone to another.


Had an other class to import to Archetypes, but is one of the first things I programmed for Plone and we don't use Archetypes anymore:

https://github.com/collective/plone.importexport is being worked on as part of the GSOC this year by @Shriyanshagro. It uses plone.rest under the hood and I believe that works with both AT and DX but I'm not sure. It is plone5 only however.
I'm sure any advice or testing would be welcome.

It's here https://github.com/Shriyanshagro/plone.importexport/tree/UI

we've forked https://github.com/zopyx/zopyx.plone.migration in the past to get content out of plone 2.x and 3.x and import into 4.3 as i was not able to wrap my head around collective.transmogrifier.
as migrations are always customer specific i like the idea of having a script as a basis and simply plug in exceptions (like if portal_type=='Foo': do_some_extra_task(obj) where you need them.

since plone.importexport (thanks for the pointer btw!) is meant to only support plone5, you package might be still have good reasons to exist/be written.
maybe you find some useful ideas/concepts in zopyx.plone.migration

I'm glad I'm in such elite company!!! :smiley:

Plone Foundation Code of Conduct