970 if extid is not None: |
970 if extid is not None: |
971 assert isinstance(extid, str) |
971 assert isinstance(extid, str) |
972 extid = b64encode(extid) |
972 extid = b64encode(extid) |
973 uri = 'system' if source.copy_based_source else source.uri |
973 uri = 'system' if source.copy_based_source else source.uri |
974 attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid, |
974 attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid, |
975 'source': uri, 'asource': source.uri, 'mtime': datetime.now()} |
975 'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()} |
976 self.doexec(session, self.sqlgen.insert('entities', attrs), attrs) |
976 self.doexec(session, self.sqlgen.insert('entities', attrs), attrs) |
977 # insert core relations: is, is_instance_of and cw_source |
977 # insert core relations: is, is_instance_of and cw_source |
978 try: |
978 try: |
979 self.doexec(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)' |
979 self.doexec(session, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)' |
980 % (entity.eid, eschema_eid(session, entity.e_schema))) |
980 % (entity.eid, eschema_eid(session, entity.e_schema))) |
1000 # reindex the entity only if this query is updating at least |
1000 # reindex the entity only if this query is updating at least |
1001 # one indexable attribute |
1001 # one indexable attribute |
1002 self.index_entity(session, entity=entity) |
1002 self.index_entity(session, entity=entity) |
1003 # update entities.mtime. |
1003 # update entities.mtime. |
1004 # XXX Only if entity.__regid__ in self.multisources_etypes? |
1004 # XXX Only if entity.__regid__ in self.multisources_etypes? |
1005 attrs = {'eid': entity.eid, 'mtime': datetime.now()} |
1005 attrs = {'eid': entity.eid, 'mtime': datetime.utcnow()} |
1006 self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs) |
1006 self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs) |
1007 |
1007 |
1008 def delete_info_multi(self, session, entities, uri): |
1008 def delete_info_multi(self, session, entities, uri): |
1009 """delete system information on deletion of a list of entities with the |
1009 """delete system information on deletion of a list of entities with the |
1010 same etype and belinging to the same source |
1010 same etype and belinging to the same source |
1017 attrs = {'eid': '(%s)' % ','.join([str(_e.eid) for _e in entities])} |
1017 attrs = {'eid': '(%s)' % ','.join([str(_e.eid) for _e in entities])} |
1018 self.doexec(session, self.sqlgen.delete_many('entities', attrs), attrs) |
1018 self.doexec(session, self.sqlgen.delete_many('entities', attrs), attrs) |
1019 if entities[0].__regid__ not in self.multisources_etypes: |
1019 if entities[0].__regid__ not in self.multisources_etypes: |
1020 return |
1020 return |
1021 attrs = {'type': entities[0].__regid__, |
1021 attrs = {'type': entities[0].__regid__, |
1022 'source': uri, 'dtime': datetime.now()} |
1022 'source': uri, 'dtime': datetime.utcnow()} |
1023 for entity in entities: |
1023 for entity in entities: |
1024 extid = entity.cw_metainformation()['extid'] |
1024 extid = entity.cw_metainformation()['extid'] |
1025 if extid is not None: |
1025 if extid is not None: |
1026 assert isinstance(extid, str), type(extid) |
1026 assert isinstance(extid, str), type(extid) |
1027 extid = b64encode(extid) |
1027 extid = b64encode(extid) |
1171 def start_undoable_transaction(self, session, uuid): |
1171 def start_undoable_transaction(self, session, uuid): |
1172 """session callback to insert a transaction record in the transactions |
1172 """session callback to insert a transaction record in the transactions |
1173 table when some undoable transaction is started |
1173 table when some undoable transaction is started |
1174 """ |
1174 """ |
1175 ueid = session.user.eid |
1175 ueid = session.user.eid |
1176 attrs = {'tx_uuid': uuid, 'tx_user': ueid, 'tx_time': datetime.now()} |
1176 attrs = {'tx_uuid': uuid, 'tx_user': ueid, 'tx_time': datetime.utcnow()} |
1177 self.doexec(session, self.sqlgen.insert('transactions', attrs), attrs) |
1177 self.doexec(session, self.sqlgen.insert('transactions', attrs), attrs) |
1178 |
1178 |
1179 def _save_attrs(self, session, entity, attrs): |
1179 def _save_attrs(self, session, entity, attrs): |
1180 """return a pickleable dictionary containing current values for given |
1180 """return a pickleable dictionary containing current values for given |
1181 attributes of the entity |
1181 attributes of the entity |