server/sources/native.py
changeset 7514 32081892850e
parent 7398 26695dd703d8
parent 7507 4c043afb104a
child 7536 29961a416faa
equal deleted inserted replaced
7497:7beb71d76d82 7514:32081892850e
   968         # update entities.mtime.
   968         # update entities.mtime.
   969         # XXX Only if entity.__regid__ in self.multisources_etypes?
   969         # XXX Only if entity.__regid__ in self.multisources_etypes?
   970         attrs = {'eid': entity.eid, 'mtime': datetime.now()}
   970         attrs = {'eid': entity.eid, 'mtime': datetime.now()}
   971         self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs)
   971         self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs)
   972 
   972 
   973     def delete_info(self, session, entity, uri, extid):
   973     def delete_info_multi(self, session, entities, uri):
   974         """delete system information on deletion of an entity:
   974         """delete system information on deletion of a list of entities with the
       
   975         same etype and belinging to the same source
       
   976 
   975         * update the fti
   977         * update the fti
   976         * remove record from the entities table
   978         * remove record from the `entities` table
   977         * transfer it to the deleted_entities table if the entity's type is
   979         * transfer it to the `deleted_entities`
   978           multi-sources
       
   979         """
       
   980         self.fti_unindex_entities(session, [entity])
       
   981         attrs = {'eid': entity.eid}
       
   982         self.doexec(session, self.sqlgen.delete('entities', attrs), attrs)
       
   983         if not entity.__regid__ in self.multisources_etypes:
       
   984             return
       
   985         if extid is not None:
       
   986             assert isinstance(extid, str), type(extid)
       
   987             extid = b64encode(extid)
       
   988         attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid,
       
   989                  'source': uri, 'dtime': datetime.now()}
       
   990         self.doexec(session, self.sqlgen.insert('deleted_entities', attrs), attrs)
       
   991 
       
   992     def delete_info_multi(self, session, entities, uri, extids):
       
   993         """delete system information on deletion of an entity:
       
   994         * update the fti
       
   995         * remove record from the entities table
       
   996         * transfer it to the deleted_entities table if the entity's type is
       
   997           multi-sources
       
   998         """
   980         """
   999         self.fti_unindex_entities(session, entities)
   981         self.fti_unindex_entities(session, entities)
  1000         attrs = {'eid': '(%s)' % ','.join([str(_e.eid) for _e in entities])}
   982         attrs = {'eid': '(%s)' % ','.join([str(_e.eid) for _e in entities])}
  1001         self.doexec(session, self.sqlgen.delete_many('entities', attrs), attrs)
   983         self.doexec(session, self.sqlgen.delete_many('entities', attrs), attrs)
  1002         if entities[0].__regid__ not in self.multisources_etypes:
   984         if entities[0].__regid__ not in self.multisources_etypes:
  1003             return
   985             return
  1004         attrs = {'type': entities[0].__regid__,
   986         attrs = {'type': entities[0].__regid__,
  1005                  'source': uri, 'dtime': datetime.now()}
   987                  'source': uri, 'dtime': datetime.now()}
  1006         for entity, extid in itertools.izip(entities, extids):
   988         for entity in entities:
       
   989             extid = entity.cw_metainformation()['extid']
  1007             if extid is not None:
   990             if extid is not None:
  1008                 assert isinstance(extid, str), type(extid)
   991                 assert isinstance(extid, str), type(extid)
  1009                 extid = b64encode(extid)
   992                 extid = b64encode(extid)
  1010             attrs.update({'eid': entity.eid, 'extid': extid})
   993             attrs.update({'eid': entity.eid, 'extid': extid})
  1011             self.doexec(session, self.sqlgen.insert('deleted_entities', attrs), attrs)
   994             self.doexec(session, self.sqlgen.insert('deleted_entities', attrs), attrs)
  1318         # delete the entity
  1301         # delete the entity
  1319         attrs = {'cw_eid': eid}
  1302         attrs = {'cw_eid': eid}
  1320         sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
  1303         sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
  1321         self.doexec(session, sql, attrs)
  1304         self.doexec(session, sql, attrs)
  1322         # remove record from entities (will update fti if needed)
  1305         # remove record from entities (will update fti if needed)
  1323         self.delete_info(session, entity, self.uri, None)
  1306         self.delete_info_multi(session, [entity], self.uri)
  1324         self.repo.hm.call_hooks('after_delete_entity', session, entity=entity)
  1307         self.repo.hm.call_hooks('after_delete_entity', session, entity=entity)
  1325         return ()
  1308         return ()
  1326 
  1309 
  1327     def _undo_u(self, session, action):
  1310     def _undo_u(self, session, action):
  1328         """undo an entity update"""
  1311         """undo an entity update"""