Commit 911295b6 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: Fix bt5 import from an archive.

The code wrongly assumed that the .py file (containing source code of a
Component) was on the filesystem upon import but importing from an archive
uses tarfile and does not extract anything...
parent aa992476
...@@ -63,6 +63,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces ...@@ -63,6 +63,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from Products.ERP5Type.Core.PropertySheet import PropertySheet as PropertySheetDocument from Products.ERP5Type.Core.PropertySheet import PropertySheet as PropertySheetDocument
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from OFS import SimpleItem, XMLExportImport from OFS import SimpleItem, XMLExportImport
from cStringIO import StringIO from cStringIO import StringIO
...@@ -3952,31 +3953,43 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem): ...@@ -3952,31 +3953,43 @@ class DocumentTemplateItem(FilesystemToZodbTemplateItem):
def _importFile(self, file_name, file_obj): def _importFile(self, file_name, file_obj):
""" """
Upon import, only consider XML file for ZODB Components (as the Python This will be called once for non-migrated Document and twice for ZODB
source file will be read and set to text_content property on the new Components (for .xml (metadata) and .py (source code)). This code MUST
object when the XML will be processed) and for backward compatibility, consider both bt5 folder (everything is on the FS) and tarball (where in
handle non-migrated Document as well case of ZODB Components, .xml may have been processed before .py and vice
versa.
""" """
if file_name.endswith('.py'): tv = getTransactionalVariable()
# If portal_components/XXX.py, then ignore it as it will be handled when obj_key, file_ext = os.path.splitext(file_name)
# the .xml file will be processed # id() for installing several bt5 in the same transaction
tv_obj_key = "%s-%s" % (id(self), obj_key)
if file_ext == '.py':
# If this Document has not been migrated yet (eg not matching
# "portal_components/XXX.py"), use legacy importer
if file_obj.name.rsplit(os.path.sep, 2)[-2] != 'portal_components': if file_obj.name.rsplit(os.path.sep, 2)[-2] != 'portal_components':
FilesystemDocumentTemplateItem._importFile(self, file_name, file_obj) FilesystemDocumentTemplateItem._importFile(self, file_name, file_obj)
elif file_name.endswith('.xml'): # For ZODB Components: if .xml have been processed before, set the
# source code property, otherwise store it in a transactional variable
# so that it can be set once the .xml has been processed
else:
text_content = file_obj.read()
try:
obj = self._objects[obj_key]
except KeyError:
tv[tv_obj_key] = text_content
else:
obj.text_content = text_content
elif file_ext == '.xml':
ObjectTemplateItem._importFile(self, file_name, file_obj) ObjectTemplateItem._importFile(self, file_name, file_obj)
self._objects[obj_key].text_content = tv.get(tv_obj_key, None)
name = file_name[:-4]
obj = self._objects[name]
with open(file_obj.name[:-4] + ".py") as f:
obj.text_content = f.read()
# When importing a Business Template, there is no way to determine if it # When importing a Business Template, there is no way to determine if it
# has been already migrated or not in __init__() when it does not # has been already migrated or not in __init__() when it does not
# already exist, therefore BaseTemplateItem.__init__() is called which # already exist, therefore BaseTemplateItem.__init__() is called which
# does not set _archive with portal_components/ like # does not set _archive with portal_components/ like
# ObjectTemplateItem.__init__() # ObjectTemplateItem.__init__()
self._archive[name] = None self._archive[obj_key] = None
del self._archive[name[len('portal_components/'):]] del self._archive[obj_key[len('portal_components/'):]]
else: else:
LOG('Business Template', 0, 'Skipping file "%s"' % file_name) LOG('Business Template', 0, 'Skipping file "%s"' % file_name)
......
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