Commit 4effc280 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* extend checkConsistency and fixConsistency API to accept 'filter' argument,...

* extend checkConsistency and fixConsistency API to accept 'filter' argument, that supports 'id' only for now.
* use boolean instead of 0/1 for fixit argument.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34873 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 86317b95
......@@ -2695,7 +2695,7 @@ class Base( CopyContainer,
# return self._recursiveApply(f)
# Content consistency implementation
def _checkConsistency(self, fixit=0):
def _checkConsistency(self, fixit=False):
"""
Check the constitency of objects.
......@@ -2709,10 +2709,10 @@ class Base( CopyContainer,
Private method.
"""
return self._checkConsistency(fixit=1)
return self._checkConsistency(fixit=True)
security.declareProtected(Permissions.AccessContentsInformation, 'checkConsistency')
def checkConsistency(self, fixit=0):
def checkConsistency(self, fixit=False, filter=None, **kw):
"""
Check the constitency of objects.
......@@ -2739,19 +2739,19 @@ class Base( CopyContainer,
# We are looking inside all instances in constraints, then we check
# the consistency for all of them
for constraint_instance in self.constraints:
for constraint_instance in self._filteredConstraintList(filter):
if fixit:
error_list2 = UnrestrictedMethod(
constraint_instance.fixConsistency)(self)
constraint_instance.fixConsistency)(self, **kw)
else:
error_list2 = UnrestrictedMethod(
constraint_instance.checkConsistency)(self)
constraint_instance.checkConsistency)(self, **kw)
if len(error_list2) > 0:
try:
if fixit:
constraint_instance.fixConsistency(self)
constraint_instance.fixConsistency(self, **kw)
else:
constraint_instance.checkConsistency(self)
constraint_instance.checkConsistency(self, **kw)
except Unauthorized:
error_list.append(getUnauthorizedErrorMessage(constraint_instance))
else:
......@@ -2763,11 +2763,24 @@ class Base( CopyContainer,
return error_list
security.declareProtected(Permissions.ManagePortal, 'fixConsistency')
def fixConsistency(self):
def fixConsistency(self, filter=None, **kw):
"""
Fix the constitency of objects.
"""
return self.checkConsistency(fixit=1)
return self.checkConsistency(fixit=True, filter=filter, **kw)
def _filteredConstraintList(self, filt):
"""
Returns a list of constraints filtered by filt argument.
"""
# currently only 'id' is supported.
constraints = self.constraints
if filt is not None:
id_list = filt.get('id', None)
if isinstance(id_list, (list, tuple)):
id_list = [id_list]
constraints = filter(lambda x:x.id in id_list, constraints)
return constraints
# Context related methods
security.declarePublic('asContext')
......
......@@ -1257,7 +1257,7 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
def checkConsistency(self, fixit=0):
def checkConsistency(self, fixit=False, filter=None, **kw):
"""
Check the consistency of this object, then
check recursively the consistency of every sub object.
......@@ -1272,7 +1272,7 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
error_list += [(self.getRelativeUrl(), 'BTree Inconsistency',
199, '(fixed)')]
# Call superclass
error_list += Base.checkConsistency(self, fixit=fixit)
error_list += Base.checkConsistency(self, fixit=fixit, filter=filter, **kw)
# We must commit before listing folder contents
# in case we erased some data
if fixit:
......@@ -1280,9 +1280,9 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
# Then check the consistency on all sub objects
for obj in self.contentValues():
if fixit:
extra_errors = obj.fixConsistency()
extra_errors = obj.fixConsistency(filter=filter, **kw)
else:
extra_errors = obj.checkConsistency()
extra_errors = obj.checkConsistency(filter=filter, **kw)
if len(extra_errors) > 0:
error_list += extra_errors
# We should also return an error if any
......
......@@ -84,12 +84,17 @@ class IConstraint(Interface):
recursivly.
"""
def checkConsistency(obj, fixit=0):
def checkConsistency(obj, fixit=False, filter=None, **kw):
"""This method checks the consistency of object 'obj', and fix errors if
the argument 'fixit' is true. Not all constraint have to support error
repairing, in that case, simply ignore the fixit parameter. This method
should return a list of errors, which are a list of `ConsistencyMessage`,
with a `getTranslatedMessage` method for user interaction.
If filter is specified, only constraints filtered by the filter
argument are checked.
Additional argument **kw is passed to each constraint.
"""
_message_id_list = Attribute("The list of messages IDs that can be "
......
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