Skip to content

Commit

Permalink
expertiment with exporting revisions (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Feb 12, 2022
1 parent 160accb commit 4893a92
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/collective/exportimport/export_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from collective.exportimport.interfaces import IRawRichTextMarker
from operator import itemgetter
from plone import api
from plone.app.layout.viewlets.content import ContentHistoryViewlet
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.restapi.interfaces import ISerializeToJson
from plone.restapi.serializer.converters import json_compatible
from Products.CMFPlone.interfaces.constrains import ISelectableConstrainTypes
from Products.CMFPlone.interfaces.constrains import ENABLED
from Products.CMFPlone.interfaces.constrains import ISelectableConstrainTypes
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getMultiAdapter
Expand Down Expand Up @@ -106,6 +107,7 @@ def __call__(
include_blobs=1,
download_to_server=False,
migration=True,
include_revisions=False,
):
self.portal_type = portal_type or []
if isinstance(self.portal_type, str):
Expand Down Expand Up @@ -134,6 +136,7 @@ def __call__(
("1", "as base-64 encoded strings"),
("2", "as blob paths"),
)
self.include_revisions = include_revisions

self.update()

Expand Down Expand Up @@ -284,6 +287,8 @@ def export_content(self):
item = self.fix_url(item, obj)
item = self.export_constraints(item, obj)
item = self.export_workflow_history(item, obj)
item = self.export_revisions(item, obj)

if self.migration:
item = self.update_data_for_migration(item, obj)
item = self.global_dict_hook(item, obj)
Expand Down Expand Up @@ -450,6 +455,26 @@ def export_workflow_history(self, item, obj):
item["workflow_history"] = results
return item

def export_revisions(self, item, obj):
if not self.include_revisions:
return item
serializer = getMultiAdapter((obj, self.request), ISerializeToJson)
content_history_viewlet = ContentHistoryViewlet(obj, self.request, None, None)
content_history_viewlet.navigation_root_url = ""
content_history_viewlet.site_url = ""
full_history = content_history_viewlet.fullHistory()
history = [i for i in full_history if i["type"] == "versioning"]
if not history or len(history) == 1:
return item
item["exportimport.versions"] = {}
# don't export the current version again
for history_item in history[1:]:
version_id = history_item["version_id"]
item_version = serializer(include_items=False, version=version_id)
item_version = self.update_data_for_migration(item_version, obj)
item["exportimport.versions"][version_id] = item_version
return item


def fix_portal_type(portal_type):
normalizer = getUtility(IIDNormalizer)
Expand Down
17 changes: 17 additions & 0 deletions src/collective/exportimport/templates/export_content.pt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@
</label>
</div>

<div class="field mb-3">
<label>
<input
type="checkbox"
class="form-check-input"
name="include_revisions:boolean"
id="include_revisions"
value="1"
tal:attributes="checked python: 'checked' if view.include_revisions else ''"
/>
Include revisions.
<span class="formHelp">
Export all revisions of each exported item. Warning: This can significantly slow down the export!
</span>
</label>
</div>

<div class="field mb-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="download_to_server:int" value="0" id="download_local" checked="checked">
Expand Down

0 comments on commit 4893a92

Please sign in to comment.