def delete_collection(collection_id): # Deleting a collection affects many associated objects and requires # checks, so this is done manually and in detail here. q = db.session.query(Collection).filter(Collection.id == collection_id) collection = q.first() if collection is None: log.error("No collection with ID: %r", collection_id) return log.info("Deleting collection [%r]: %r", collection.id, collection.label) deleted_at = datetime.utcnow() for entity in collection.entities: # TODO: consider hard-deleting entities because the polyglot tagger # cannot tell if a deleted match on a tagged term on a revived # collection means not to tag this entity any more. log.info("Delete entity: %r", entity) delete_entity(entity, deleted_at=deleted_at) for document in collection.documents: log.info("Delete document: %r", document) delete_document(document, deleted_at=deleted_at) db.session.refresh(collection) collection.delete(deleted_at=deleted_at) db.session.commit() index_delete(collection_id)
def delete_collection(collection_id=None): # Deleting a collection affects many associated objects and requires # checks, so this is done manually and in detail here. q = db.session.query(Collection).filter(Collection.id == collection_id) collection = q.first() if collection is None: log.error("No collection with ID: %r", collection_id) log.info("Deleting collection [%r]: %r", collection.id, collection.label) deleted_at = datetime.utcnow() for entity in collection.entities: entity.collections = [c for c in entity.collections if c.id != collection.id] db.session.add(entity) if not len(entity.collections): delete_entity(entity) else: update_entity(entity) for document in collection.documents: document.collections = [c for c in document.collections if c.id != collection.id] if not len(document.collections): delete_document(document, deleted_at=deleted_at) else: if collection_id == document.source_collection_id: document.source_collection_id = None db.session.add(document) update_document(document) collection.delete(deleted_at=deleted_at) db.session.commit() index_delete(collection_id) with graph.transaction() as tx: graph.remove_collection(tx, collection_id)
def delete_collection(collection_id): # Deleting a collection affects many associated objects and requires # checks, so this is done manually and in detail here. q = db.session.query(Collection).filter(Collection.id == collection_id) collection = q.first() if collection is None: log.error("No collection with ID: %r", collection_id) return log.info("Deleting collection [%r]: %r", collection.id, collection.label) index_delete(collection_id) deleted_at = datetime.utcnow() q = db.session.query(Entity) q = q.filter(Entity.collection_id == collection.id) for entity in q.yield_per(5000): log.info("Delete entity: %r", entity) delete_entity(entity, deleted_at=deleted_at) q = db.session.query(Document) q = q.filter(Document.collection_id == collection.id) for document in q.yield_per(5000): log.info("Delete document: %r", document) delete_document(document, deleted_at=deleted_at) collection.delete(deleted_at=deleted_at) db.session.commit()
def delete_collection(collection_id=None): # Deleting a collection affects many associated objects and requires # checks, so this is done manually and in detail here. q = db.session.query(Collection).filter(Collection.id == collection_id) collection = q.first() if collection is None: log.error("No collection with ID: %r", collection_id) log.info("Deleting collection [%r]: %r", collection.id, collection.label) deleted_at = datetime.utcnow() for entity in collection.entities: entity.collections = [ c for c in entity.collections if c.id != collection.id ] db.session.add(entity) if not len(entity.collections): delete_entity(entity) else: update_entity(entity) for document in collection.documents: document.collections = [ c for c in document.collections if c.id != collection.id ] if not len(document.collections): delete_document(document, deleted_at=deleted_at) else: if collection_id == document.source_collection_id: document.source_collection_id = None db.session.add(document) update_document(document) collection.delete(deleted_at=deleted_at) db.session.commit() index_delete(collection_id) with graph.transaction() as tx: graph.remove_collection(tx, collection_id)
def delete(document_id): document = get_db_document(document_id, request.authz.WRITE) delete_document(document) update_collection(document.collection) refresh_index(entities_index()) return ('', 204)
def delete(document_id): document = get_db_document(document_id, request.authz.WRITE) delete_document(document, sync=True) return ('', 204)
def delete(document_id): document = get_document(document_id, request.authz.WRITE) delete_document(document) update_collection(document.collection) return jsonify({'status': 'ok'}, status=410)