def delete_record(self, fileinstance_id, record_uuid): """Delete a record. :param fileinstance_id: The file instance id. :param record_uuid: The record's uuid. """ # get the FileInstance object file_instance = FileInstance.get(fileinstance_id) # get the uri of the file for the directory of the folder uri = file_instance.uri # building the path to delete by storing the index of the folder data i = uri.find('data') # removing the record indexing, the record and the file instance recind = RecordIndexer() recind.delete_by_id(record_uuid=record_uuid) self.delete_bucket() FileInstance.query.filter_by(id=fileinstance_id).delete() PersistentIdentifier.query.filter_by(object_uuid=record_uuid).delete() db.session.commit() # removing the file on disk and the folder containing it # the full path is /home/<user>/.local/share/virtualenvs/ # fare-platform-<code>/var/instance/data/<f1>/<f2>/<bucketid>/<filename> # after have stored the index of the folder "data", where there are all # the records, the path is passed to the function below # and trimmed at <f1>, a folder name composed by 2 character, # at the index "i" is added 8 because is the number of # character for completing the path, terminating at "<f1>/" shutil.rmtree(uri[:i + 8]) current_app.logger.info("Deleted file= " + self['title'] + ", by user= " + current_user.email)
def indexed_loans(es, test_loans): """Get a function to wait for records to be flushed to index.""" indexer = RecordIndexer() for pid, loan in test_loans: indexer.index(loan) current_search.flush_and_refresh(index="loans") yield test_loans for pid, loan in test_loans: indexer.delete_by_id(loan.id) current_search.flush_and_refresh(index="loans")
def remove_records(app, record_ids): """Remove all records.""" with app.app_context(): indexer = RecordIndexer() for r_id in record_ids: record = RecordMetadata.query.get(r_id) indexer.delete_by_id(r_id) pids = PersistentIdentifier.query.filter_by(object_uuid=r_id).all() for pid in pids: db.session.delete(pid) db.session.delete(record) db.session.commit()
def remove_records(app, record_ids): """Remove all records.""" with app.app_context(): indexer = RecordIndexer() for r_id in record_ids: record = RecordMetadata.query.get(r_id) indexer.delete_by_id(r_id) pids = PersistentIdentifier.query.filter_by( object_uuid=r_id).all() for pid in pids: db.session.delete(pid) db.session.delete(record) db.session.commit()