cubicweb/hooks/metadata.py
changeset 11763 39df042f4ab4
parent 11757 e845746b4d3c
child 11767 432f87a63057
equal deleted inserted replaced
11762:7518cb58ab4c 11763:39df042f4ab4
   155 
   155 
   156 
   156 
   157 # entity source handling #######################################################
   157 # entity source handling #######################################################
   158 
   158 
   159 class ChangeEntitySourceUpdateCaches(hook.Operation):
   159 class ChangeEntitySourceUpdateCaches(hook.Operation):
   160     oldsource = newsource = entity = None # make pylint happy
   160     oldsource = entity = None # make pylint happy
   161 
   161 
   162     def postcommit_event(self):
   162     def postcommit_event(self):
   163         self.oldsource.reset_caches()
   163         self.oldsource.reset_caches()
   164         repo = self.cnx.repo
   164         repo = self.cnx.repo
   165         entity = self.entity
   165         entity = self.entity
   166         extid = entity.cw_metainformation()['extid']
   166         repo._type_extid_cache[entity.eid] = (entity.cw_etype, None)
   167         repo._type_source_cache[entity.eid] = (
       
   168             entity.cw_etype, None, self.newsource.uri)
       
   169 
   167 
   170 
   168 
   171 class ChangeEntitySourceDeleteHook(MetaDataHook):
   169 class ChangeEntitySourceDeleteHook(MetaDataHook):
   172     """support for moving an entity from an external source by watching 'Any
   170     """support for moving an entity from an external source by watching 'Any
   173     cw_source CWSource' relation
   171     cw_source CWSource' relation
   203             attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None,
   201             attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None,
   204                      'asource': 'system'}
   202                      'asource': 'system'}
   205             self._cw.system_sql(syssource.sqlgen.update('entities', attrs, ['eid']), attrs)
   203             self._cw.system_sql(syssource.sqlgen.update('entities', attrs, ['eid']), attrs)
   206             # register an operation to update repository/sources caches
   204             # register an operation to update repository/sources caches
   207             ChangeEntitySourceUpdateCaches(self._cw, entity=entity,
   205             ChangeEntitySourceUpdateCaches(self._cw, entity=entity,
   208                                            oldsource=oldsource.repo_source,
   206                                            oldsource=oldsource.repo_source)
   209                                            newsource=syssource)