157 repo = self.session.repo |
157 repo = self.session.repo |
158 entity = self.entity |
158 entity = self.entity |
159 extid = entity.cw_metainformation()['extid'] |
159 extid = entity.cw_metainformation()['extid'] |
160 repo._type_source_cache[entity.eid] = ( |
160 repo._type_source_cache[entity.eid] = ( |
161 entity.cw_etype, self.newsource.uri, None, self.newsource.uri) |
161 entity.cw_etype, self.newsource.uri, None, self.newsource.uri) |
162 if self.oldsource.copy_based_source: |
162 repo._extid_cache[(extid, 'system')] = -entity.eid |
163 uri = 'system' |
163 |
164 else: |
|
165 uri = self.oldsource.uri |
|
166 repo._extid_cache[(extid, uri)] = -entity.eid |
|
167 |
164 |
168 class ChangeEntitySourceDeleteHook(MetaDataHook): |
165 class ChangeEntitySourceDeleteHook(MetaDataHook): |
169 """support for moving an entity from an external source by watching 'Any |
166 """support for moving an entity from an external source by watching 'Any |
170 cw_source CWSource' relation |
167 cw_source CWSource' relation |
171 """ |
168 """ |
195 raise Exception('changing source to something else than the ' |
192 raise Exception('changing source to something else than the ' |
196 'system source is unsupported') |
193 'system source is unsupported') |
197 syssource = newsource.repo_source |
194 syssource = newsource.repo_source |
198 oldsource = self._cw.entity_from_eid(schange[self.eidfrom]) |
195 oldsource = self._cw.entity_from_eid(schange[self.eidfrom]) |
199 entity = self._cw.entity_from_eid(self.eidfrom) |
196 entity = self._cw.entity_from_eid(self.eidfrom) |
200 # copy entity if necessary |
|
201 if not oldsource.repo_source.copy_based_source: |
|
202 entity.complete(skip_bytes=False, skip_pwd=False) |
|
203 if not entity.creation_date: |
|
204 entity.cw_attr_cache['creation_date'] = datetime.now() |
|
205 if not entity.modification_date: |
|
206 entity.cw_attr_cache['modification_date'] = datetime.now() |
|
207 entity.cw_attr_cache['cwuri'] = u'%s%s' % (self._cw.base_url(), entity.eid) |
|
208 entity.cw_edited = EditedEntity(entity, **entity.cw_attr_cache) |
|
209 syssource.add_entity(self._cw, entity) |
|
210 # we don't want the moved entity to be reimported later. To |
197 # we don't want the moved entity to be reimported later. To |
211 # distinguish this state, the trick is to change the associated |
198 # distinguish this state, the trick is to change the associated |
212 # record in the 'entities' system table with eid=-eid while leaving |
199 # record in the 'entities' system table with eid=-eid while leaving |
213 # other fields unchanged, and to add a new record with eid=eid, |
200 # other fields unchanged, and to add a new record with eid=eid, |
214 # source='system'. External source will then have consider case |
201 # source='system'. External source will then have consider case |