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) |