def delete_collection(collection_id, wait=False): # Deleting a collection affects many associated objects and requires # checks, so this is done manually and in detail here. q = db.session.query(Collection) q = q.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() index_delete(collection_id, wait=wait) log.info("Deleting cross-referencing matches...") Match.delete_by_collection(collection_id) log.info("Deleting permissions...") Permission.delete_by_collection(collection_id, deleted_at=deleted_at) delete_documents(collection_id, wait=wait) delete_entities(collection_id, wait=wait) collection.delete(deleted_at=deleted_at) db.session.commit()
def delete_documents(collection_id, deleted_at=None): deleted_at = deleted_at or datetime.utcnow() log.info("Deleting documents...") Document.delete_by_collection(collection_id, deleted_at=deleted_at) index.delete_documents(collection_id) log.info("Deleting cross-referencing matches...") Match.delete_by_collection(collection_id, deleted_at=deleted_at)
def delete_entities(collection_id, deleted_at=None): deleted_at = deleted_at or datetime.utcnow() log.info("Deleting entities...") Entity.delete_by_collection(collection_id, deleted_at=deleted_at) index.delete_entities(collection_id) log.info("Deleting cross-referencing matches...") Match.delete_by_collection(collection_id, deleted_at=deleted_at)
def reset_collection(collection): """Reset the collection by deleting any derived data.""" drop_aggregator(collection) Match.delete_by_collection(collection.id) db.session.commit() cancel_queue(collection) refresh_collection(collection.id)
def reset_collection(collection, sync=False): """Reset the collection by deleting any derived data.""" drop_aggregator(collection) Match.delete_by_collection(collection.id) cancel_queue(collection) index.delete_entities(collection.id, sync=sync) refresh_collection(collection.id) db.session.commit()
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_content(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) q = q.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 = 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) index.delete_collection(collection_id) index.delete_entities(collection_id) collection.delete(deleted_at=deleted_at) db.session.commit()
def delete_bulk_entities(collection_id, deleted_at=None): deleted_at = deleted_at or datetime.utcnow() log.info("Deleting entities...") index.delete_entities(collection_id, bulk_only=True) Match.delete_by_collection(collection_id, deleted_at=deleted_at)