483 changes=self._binary(dumps(changes))) |
483 changes=self._binary(dumps(changes))) |
484 attrs = {'cw_eid': entity.eid} |
484 attrs = {'cw_eid': entity.eid} |
485 sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs) |
485 sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs) |
486 self.doexec(session, sql, attrs) |
486 self.doexec(session, sql, attrs) |
487 |
487 |
|
488 def add_relation(self, session, subject, rtype, object, inlined=False): |
|
489 """add a relation to the source""" |
|
490 self._add_relation(session, subject, rtype, object, inlined) |
|
491 if session.undoable_action('A', rtype): |
|
492 self._record_tx_action(session, 'tx_relation_actions', 'A', |
|
493 eid_from=subject, rtype=rtype, eid_to=object) |
|
494 |
488 def _add_relation(self, session, subject, rtype, object, inlined=False): |
495 def _add_relation(self, session, subject, rtype, object, inlined=False): |
489 """add a relation to the source""" |
496 """add a relation to the source""" |
490 if inlined is False: |
497 if inlined is False: |
491 attrs = {'eid_from': subject, 'eid_to': object} |
498 attrs = {'eid_from': subject, 'eid_to': object} |
492 sql = self.sqlgen.insert('%s_relation' % rtype, attrs) |
499 sql = self.sqlgen.insert('%s_relation' % rtype, attrs) |
494 etype = session.describe(subject)[0] |
501 etype = session.describe(subject)[0] |
495 attrs = {'cw_eid': subject, SQL_PREFIX + rtype: object} |
502 attrs = {'cw_eid': subject, SQL_PREFIX + rtype: object} |
496 sql = self.sqlgen.update(SQL_PREFIX + etype, attrs, |
503 sql = self.sqlgen.update(SQL_PREFIX + etype, attrs, |
497 ['cw_eid']) |
504 ['cw_eid']) |
498 self.doexec(session, sql, attrs) |
505 self.doexec(session, sql, attrs) |
499 |
|
500 def add_relation(self, session, subject, rtype, object, inlined=False): |
|
501 """add a relation to the source""" |
|
502 self._add_relation(session, subject, rtype, object, inlined) |
|
503 if session.undoable_action('A', rtype): |
|
504 self._record_tx_action(session, 'tx_relation_actions', 'A', |
|
505 eid_from=subject, rtype=rtype, eid_to=object) |
|
506 |
506 |
507 def delete_relation(self, session, subject, rtype, object): |
507 def delete_relation(self, session, subject, rtype, object): |
508 """delete a relation from the source""" |
508 """delete a relation from the source""" |
509 rschema = self.schema.rschema(rtype) |
509 rschema = self.schema.rschema(rtype) |
510 if rschema.inlined: |
510 if rschema.inlined: |
696 deleted since the given timestamp |
696 deleted since the given timestamp |
697 """ |
697 """ |
698 for etype in etypes: |
698 for etype in etypes: |
699 if not etype in self.multisources_etypes: |
699 if not etype in self.multisources_etypes: |
700 self.critical('%s not listed as a multi-sources entity types. ' |
700 self.critical('%s not listed as a multi-sources entity types. ' |
701 'Modify your configuration') |
701 'Modify your configuration' % etype) |
702 self.multisources_etypes.add(etype) |
702 self.multisources_etypes.add(etype) |
703 modsql = _modified_sql('entities', etypes) |
703 modsql = _modified_sql('entities', etypes) |
704 cursor = self.doexec(session, modsql, {'time': mtime}) |
704 cursor = self.doexec(session, modsql, {'time': mtime}) |
705 modentities = cursor.fetchall() |
705 modentities = cursor.fetchall() |
706 delsql = _modified_sql('deleted_entities', etypes) |
706 delsql = _modified_sql('deleted_entities', etypes) |
790 """See :class:`cubicweb.dbapi.Connection.transaction_actions`""" |
790 """See :class:`cubicweb.dbapi.Connection.transaction_actions`""" |
791 self._tx_info(session, txuuid) |
791 self._tx_info(session, txuuid) |
792 restr = {'tx_uuid': txuuid} |
792 restr = {'tx_uuid': txuuid} |
793 if public: |
793 if public: |
794 restr['txa_public'] = True |
794 restr['txa_public'] = True |
|
795 # XXX use generator to avoid loading everything in memory? |
795 sql = self.sqlgen.select('tx_entity_actions', restr, |
796 sql = self.sqlgen.select('tx_entity_actions', restr, |
796 ('txa_action', 'txa_public', 'txa_order', |
797 ('txa_action', 'txa_public', 'txa_order', |
797 'etype', 'eid', 'changes')) |
798 'etype', 'eid', 'changes')) |
798 cu = self.doexec(session, sql, restr) |
799 cu = self.doexec(session, sql, restr) |
799 actions = [tx.EntityAction(a,p,o,et,e,c and loads(self.binary_to_str(c))) |
800 actions = [tx.EntityAction(a,p,o,et,e,c and loads(self.binary_to_str(c))) |
909 err(_("Can't restore relation %(rtype)s of entity %(eid)s, " |
910 err(_("Can't restore relation %(rtype)s of entity %(eid)s, " |
910 "this relation does not exists anymore in the schema.") |
911 "this relation does not exists anymore in the schema.") |
911 % {'rtype': rtype, 'eid': eid}) |
912 % {'rtype': rtype, 'eid': eid}) |
912 if not rschema.final: |
913 if not rschema.final: |
913 assert value is None |
914 assert value is None |
914 # try: |
|
915 # tentity = session.entity_from_eid(eid) |
|
916 # except UnknownEid: |
|
917 # err(_("Can't restore %(role)s relation %(rtype)s to " |
|
918 # "entity %(eid)s which doesn't exist anymore.") |
|
919 # % {'role': _('subject'), |
|
920 # 'rtype': _(rtype), |
|
921 # 'eid': eid}) |
|
922 # continue |
|
923 # rdef = rdefs[(eschema, tentity.__regid__)] |
|
924 # try: |
|
925 # _undo_check_relation_target(tentity, rdef, 'object') |
|
926 # except UndoException, ex: |
|
927 # err(unicode(ex)) |
|
928 # continue |
|
929 # if rschema.inlined: |
|
930 # entity[rtype] = value |
|
931 # else: |
|
932 # # restore relation where inlined changed since the deletion |
|
933 # del action.changes[column] |
|
934 # self._add_relation(session, subject, rtype, object) |
|
935 # # set related cache |
|
936 # session.update_rel_cache_add(eid, rtype, value, |
|
937 # rschema.symmetric) |
|
938 elif eschema.destination(rtype) in ('Bytes', 'Password'): |
915 elif eschema.destination(rtype) in ('Bytes', 'Password'): |
939 action.changes[column] = self._binary(value) |
916 action.changes[column] = self._binary(value) |
940 entity[rtype] = Binary(value) |
917 entity[rtype] = Binary(value) |
941 elif isinstance(value, str): |
918 elif isinstance(value, str): |
942 entity[rtype] = unicode(value, session.encoding, 'replace') |
919 entity[rtype] = unicode(value, session.encoding, 'replace') |