Commit 13a56b51 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Products Documents for a given bt5 can now be migrated from filesystem.

Until now, only bt5 Extension/Test/Document could be migrated from
filesystem.

From migration dialog, allow to select any Products.ERP5.Document.* (only,
for now) to be migrated. By default, automatically select Products Documents
used by the current bt5 Portal Types (by looking at the mro() of its
erp5.portal_type classes).

Also, to easily identified where it was migrated from, source_reference
is set to 'bt.getTitle():ID' for bt5 Extension/Test/Document and
'Products.ERP5.Document.XXX' for filesystem Products.
parent 87d682c6
This diff is collapsed.
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>text</string> </key> <key> <string>text</string> </key>
<value> <string>python: portal.Base_checkPermission(\'portal_components\', \'Add portal content\') and context.getInstallationState() != \'installed\' and [id_ for id_ in (context.getTemplateExtensionIdList() + context.getTemplateDocumentIdList() + context.getTemplateTestIdList()) if not id_.startswith(\'extension.\') and not id_.startswith(\'document.\') and not id_.startswith(\'test.\') ]</string> </value> <value> <string>python: portal.Base_checkPermission(\'portal_components\', \'Add portal content\') and context.getInstallationState() != \'installed\'</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -403,6 +403,10 @@ ...@@ -403,6 +403,10 @@
<string>reference</string> <string>reference</string>
<string>Name</string> <string>Name</string>
</tuple> </tuple>
<tuple>
<string>source_reference</string>
<string>Module</string>
</tuple>
<tuple> <tuple>
<string>portal_type</string> <string>portal_type</string>
<string>Destination Portal Type</string> <string>Destination Portal Type</string>
...@@ -549,7 +553,7 @@ ...@@ -549,7 +553,7 @@
</item> </item>
<item> <item>
<key> <string>select</string> </key> <key> <string>select</string> </key>
<value> <int>0</int> </value> <value> <int>1</int> </value>
</item> </item>
<item> <item>
<key> <string>selection_name</string> </key> <key> <string>selection_name</string> </key>
......
This diff is collapsed.
...@@ -68,7 +68,7 @@ class IComponent(Interface): ...@@ -68,7 +68,7 @@ class IComponent(Interface):
Return the ID prefix for Component objects Return the ID prefix for Component objects
""" """
def importFromFilesystem(cls, context, reference, version): def importFromFilesystem(cls, context, reference, version, source_reference=None):
""" """
Import a Component from the filesystem into ZODB after checking that the Import a Component from the filesystem into ZODB after checking that the
source code is valid source code is valid
......
...@@ -345,14 +345,21 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -345,14 +345,21 @@ class ComponentMixin(PropertyRecordableMixin, Base):
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'importFromFilesystem') 'importFromFilesystem')
@classmethod @classmethod
def importFromFilesystem(cls, context, reference, version): def importFromFilesystem(cls, context, reference, version, source_reference=None):
""" """
Import a Component from the filesystem into ZODB and validate it so it can Import a Component from the filesystem into ZODB and validate it so it can
be loaded straightaway provided validate() does not raise any error of be loaded straightaway provided validate() does not raise any error of
course course
""" """
import os.path import os.path
path = os.path.join(cls._getFilesystemPath(), reference + '.py') if source_reference is None or not source_reference.startswith('Products'):
path = os.path.join(cls._getFilesystemPath(), reference + '.py')
else:
import inspect
module_obj = __import__(source_reference, globals(), {},
level=0, fromlist=[source_reference])
path = inspect.getsourcefile(module_obj)
with open(path) as f: with open(path) as f:
source_code = f.read() source_code = f.read()
...@@ -363,6 +370,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -363,6 +370,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
object_id = '%s.%s.%s' % (cls.getIdPrefix(), version, reference) object_id = '%s.%s.%s' % (cls.getIdPrefix(), version, reference)
new_component = context.newContent(id=object_id, new_component = context.newContent(id=object_id,
reference=reference, reference=reference,
source_reference=source_reference,
version=version, version=version,
text_content=source_code, text_content=source_code,
portal_type=cls.portal_type) portal_type=cls.portal_type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment