-
-
Notifications
You must be signed in to change notification settings - Fork 190
Custom exporter logic #2101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.0
Are you sure you want to change the base?
Custom exporter logic #2101
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
| - only a specific part of the site is relevant | ||||||
| - ... | ||||||
|
|
||||||
| For that, you can _override_ the `plone.exportimport.interfaces.IObjectsExporter` adapter. | ||||||
|
|
||||||
| On `overrides.zcml` add: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ```XML | ||||||
| <adapter | ||||||
| factory="my.addon.adapters.ObjectsExporter" | ||||||
| provides="plone.exportimport.interfaces.IObjectsExporter" | ||||||
| for="plone.base.interfaces.siteroot.IPloneSiteRoot" | ||||||
| /> | ||||||
| ``` | ||||||
|
|
||||||
| On `my.package.adapters.py` add: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ```python | ||||||
| class ObjectsExporter: | ||||||
|
|
||||||
| def __init__(self, obj): | ||||||
| self.obj = obj | ||||||
| self.errors = None | ||||||
|
|
||||||
| def get_objects(self, query, errors) -> Generator: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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**. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"sensible" means "it makes sense"
"sensitive" means "delicate" or "secret"