def _delete_document(document, deleted_at=None, sync=False): for child in document.children: # TODO: are we likely to hit recursion limits? _delete_document(child, deleted_at=deleted_at, sync=sync) flush_notifications(document) index.delete_document(document.id, sync=sync) document.delete(deleted_at=deleted_at)
def delete_document(document, deleted_at=None): for child in document.children: # TODO: are we likely to hit recursion limits? delete_document(child, deleted_at=deleted_at) index.delete_document(document.id) flush_notifications(document) document.delete(deleted_at=deleted_at)
def delete_collection(collection, keep_metadata=False, sync=False): cancel_queue(collection) aggregator = get_aggregator(collection) try: aggregator.drop() finally: aggregator.close() flush_notifications(collection, sync=sync) index.delete_entities(collection.id, sync=sync) xref_index.delete_xref(collection, sync=sync) deleted_at = collection.deleted_at or datetime.utcnow() Entity.delete_by_collection(collection.id, deleted_at=deleted_at) Mapping.delete_by_collection(collection.id, deleted_at=deleted_at) Diagram.delete_by_collection(collection.id, deleted_at=deleted_at) Document.delete_by_collection(collection.id) if not keep_metadata: # Considering linkages metadata for now, might be wrong: Linkage.delete_by_collection(collection.id) Permission.delete_by_collection(collection.id, deleted_at=deleted_at) collection.delete(deleted_at=deleted_at) db.session.commit() if not keep_metadata: index.delete_collection(collection.id, sync=True) Authz.flush() refresh_collection(collection.id, sync=True)
def delete_collection(collection, sync=False): flush_notifications(collection) collection.delete() db.session.commit() index.delete_collection(collection.id, sync=sync) delete_collection_content.apply_async([collection.id], priority=7) Authz.flush()
def prune_entity(collection, entity_id=None, job_id=None): """Prune handles the full deletion of an entity outside of the HTTP request cycle. This involves cleaning up adjacent entities like xref results, notifications and so on.""" # This is recursive and will also delete any entities which # reference the given entity. Usually this is going to be child # documents, or directoships referencing a person. It's a pretty # dangerous operation, though. log.info("[%s] Prune entity: %s", collection, entity_id) for adjacent in index.iter_adjacent(collection.id, entity_id): log.warning("Recursive delete: %s", adjacent.get("id")) delete_entity(collection, adjacent, job_id=job_id) flush_notifications(entity_id, clazz=Entity) obj = Entity.by_id(entity_id, collection=collection) if obj is not None: obj.delete() doc = Document.by_id(entity_id, collection=collection) if doc is not None: doc.delete() EntitySetItem.delete_by_entity(entity_id) Mapping.delete_by_table(entity_id) xref_index.delete_xref(collection, entity_id=entity_id) aggregator = get_aggregator(collection) aggregator.delete(entity_id=entity_id) refresh_entity(collection, entity_id) collection.touch() db.session.commit()
def _delete_document(document, deleted_at=None, sync=False): for child in document.children: # TODO: are we likely to hit recursion limits? _delete_document(child, deleted_at=deleted_at, sync=sync) flush_notifications(document) index.delete_document(document.id, sync=sync) document.delete(deleted_at=deleted_at)
def reset_collection(collection, sync=False): """Reset the collection by deleting any derived data.""" drop_aggregator(collection) cancel_queue(collection) flush_notifications(collection, sync=sync) index.delete_entities(collection.id, sync=sync) xref_index.delete_xref(collection, sync=sync) refresh_collection(collection.id, sync=sync)
def delete_collection(collection, sync=False): flush_notifications(collection) collection.delete() db.session.commit() index.delete_collection(collection.id, sync=sync) delete_collection_content.apply_async([collection.id], priority=7) refresh_collection(collection.id) Authz.flush()
def delete_collection(collection, sync=False): reset_collection(collection, sync=False) flush_notifications(collection) deleted_at = collection.deleted_at or datetime.utcnow() Entity.delete_by_collection(collection.id, deleted_at=deleted_at) Document.delete_by_collection(collection.id) Permission.delete_by_collection(collection.id, deleted_at=deleted_at) collection.delete(deleted_at=deleted_at) db.session.commit() index.delete_collection(collection.id, sync=sync) Authz.flush()
def delete_collection(collection, sync=False): flush_notifications(collection) drop_aggregator(collection) deleted_at = collection.deleted_at or datetime.utcnow() Entity.delete_by_collection(collection.id, deleted_at=deleted_at) Match.delete_by_collection(collection.id, deleted_at=deleted_at) Permission.delete_by_collection(collection.id, deleted_at=deleted_at) collection.delete(deleted_at=deleted_at) db.session.commit() index.delete_collection(collection.id, sync=sync) index.delete_entities(collection.id, sync=False) refresh_collection(collection.id) Authz.flush()
def delete_collection(collection, keep_metadata=False, sync=False): reset_collection(collection, sync=False) flush_notifications(collection) deleted_at = collection.deleted_at or datetime.utcnow() Entity.delete_by_collection(collection.id, deleted_at=deleted_at) Document.delete_by_collection(collection.id) Mapping.delete_by_collection(collection.id) if not keep_metadata: Permission.delete_by_collection(collection.id, deleted_at=deleted_at) collection.delete(deleted_at=deleted_at) db.session.commit() if not keep_metadata: index.delete_collection(collection.id, sync=sync) Authz.flush() refresh_collection(collection.id, sync=True)
def delete_entity(entity, deleted_at=None, sync=False): # This is recursive and will also delete any entities which # reference the given entity. Usually this is going to be child # documents, or directoships referencing a person. It's a pretty # dangerous operation, though. for adjacent in index.iter_adjacent(entity): log.warning("Recursive delete: %r", adjacent) delete_entity(adjacent, deleted_at=deleted_at, sync=sync) flush_notifications(entity.get('id'), clazz=Entity) obj = Entity.by_id(entity.get('id')) if obj is not None: obj.delete(deleted_at=deleted_at) doc = Document.by_id(entity.get('id')) if doc is not None: doc.delete(deleted_at=deleted_at) index.delete_entity(entity.get('id'), sync=sync) refresh_entity(entity)
def delete_collection(collection, keep_metadata=False, sync=False): cancel_queue(collection) aggregator = get_aggregator(collection) aggregator.drop() flush_notifications(collection, sync=sync) index.delete_entities(collection.id, sync=sync) xref_index.delete_xref(collection, sync=sync) deleted_at = collection.deleted_at or datetime.utcnow() Mapping.delete_by_collection(collection.id) EntitySet.delete_by_collection(collection.id, deleted_at) Entity.delete_by_collection(collection.id) Document.delete_by_collection(collection.id) if not keep_metadata: Permission.delete_by_collection(collection.id) collection.delete(deleted_at=deleted_at) db.session.commit() if not keep_metadata: index.delete_collection(collection.id, sync=True) Authz.flush() refresh_collection(collection.id)
def delete_entity(collection, entity, deleted_at=None, sync=False): # This is recursive and will also delete any entities which # reference the given entity. Usually this is going to be child # documents, or directoships referencing a person. It's a pretty # dangerous operation, though. entity_id = collection.ns.sign(entity.get("id")) for adjacent in index.iter_adjacent(entity): log.warning("Recursive delete: %r", adjacent) delete_entity(collection, adjacent, deleted_at=deleted_at, sync=sync) flush_notifications(entity_id, clazz=Entity) obj = Entity.by_id(entity_id, collection=collection) if obj is not None: obj.delete() doc = Document.by_id(entity_id, collection=collection) if doc is not None: doc.delete() index.delete_entity(entity_id, sync=sync) EntitySetItem.delete_by_entity(entity_id) Mapping.delete_by_table(entity_id) xref_index.delete_xref(collection, entity_id=entity_id, sync=sync) delete_aggregator_entity(collection, entity_id) refresh_entity(collection, entity_id)
def delete_entity(entity, deleted_at=None): flush_notifications(entity) entity.delete(deleted_at=deleted_at) index.delete_entity(entity.id)
def delete_entity(entity, deleted_at=None, sync=False): flush_notifications(entity) entity.delete(deleted_at=deleted_at) index.delete_entity(entity.id, sync=sync) # TODO: implement recursion? refresh_entity(entity)
def delete_entity(entity, deleted_at=None, sync=False): flush_notifications(entity) entity.delete(deleted_at=deleted_at) refresh_entity(entity) index.delete_entity(entity.id, sync=sync)
def delete_entity(entity, deleted_at=None, sync=False): flush_notifications(entity) entity.delete(deleted_at=deleted_at) refresh_entity(entity) index.delete_entity(entity.id, sync=sync)
def delete_collection(collection): flush_notifications(collection) collection.delete() db.session.commit() index.delete_collection(collection.id) delete_collection_content.apply_async([collection.id], priority=7)
def delete_entity(entity, deleted_at=None, sync=False): flush_notifications(entity) collection = entity.collection entity.delete(deleted_at=deleted_at) index.delete_entity(entity.id, sync=sync) refresh_collection(collection, sync=sync)