From: BenoƮt Pin Date: Thu, 19 Dec 2013 13:21:51 +0000 (+0100) Subject: Ajout script de migration zctl dossier standard vers btree. X-Git-Url: https://scm.cri.ensmp.fr/git/Plinn.git/commitdiff_plain/87728d9b4278a10b35c89d7ca114e9b0b60550dd?ds=inline;hp=12d3a4e2539507b7740d48499fbb33c349cca11e Ajout script de migration zctl dossier standard vers btree. --- diff --git a/_zctl/folders2BTrees.py b/_zctl/folders2BTrees.py new file mode 100644 index 0000000..a7b8a4a --- /dev/null +++ b/_zctl/folders2BTrees.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +from argparse import ArgumentParser +import os.path +from Acquisition import aq_base +from zope.site.hooks import setSite +from Products.CMFCore.CMFCatalogAware import CMFCatalogAware +import transaction +from OFS.interfaces import IObjectManager +from zope.interface import providedBy +from Products.Plinn.Folder import PlinnFolder +from Products.Plinn.HugePlinnFolder import HugePlinnFolder +from Products.Plinn.migration.folder import migrateFolder + +def recurseMigrateFolders(parent) : + for child in parent.objectValues() : + if IObjectManager.providedBy(child) : + recurseMigrateFolders(child) + if isinstance(child, PlinnFolder) and \ + not isinstance(child, HugePlinnFolder) : + migrated = migrateFolder(child, parent) + # pseudo _finishContrsuction to preserve dates. + migrated._setPortalTypeName('Huge Plinn Folder') + migrated.reindexObject() + + + + + +parser = ArgumentParser(description="Convert all regular Plinn Folder to Huge Plinn Folder") +parser.add_argument('portal_path') +parser.add_argument('--dry-run', action='store_true') +args = parser.parse_args() +portal = app.unrestrictedTraverse(args.portal_path) +setSite(portal) + +recurseMigrateFolders(portal) + +if not args.dry_run : + transaction.commit() \ No newline at end of file diff --git a/migration/__init__.py b/migration/__init__.py new file mode 100644 index 0000000..4287ca8 --- /dev/null +++ b/migration/__init__.py @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/migration/folder.py b/migration/folder.py new file mode 100644 index 0000000..55cd462 --- /dev/null +++ b/migration/folder.py @@ -0,0 +1,25 @@ +from Products.Plinn.HugePlinnFolder import HugePlinnFolder + +IGNORED_ATTRIBUTES = ('_objects',) + +def migrateFolder(old, container) : + print 'migrate %s' % old.absolute_url() + + origid = old.getId() + title = old.Title() + toBeSkipped = IGNORED_ATTRIBUTES + tuple(old.objectIds()) + + new = HugePlinnFolder(origid, title=title) + + for name in old.__dict__.keys() : + if name in toBeSkipped : + continue + else : + setattr(new, name, getattr(old, name)) + + new._populateFromFolder(old) + + container._delOb(origid) + container._setOb(origid, new) + + return container._getOb(origid)