Commit b2207762 authored by Arnaud Fontaine's avatar Arnaud Fontaine Committed by Alain Takoudjou

ZODB Components: Fix bootstrap issue.

When a Property Sheet with a ScriptConstraint (whose Document is a ZODB
Component) was added to Memcached Tool: Document Component was partially
loaded with no Property Sheet yet (and thus without the accessors needed
to import ScriptConstraint ZODB Component module) and ScriptConstraint
Document was considered not available.
parent a04b1932
...@@ -114,20 +114,15 @@ class ComponentDynamicPackage(ModuleType): ...@@ -114,20 +114,15 @@ class ComponentDynamicPackage(ModuleType):
# Only consider modified or validated states as state transition will # Only consider modified or validated states as state transition will
# be handled by component_validation_workflow which will take care of # be handled by component_validation_workflow which will take care of
# updating the registry # updating the registry
try: validation_state_tuple = component.getValidationState()
validation_state_tuple = component.getValidationState() if validation_state_tuple in ('modified', 'validated'):
except AttributeError: version = component.getVersion(validated_only=True)
# XXX: Accessors may have not been generated yet # The versions should have always been set on ERP5Site property
pass # beforehand
else: if version in version_priority_set:
if validation_state_tuple in ('modified', 'validated'): reference = component.getReference(validated_only=True)
version = component.getVersion(validated_only=True) self.__registry_dict[reference][version] = (component.getId(),
# The versions should have always been set on ERP5Site property component._p_oid)
# beforehand
if version in version_priority_set:
reference = component.getReference(validated_only=True)
self.__registry_dict[reference][version] = (component.getId(),
component._p_oid)
return self.__registry_dict return self.__registry_dict
......
...@@ -37,6 +37,7 @@ from Products.ERP5.mixin.property_recordable import PropertyRecordableMixin ...@@ -37,6 +37,7 @@ from Products.ERP5.mixin.property_recordable import PropertyRecordableMixin
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
from Products.ERP5Type.Accessor import Base as BaseAccessor
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
from zExceptions import Forbidden from zExceptions import Forbidden
...@@ -78,7 +79,7 @@ class RecordablePropertyMetaClass(ExtensionClass): ...@@ -78,7 +79,7 @@ class RecordablePropertyMetaClass(ExtensionClass):
setter.__name__ = accessor_name setter.__name__ = accessor_name
return setter return setter
def getterWrapper(accessor_name, property_name): def getterWrapper(accessor_name, property_name, property_getter):
dictionary['security'].declareProtected(Permissions.AccessContentsInformation, dictionary['security'].declareProtected(Permissions.AccessContentsInformation,
accessor_name) accessor_name)
...@@ -97,17 +98,19 @@ class RecordablePropertyMetaClass(ExtensionClass): ...@@ -97,17 +98,19 @@ class RecordablePropertyMetaClass(ExtensionClass):
except (AttributeError, KeyError): except (AttributeError, KeyError):
pass pass
return getattr(super(ComponentMixin, self), accessor_name)() return property_getter(self)
getter.__name__ = accessor_name getter.__name__ = accessor_name
return getter return getter
for property_name in dictionary['_recorded_property_name_tuple']: for (property_name,
property_getter) in dictionary['_recorded_property_name_getter_dict'].iteritems():
setter_name = '_set' + convertToUpperCase(property_name) setter_name = '_set' + convertToUpperCase(property_name)
dictionary[setter_name] = setterWrapper(setter_name, property_name) dictionary[setter_name] = setterWrapper(setter_name, property_name)
getter_name = 'get' + convertToUpperCase(property_name) getter_name = 'get' + convertToUpperCase(property_name)
dictionary[getter_name] = getterWrapper(getter_name, property_name) dictionary[getter_name] = getterWrapper(getter_name, property_name,
property_getter)
# docstring required for publishing any object # docstring required for publishing any object
dictionary['__doc__'] = metacls.__doc__ dictionary['__doc__'] = metacls.__doc__
...@@ -159,10 +162,23 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -159,10 +162,23 @@ class ComponentMixin(PropertyRecordableMixin, Base):
'TextDocument', 'TextDocument',
'Component') 'Component')
_recorded_property_name_tuple = ( _recorded_property_name_getter_dict = {
'reference', 'reference': BaseAccessor.Getter('getReference',
'version', 'reference',
'text_content') 'string',
storage_id='default_reference'),
'version': BaseAccessor.Getter('getVersion',
'version',
'string',
default=''),
'text_content': BaseAccessor.Getter('getTextContent',
'text_content',
'string'),
'description': BaseAccessor.Getter('getDescription',
'description',
'string',
default='')
}
_message_reference_not_set = "Reference must be set" _message_reference_not_set = "Reference must be set"
_message_invalid_reference = "Reference cannot end with '_version' or "\ _message_invalid_reference = "Reference cannot end with '_version' or "\
...@@ -176,6 +192,15 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -176,6 +192,15 @@ class ComponentMixin(PropertyRecordableMixin, Base):
_message_text_content_not_set = "No source code" _message_text_content_not_set = "No source code"
_message_text_content_error = "Error in Source Code: ${error_message}" _message_text_content_error = "Error in Source Code: ${error_message}"
security.declareProtected(Permissions.AccessContentsInformation,
'getValidationState')
def getValidationState(self):
"""
Needed for bootstrap when the WorkflowState Accessor is not defined yet
"""
return self.workflow_history[
'component_validation_workflow'][-1]['validation_state']
security.declareProtected(Permissions.ModifyPortalContent, 'checkConsistency') security.declareProtected(Permissions.ModifyPortalContent, 'checkConsistency')
def checkConsistency(self, *args, **kw): def checkConsistency(self, *args, **kw):
""" """
...@@ -270,7 +295,7 @@ class ComponentMixin(PropertyRecordableMixin, Base): ...@@ -270,7 +295,7 @@ class ComponentMixin(PropertyRecordableMixin, Base):
reference, version and text_content reference, version and text_content
""" """
if not self.checkConsistency(): if not self.checkConsistency():
for property_name in self._recorded_property_name_tuple: for property_name in self._recorded_property_name_getter_dict:
self.clearRecordedProperty(property_name) self.clearRecordedProperty(property_name)
self.validate() self.validate()
......
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