54 from cubicweb.utils import QueryCache |
54 from cubicweb.utils import QueryCache |
55 from cubicweb.schema import VIRTUAL_RTYPES |
55 from cubicweb.schema import VIRTUAL_RTYPES |
56 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
56 from cubicweb.cwconfig import CubicWebNoAppConfiguration |
57 from cubicweb.server import hook |
57 from cubicweb.server import hook |
58 from cubicweb.server import schema2sql as y2sql |
58 from cubicweb.server import schema2sql as y2sql |
59 from cubicweb.server.utils import crypt_password, eschema_eid, verify_and_update |
59 from cubicweb.server.utils import crypt_password, verify_and_update |
60 from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn |
60 from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn |
61 from cubicweb.server.rqlannotation import set_qdata |
61 from cubicweb.server.rqlannotation import set_qdata |
62 from cubicweb.server.hook import CleanupDeletedEidsCacheOp |
62 from cubicweb.server.hook import CleanupDeletedEidsCacheOp |
63 from cubicweb.server.edition import EditedEntity |
63 from cubicweb.server.edition import EditedEntity |
64 from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results |
64 from cubicweb.server.sources import AbstractSource, dbg_st_search, dbg_results |
913 extid = b64encode(extid).decode('ascii') |
913 extid = b64encode(extid).decode('ascii') |
914 attrs = {'type': text_type(entity.cw_etype), 'eid': entity.eid, 'extid': extid, |
914 attrs = {'type': text_type(entity.cw_etype), 'eid': entity.eid, 'extid': extid, |
915 'asource': text_type(source.uri)} |
915 'asource': text_type(source.uri)} |
916 self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs) |
916 self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs) |
917 # insert core relations: is, is_instance_of and cw_source |
917 # insert core relations: is, is_instance_of and cw_source |
918 try: |
918 |
|
919 if entity.e_schema.eid is not None: # else schema has not yet been serialized |
919 self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)', |
920 self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)', |
920 (entity.eid, eschema_eid(cnx, entity.e_schema))) |
921 (entity.eid, entity.e_schema.eid)) |
921 except IndexError: |
|
922 # during schema serialization, skip |
|
923 pass |
|
924 else: |
|
925 for eschema in entity.e_schema.ancestors() + [entity.e_schema]: |
922 for eschema in entity.e_schema.ancestors() + [entity.e_schema]: |
926 self._handle_is_relation_sql(cnx, |
923 self._handle_is_relation_sql(cnx, |
927 'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)', |
924 'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)', |
928 (entity.eid, eschema_eid(cnx, eschema))) |
925 (entity.eid, eschema.eid)) |
929 if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10 |
926 if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10 |
930 self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)', |
927 self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)', |
931 (entity.eid, source.eid)) |
928 (entity.eid, source.eid)) |
932 # now we can update the full text index |
929 # now we can update the full text index |
933 if self.need_fti_indexation(entity.cw_etype): |
930 if self.need_fti_indexation(entity.cw_etype): |