Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/admin-guide/export-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,66 @@ Consider a File content item with UID `3e0dd7c4b2714eafa1d6fc6a1493f953` and a P
| `content/3e0dd7c4b2714eafa1d6fc6a1493f953/data.json` | JSON File with serialized representation of a content item |
| `content/3e0dd7c4b2714eafa1d6fc6a1493f953/file/plone.pdf` | Blob file stored in the `file` field in the content item |


## Custom export

```{versionadded} Plone 6.3
The `IObjectsExporter` adapter is new in Plone 6.3.
Prior to it, although possible, it was harder to customize the content exporter.
```

By default, all content from an existing Plone site is exported.
While that's great for migrations, it is not practical/feasible for larger sites.

There are other scenarios where a custom data export makes sense:

- sensitive content should not be exported
- only a specific part of the site is relevant
- ...

For that, you can _override_ the `plone.exportimport.interfaces.IObjectsExporter` adapter.

In {file}`overrides.zcml` add:

```XML
<adapter
factory="my.addon.adapters.ObjectsExporter"
provides="plone.exportimport.interfaces.IObjectsExporter"
for="plone.base.interfaces.siteroot.IPloneSiteRoot"
/>
```

In {file}`my.package.adapters.py` add:

```python
from collections.abc import Generator


class ObjectsExporter:

def __init__(self, obj):
self.obj = obj
self.errors = None

def get_objects(self, query, errors) -> Generator:
Comment thread
gforcada marked this conversation as resolved.
"""Return all objects to be serialized"""
self.errors = errors

yield from self.gather_objects()

def gather_objects(self):
# custom logic to select which specific content gets exported
```

With this, the default `plone-exporter` will no longer export **all content**.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit of a limitation. Maybe you want all of the content sometimes, and different subsets at other times. This makes me wonder whether we should have named IObjectsExporter adapters, and make it possible to specify which one to use in the CLI

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had quite a few ideas to improve what gets exported:

  • add a control panel that lists what gets exported (a fancy print of what IObjectsExporter returns)
  • add dexterity behavior that allows to mark objects to be always/never exported
    • thinking about privacy or mandatory objects
  • on that control panel add a checkbox to use either the full or subset export

I'm not sure if there are enough users for such use cases, that's why we started with first allowing to customize the logic, and then we can expand further if there is a need for it


```{warning}
As soon as you override the export be aware that other parts of the export might not work.
Comment thread
davisagli marked this conversation as resolved.

Carefully check that your custom objects exporter works as expected.
```


## Related content

- {doc}`/admin-guide/backup-restore-plone-buildout`
Expand Down