[migration] schema should be accessed through .repo stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 01 Jul 2010 17:46:58 +0200
branchstable
changeset 5850 fabff2813ee4
parent 5848 b5640328ffad
child 5851 74f68d6549c0
[migration] schema should be accessed through .repo
server/checkintegrity.py
server/migractions.py
--- a/server/checkintegrity.py	Thu Jul 01 09:23:39 2010 +0200
+++ b/server/checkintegrity.py	Thu Jul 01 17:46:58 2010 +0200
@@ -88,7 +88,7 @@
     else:
         yield eschema
 
-def reindex_entities(schema, session, withpb=True):
+def reindex_entities(schema, session, withpb=True, etypes=None):
     """reindex all entities in the repository"""
     # deactivate modification_date hook since we don't want them
     # to be updated due to the reindexation
@@ -98,15 +98,16 @@
         print 'no text index table'
         repo.system_source.dbhelper.init_fti(cursor)
     repo.system_source.do_fti = True  # ensure full-text indexation is activated
-    etypes = set()
-    for eschema in schema.entities():
-        if eschema.final:
-            continue
-        indexable_attrs = tuple(eschema.indexable_attributes()) # generator
-        if not indexable_attrs:
-            continue
-        for container in etype_fti_containers(eschema):
-            etypes.add(container)
+    if etypes is None:
+        etypes = set()
+        for eschema in schema.entities():
+            if eschema.final:
+                continue
+            indexable_attrs = tuple(eschema.indexable_attributes()) # generator
+            if not indexable_attrs:
+                continue
+            for container in etype_fti_containers(eschema):
+                etypes.add(container)
     print 'Reindexing entities of type %s' % \
           ', '.join(sorted(str(e) for e in etypes))
     if withpb:
--- a/server/migractions.py	Thu Jul 01 09:23:39 2010 +0200
+++ b/server/migractions.py	Thu Jul 01 17:46:58 2010 +0200
@@ -25,9 +25,8 @@
 The following data actions are supported for now:
 * add an entity
 * execute raw RQL queries
-
+"""
 
-"""
 from __future__ import with_statement
 
 __docformat__ = "restructuredtext en"
@@ -1216,6 +1215,13 @@
             self.commit()
         return entity
 
+    def cmd_reindex_entities(self, etypes=None):
+        """force reindexaction of entities of the given types or of all
+        indexable entity types
+        """
+        from cubicweb.server.checkintegrity import reindex_entities
+        reindex_entities(self.repo.schema, self.session, etypes=etypes)
+
     @deprecated('[3.5] use create_entity', stacklevel=3)
     def cmd_add_entity(self, etype, *args, **kwargs):
         """add a new entity of the given type"""