def _delete_document(self, document_id, document_type, redirecting=False): # Check if documents are redirecting (merged) to the document to delete # If yes, delete them first. self._remove_merged_documents(document_id, document_type) _remove_from_cache(document_id) # Remove associations and update cache of formerly associated docs update_cache_version_full(document_id, document_type) _remove_associations(document_id) clazz, clazz_locale, archive_clazz, archive_clazz_locale = _get_models( document_type) # Order of removals depends on foreign key constraints _remove_history_metadata(document_id) _remove_archive_locale(archive_clazz_locale, document_id) _remove_archive_geometry(document_id) _remove_archive(archive_clazz, document_id) _remove_locale(clazz_locale, document_id) _remove_geometry(document_id) _remove_figures(clazz, document_id) if not redirecting: _remove_from_feed(document_id) if not redirecting and document_type == IMAGE_TYPE: # Remove the references of this image from the feed _remove_image_from_feed(document_id) # When all references have been deleted, finally remove the main # document entry _remove_document(document_id)
def _delete_document(self, document_id, document_type, redirecting=False): # Check if documents are redirecting (merged) to the document to delete # If yes, delete them first. self._remove_merged_documents(document_id, document_type) remove_from_cache(document_id) # Remove associations and update cache of formerly associated docs update_cache_version_full(document_id, document_type) _remove_associations(document_id) clazz, clazz_locale, archive_clazz, archive_clazz_locale = _get_models( document_type) if not redirecting: _remove_from_feed(document_id) if not redirecting and document_type == IMAGE_TYPE: # Remove the references of this image from the feed _remove_image_from_feed(document_id) if document_type == WAYPOINT_TYPE: _remove_waypoint_from_routes_archives_main_waypoint_id(document_id) remove_whole_document(document_id, clazz, clazz_locale, archive_clazz, archive_clazz_locale)
def delete(self): """ Delete a document locale. Request: `DELETE` `/documents/delete/{id}/{lang}` """ document_id = self.request.validated['id'] document_type = self.request.validated['document_type'] lang = self.request.validated['lang'] # Note: if an error occurs while deleting, SqlAlchemy will # automatically cancel all DB changes. # If only one locale is available, deleting it implies to remove # the whole document. if self.request.validated['is_only_locale']: return self._delete(document_id, document_type) clazz, clazz_locale, archive_clazz, archive_clazz_locale = _get_models( document_type) _remove_locale_versions(document_id, lang) _remove_archive_locale(archive_clazz_locale, document_id, lang) _remove_locale(clazz_locale, document_id, lang) update_langs_of_changes(document_id) update_cache_version_full(document_id, document_type) update_deleted_locales_list(document_id, document_type, lang) notify_es_syncer(self.request.registry.queue_config) return {}
def merge_user_accounts(source_user_id, target_user_id, queue_config): print('Removing from cache...') remove_from_cache(source_user_id) print('Removing geo associations...') _remove_geo_associations(source_user_id) print('Transfering associations...') _transfer_associations(source_user_id, target_user_id) print('Transfering tags...') _transfer_tags(source_user_id, target_user_id) print('Updating feed entries...') _update_feed_entries(source_user_id, target_user_id) print('Updating contributions versions and histories...') _update_history_metadata(source_user_id, target_user_id) print('Unregistering from mailing lists...') _unregister_from_mailinglists(source_user_id) print('Removing profile and user account...') _remove_user_account(source_user_id) # update the cache version for the source and target user accounts print('Updating associated documents cache...') update_cache_version_direct(source_user_id) update_cache_version_full(target_user_id, USERPROFILE_TYPE) # notify ES the source account no longer exists print('Notifying Elastic Search...') notify_es_syncer(queue_config)
def post(self): """ Merges a document into another document. - Associations and tags of the source document are transferred to the target document. - The association log entries are rewritten to the target document. - The time of the log entries is updated, so that the ES syncer will pick up the new associations of the target document. - The attribute `redirects_to` of the source document is set. - A new version is created for the source document. This makes sure that the ES syncer removes the document from ES index. - Update the cache version of the source document. - Update the cache version of the target document and its associations. - Removes the feed entries of the source document. Request: `POST` `/documents/merge` Request body: { 'source_document_id': @document_id@, 'target_document_id': @document_id@ } """ source_document_id = self.request.validated['source_document_id'] target_document_id = self.request.validated['target_document_id'] source_doc = DBSession.query(Document).get(source_document_id) # transfer associations from source to target transfer_associations(source_document_id, target_document_id) # transfer tags from source to target transfer_tags(source_document_id, target_document_id) # if waypoint, update main waypoint of routes if source_doc.type == WAYPOINT_TYPE: _transfer_main_waypoint(source_document_id, target_document_id) # set redirection and create a new version source_doc.redirects_to = target_document_id DocumentRest.update_version( source_doc, self.request.authenticated_userid, 'merged with {}'.format(target_document_id), [UpdateType.FIGURES], []) # update the cache version for the source and target document update_cache_version_direct(source_document_id) update_cache_version_full(target_document_id, source_doc.type) _remove_feed_entry(source_document_id) if source_doc.type == IMAGE_TYPE: delete_all_files_for_image(source_document_id, self.request) notify_es_syncer(self.request.registry.queue_config) return {}