Ajout script de migration zctl dossier standard vers btree.
authorBenoît Pin <benoit.pin@gmail.com>
Thu, 19 Dec 2013 13:21:51 +0000 (14:21 +0100)
committerBenoît Pin <benoit.pin@gmail.com>
Thu, 19 Dec 2013 13:21:51 +0000 (14:21 +0100)
_zctl/folders2BTrees.py [new file with mode: 0644]
migration/__init__.py [new file with mode: 0644]
migration/folder.py [new file with mode: 0644]

diff --git a/_zctl/folders2BTrees.py b/_zctl/folders2BTrees.py
new file mode 100644 (file)
index 0000000..a7b8a4a
--- /dev/null
@@ -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 (file)
index 0000000..4287ca8
--- /dev/null
@@ -0,0 +1 @@
+#
\ No newline at end of file
diff --git a/migration/folder.py b/migration/folder.py
new file mode 100644 (file)
index 0000000..55cd462
--- /dev/null
@@ -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)