Commit 6bcccf94 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Only edit if the document isMemberOf

   Factorize script to make easier projects slow roll migration or use activities in case the object removed contains way too many related objects.
parent a6e65f17
...@@ -52,21 +52,8 @@ for category in category_to_migrate_list: ...@@ -52,21 +52,8 @@ for category in category_to_migrate_list:
new_category = new_category_list[0] new_category = new_category_list[0]
# Can we make it cheaper # XXX It could be relavant to use activities here
related_document_list = category.Base_getRelatedObjectList(**{ category.Category_updateRelatedRegionAndExpire(new_category)
'portal_type': NegatedQuery(SimpleQuery(portal_type='Category')),
'category.category_strict_membership': 1})
for document in related_document_list:
# does it actually has the category?
document.edit(region=new_category)
document.reindexObject()
# 1) Search for the all related objects
# 2) Migrate all related objects
# 3) reindex everything
# 4) Expire the category
category.expire()
message_list.append( message_list.append(
"%s migrated and expired (int_index: %s, validation_state: %s)" % ( "%s migrated and expired (int_index: %s, validation_state: %s)" % (
category.getRelativeUrl(), category.getIntIndex(), category.getValidationState()) category.getRelativeUrl(), category.getIntIndex(), category.getValidationState())
......
from zExceptions import Unauthorized
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, NegatedQuery
if REQUEST is not None:
raise Unauthorized
assert context.getPortalType() == "Category"
assert context.getIntIndex() < 0
assert context.getRelativeUrl().startswith("portal_categories/region/"), \
"The context (%s) is not a region"
if context.getValidationState() == 'expired':
# skip, we seems to be rerunning the migration
# and some reindexation is going on.
return []
related_document_list = context.Base_getRelatedObjectList(**{
'portal_type': NegatedQuery(SimpleQuery(portal_type='Category')),
'category.category_strict_membership': 1})
for document in related_document_list:
# XXX Can we do better them use replace?
if document.isMemberOf(context.getRelativeUrl().replace("portal_categories/", "")):
document.edit(
region=new_category.getRelativeUrl(),
activate_kw={'tag': 'edit_%s' % (context.getRelativeUrl())})
else:
# Trigger reindex since the the member was edited
# use tag to ensure it happens after the edit is reindexed.
document.reindexObject(
activate_kw={'after_tag': 'edit_%s' % (context.getRelativeUrl())})
context.expire()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>new_category, REQUEST=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Category_updateRelatedRegionAndExpire</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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