Commit 84019372 authored by Jérome Perrin's avatar Jérome Perrin Committed by Eteri

mysql_innodb_catalog: delete before inserting in predicate table

since predicate is scriptable, a document that was once a predicate may
no longer be a predicate next time it's indexed, so we should remove it
from predicate table in that case.

predicate_category was already doing this correctly
parent 66cabd5f
DELETE FROM
predicate
WHERE
<dtml-sqltest uid type="int" multiple>
<dtml-var sql_delimiter>
<dtml-let predicate_list="[]">
<dtml-in prefix="loop" expr="_.range(_.len(uid))">
<dtml-if "isPredicate[loop_item]">
......
......@@ -616,6 +616,44 @@ class TestPredicates(TestPredicateMixIn):
self.assertFalse(getattr(predicate, '_identity_criterion', None) is None)
self.assertFalse(getattr(predicate, '_range_criterion', None) is None)
def test_predicateIndexation(self):
predicate = self.createPredicate(
membership_criterion_base_category_list = ['region'],
membership_criterion_category_list = [REGION_FRANCE_PATH]
)
# Our test document will only be a predicate if title is different
# from 'never applies'
createZODBPythonScript(
self.portal.portal_skins.custom,
'Predicate_asPredicate',
'',
"""return None if context.getTitle() == 'never applies' else context""")
self.tic()
self.assertEqual(
[predicate],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate.uid': predicate.getUid()})])
self.assertEqual(
[predicate],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate_category.uid': predicate.getUid()})])
predicate.setTitle("never applies")
# this predicate is no longer a predicate, so it no longer exist in predicate tables
self.tic()
self.assertEqual(
[],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate.uid': predicate.getUid()})])
self.assertEqual(
[],
[brain.getObject() for brain in self.portal.portal_catalog(
**{'predicate_category.uid': predicate.getUid()})])
# TODO :
# multi membership category
# asPredicate scripts
......
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