18 """Core hooks: set generic metadata""" |
18 """Core hooks: set generic metadata""" |
19 |
19 |
20 __docformat__ = "restructuredtext en" |
20 __docformat__ = "restructuredtext en" |
21 |
21 |
22 from datetime import datetime |
22 from datetime import datetime |
|
23 from base64 import b64encode |
23 |
24 |
24 from cubicweb.predicates import is_instance |
25 from cubicweb.predicates import is_instance |
25 from cubicweb.server import hook |
26 from cubicweb.server import hook |
26 from cubicweb.server.edition import EditedEntity |
27 from cubicweb.server.edition import EditedEntity |
27 |
28 |
201 # we don't want the moved entity to be reimported later. To |
202 # we don't want the moved entity to be reimported later. To |
202 # distinguish this state, move the record from the 'entities' table |
203 # distinguish this state, move the record from the 'entities' table |
203 # to 'moved_entities'. External source will then have consider |
204 # to 'moved_entities'. External source will then have consider |
204 # case where `extid2eid` returns a negative eid as 'this entity was |
205 # case where `extid2eid` returns a negative eid as 'this entity was |
205 # known but has been moved, ignore it'. |
206 # known but has been moved, ignore it'. |
206 attrs = {'eid': entity.eid, 'extid': self._cw.entity_metas(entity.eid)['extid']} |
207 extid = self._cw.entity_metas(entity.eid)['extid'] |
|
208 assert extid is not None |
|
209 attrs = {'eid': entity.eid, 'extid': b64encode(extid).decode('ascii')} |
207 self._cw.system_sql(syssource.sqlgen.insert('moved_entities', attrs), attrs) |
210 self._cw.system_sql(syssource.sqlgen.insert('moved_entities', attrs), attrs) |
208 attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None, |
211 attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None, |
209 'asource': 'system'} |
212 'asource': 'system'} |
210 self._cw.system_sql(syssource.sqlgen.update('entities', attrs, ['eid']), attrs) |
213 self._cw.system_sql(syssource.sqlgen.update('entities', attrs, ['eid']), attrs) |
211 # register an operation to update repository/sources caches |
214 # register an operation to update repository/sources caches |