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
52 changes: 52 additions & 0 deletions docs/admin-guide/export-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,58 @@ 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

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:

- sensible content should not be exported

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.

Suggested change
- sensible content should not be exported
- sensitive content should not be exported

"sensible" means "it makes sense"
"sensitive" means "delicate" or "secret"

- only a specific part of the site is relevant
- ...

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

On `overrides.zcml` add:

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.

Suggested change
On `overrides.zcml` add:
In {file}`overrides.zcml` add:


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

On `my.package.adapters.py` add:

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.

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


```python
class ObjectsExporter:

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

def get_objects(self, query, errors) -> Generator:

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.

Show the import of Generator

"""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


```{warning}
As soon as you override the export be aware that other parts of the export might not work.

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.

I was more worried about whether the import works. For example if 10% of content is exported by the content step but 100% of relations are exported by the relations step, then the import might fail when there is a relation that refers to one of the content items that was not included. Can you at least do a sanity check that this works in your case?


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


## Related content

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