backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 08 Mar 2010 09:51:29 +0100
changeset 4829 3b79a0fc91db
parent 4823 e833520870ee (current diff)
parent 4828 3e173d598cad (diff)
child 4830 10e8bc190695
child 4831 c5aec27c1bf7
backport stable
hooks/syncschema.py
hooks/test/unittest_syncschema.py
server/sources/native.py
--- a/hooks/syncschema.py	Fri Mar 05 18:20:39 2010 +0100
+++ b/hooks/syncschema.py	Mon Mar 08 09:51:29 2010 +0100
@@ -227,15 +227,22 @@
 
 class SourceDbCWRTypeUpdate(hook.Operation):
     """actually update some properties of a relation definition"""
-    rschema = values = entity = None # make pylint happy
+    rschema = entity = None # make pylint happy
 
     def precommit_event(self):
         session = self.session
         rschema = self.rschema
-        if rschema.final or not 'inlined' in self.values:
+        entity = self.entity
+        if 'fulltext_container' in entity.edited_attributes:
+            ftiupdates = session.transaction_data.setdefault(
+                'fti_update_etypes', set())
+            for subjtype, objtype in rschema.rdefs:
+                ftiupdates.add(subjtype)
+                ftiupdates.add(objtype)
+            UpdateFTIndexOp(session)
+        if rschema.final or not 'inlined' in entity.edited_attributes:
             return # nothing to do
-        inlined = self.values['inlined']
-        entity = self.entity
+        inlined = entity.inlined
         # check in-lining is necessary / possible
         if not entity.inlined_changed(inlined):
             return # nothing to do
@@ -497,12 +504,6 @@
             UpdateFTIndexOp(session)
             session.transaction_data.setdefault(
                 'fti_update_etypes', set()).add(etype)
-        elif 'fulltext_container' in self.values:
-            ftiupdates = session.transaction_data.setdefault(
-                'fti_update_etypes', set())
-            ftiupdates.add(etype)
-            ftiupdates.add(self.kobj[1])
-            UpdateFTIndexOp(session)
 
 
 class SourceDbCWConstraintAdd(hook.Operation):
@@ -946,15 +947,14 @@
 
     def __call__(self):
         entity = self.entity
-        rschema = self._cw.vreg.schema.rschema(entity.name)
         newvalues = {}
-        for prop in ('meta', 'symmetric', 'inlined'):
-            if prop in entity:
+        for prop in ('symmetric', 'inlined', 'fulltext_container'):
+            if prop in entity.edited_attributes:
                 newvalues[prop] = entity[prop]
         if newvalues:
+            rschema = self._cw.vreg.schema.rschema(entity.name)
+            SourceDbCWRTypeUpdate(self._cw, rschema=rschema, entity=entity)
             MemSchemaCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues)
-            SourceDbCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues,
-                                  entity=entity)
 
 
 class AfterDelRelationTypeHook(SyncSchemaHook):
@@ -1164,15 +1164,11 @@
                       len(rset), etype)
             still_fti = list(schema[etype].indexable_attributes())
             for entity in rset.entities():
-                try:
-                    source.fti_unindex_entity(session, entity.eid)
-                    for container in entity.fti_containers():
-                        if still_fti or container is not entity:
-                            source.fti_unindex_entity(session, entity.eid)
-                            source.fti_index_entity(session, container)
-                except Exception:
-                    self.critical('Error while updating Full Text Index for'
-                                  ' entity %s', entity.eid, exc_info=True)
+                source.fti_unindex_entity(session, entity.eid)
+                for container in entity.fti_containers():
+                    if still_fti or container is not entity:
+                        source.fti_unindex_entity(session, entity.eid)
+                        source.fti_index_entity(session, container)
         if len(to_reindex):
             # Transaction have already been committed
             session.pool.commit()
--- a/hooks/test/unittest_syncschema.py	Fri Mar 05 18:20:39 2010 +0100
+++ b/hooks/test/unittest_syncschema.py	Mon Mar 08 09:51:29 2010 +0100
@@ -256,20 +256,40 @@
         self.execute('Any X WHERE X is_instance_of BaseTransition, X messageid "hop"')
 
     def test_change_fulltextindexed(self):
-        target = self.request().create_entity(u'EmailAddress', address=u'rick.roll@dance.com')
+        req = self.request()
+        target = req.create_entity(u'Email', messageid=u'1234',
+                                   subject=u'rick.roll@dance.com')
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(target.eid, [item[0] for item in rset])
+        assert req.execute('SET A fulltextindexed FALSE '
+                            'WHERE E is CWEType, E name "Email", A is CWAttribute,'
+                            'A from_entity E, A relation_type R, R name "subject"')
+        self.commit()
+        rset = req.execute('Any X Where X has_text "rick.roll"')
+        self.failIf(rset)
+        assert req.execute('SET A fulltextindexed TRUE '
+                           'WHERE A from_entity E, A relation_type R, '
+                           'E name "Email", R name "subject"')
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(target.eid, [item[0] for item in rset])
+
+    def test_change_fulltext_container(self):
+        req = self.request()
+        target = req.create_entity(u'EmailAddress', address=u'rick.roll@dance.com')
+        target.set_relations(reverse_use_email=req.user)
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(req.user.eid, [item[0] for item in rset])
+        assert self.execute('SET R fulltext_container NULL '
+                            'WHERE R name "use_email"')
         self.commit()
         rset = self.execute('Any X Where X has_text "rick.roll"')
         self.assertIn(target.eid, [item[0] for item in rset])
+        assert self.execute('SET R fulltext_container "subject" '
+                            'WHERE R name "use_email"')
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(req.user.eid, [item[0] for item in rset])
 
-        assert self.execute('''SET A fulltextindexed False
-                        WHERE E is CWEType,
-                              E name "EmailAddress",
-                              A is CWAttribute,
-                              A from_entity E,
-                              A relation_type R,
-                              R name "address"
-                    ''')
-        self.commit()
-        rset = self.execute('Any X Where X has_text "rick.roll"')
-        self.assertNotIn(target.eid, [item[0] for item in rset])
-
--- a/web/test/unittest_views_basecontrollers.py	Fri Mar 05 18:20:39 2010 +0100
+++ b/web/test/unittest_views_basecontrollers.py	Mon Mar 08 09:51:29 2010 +0100
@@ -489,7 +489,7 @@
         # fail if the controller API changes and if EmbedController is not
         # updated (which is what happened before this test)
         req = self.request()
-        req.form['url'] = 'http://intranet.logilab.fr/'
+        req.form['url'] = 'http://www.logilab.fr/'
         controller = self.vreg['controllers'].select('embed', req)
         result = controller.publish(rset=None)