def delete(entity_id): """ --- delete: summary: Delete an entity description: Delete the entity with id `entity_id` parameters: - in: path name: entity_id required: true schema: type: string responses: '204': description: No Content tags: - Entity """ entity = get_index_entity(entity_id, request.authz.WRITE) collection = get_db_collection(entity.get("collection_id"), request.authz.WRITE) tag_request(collection_id=collection.id) sync = get_flag("sync", default=True) job_id = get_session_id() delete_entity(collection, entity, sync=sync, job_id=job_id) return ("", 204)
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(entity_id): """ --- delete: summary: Delete an entity description: Delete the entity with id `entity_id` parameters: - in: path name: entity_id required: true schema: type: string responses: '204': description: No Content tags: - Entity """ entity = get_index_entity(entity_id, request.authz.WRITE) collection = get_db_collection(entity.get('collection_id'), request.authz.WRITE) tag_request(collection_id=collection.id) delete_entity(collection, entity, sync=get_flag('sync', True)) db.session.commit() return ('', 204)
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): # 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(id): entity = get_db_entity(id, request.authz.WRITE) delete_entity(entity) db.session.commit() update_collection(entity.collection) refresh_index(entities_index()) return ('', 204)
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(entity_id): entity = get_db_entity(entity_id, request.authz.WRITE) tag_request(collection_id=entity.collection_id) delete_entity(entity, sync=True) db.session.commit() return ('', 204)
def delete(id): entity = get_db_entity(id, request.authz.WRITE) delete_entity(entity) db.session.commit() update_collection(entity.collection) return jsonify({'status': 'ok'}, status=410)
def delete(id): entity = get_db_entity(id, request.authz.WRITE) delete_entity(entity, sync=True) db.session.commit() return ('', 204)
def delete(entity_id): entity = get_index_entity(entity_id, request.authz.WRITE) tag_request(collection_id=entity.get('collection_id')) delete_entity(entity, sync=get_flag('sync', False)) db.session.commit() return ('', 204)