cubicweb/server/repository.py
branch3.25
changeset 12135 e814ba7e51dc
parent 12130 4d874c2fbb5f
child 12142 db2fc87348ab
equal deleted inserted replaced
12134:0bf232be21a6 12135:e814ba7e51dc
   292         if config.creating:
   292         if config.creating:
   293             # call init_creating so that for instance native source can
   293             # call init_creating so that for instance native source can
   294             # configurate tsearch according to postgres version
   294             # configurate tsearch according to postgres version
   295             self.system_source.init_creating()
   295             self.system_source.init_creating()
   296         else:
   296         else:
       
   297             self._init_system_source()
   297             self.init_sources_from_database()
   298             self.init_sources_from_database()
   298             if 'CWProperty' in self.schema:
   299             if 'CWProperty' in self.schema:
   299                 self.vreg.init_properties(self.properties())
   300                 self.vreg.init_properties(self.properties())
   300         # 4. close initialization connection set and reopen fresh ones for
   301         # 4. close initialization connection set and reopen fresh ones for
   301         #    proper initialization
   302         #    proper initialization
   304         # 5. call instance level initialisation hooks
   305         # 5. call instance level initialisation hooks
   305         self.hm.call_hooks('server_startup', repo=self)
   306         self.hm.call_hooks('server_startup', repo=self)
   306 
   307 
   307     # internals ###############################################################
   308     # internals ###############################################################
   308 
   309 
       
   310     def _init_system_source(self):
       
   311         if self.config.quick_start:
       
   312             self.system_source.init_creating()
       
   313             return
       
   314         with self.internal_cnx() as cnx:
       
   315             sourceent = cnx.execute(
       
   316                 'Any S, SA, SC WHERE S is_instance_of CWSource,'
       
   317                 ' S name "system", S type SA, S config SC'
       
   318             ).one()
       
   319             self.system_source.eid = sourceent.eid
       
   320             self.sources_by_eid[sourceent.eid] = self.system_source
       
   321             self.system_source.init(True, sourceent)
       
   322 
   309     def init_sources_from_database(self):
   323     def init_sources_from_database(self):
   310         if self.config.quick_start:
   324         if self.config.quick_start:
   311             self.system_source.init_creating()
       
   312             return
   325             return
   313         with self.internal_cnx() as cnx:
   326         with self.internal_cnx() as cnx:
   314             # FIXME: sources should be ordered (add_entity priority)
   327             # FIXME: sources should be ordered (add_entity priority)
   315             for sourceent in cnx.execute(
   328             for sourceent in cnx.execute(
   316                     'Any S, SN, SA, SC WHERE S is_instance_of CWSource, '
   329                     'Any S, SN, SA, SC WHERE S is_instance_of CWSource, '
   317                     'S name SN, S type SA, S config SC').entities():
   330                     'S name SN, S type SA, S config SC, S name != "system"').entities():
   318                 if sourceent.name == 'system':
       
   319                     self.system_source.eid = sourceent.eid
       
   320                     self.sources_by_eid[sourceent.eid] = self.system_source
       
   321                     self.system_source.init(True, sourceent)
       
   322                     continue
       
   323                 self.add_source(sourceent)
   331                 self.add_source(sourceent)
   324 
   332 
   325     def add_source(self, sourceent):
   333     def add_source(self, sourceent):
   326         try:
   334         try:
   327             source = self.get_source(sourceent.type, sourceent.name,
   335             source = self.get_source(sourceent.type, sourceent.name,