Skip to content

Commit

Permalink
fixed reprocess documents migration to ignore unexistent document
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Jul 14, 2017
1 parent 6f0362f commit 6e17927
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/api/migrations/reprocess_documents.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import P from 'bluebird';
import PDF from '../upload/PDF.js';
import entities from '../entities/entitiesModel';
import fs from 'fs';
import mongoose from 'mongoose';

entities.get({type: 'document'}, {_id: 1})
.then(documents => {
return P.resolve(documents).map(({_id}) => {
return entities.get({_id})
.then(([doc]) => {
if (!doc.file) {
return;
}
const file = __dirname + '/../../../uploaded_documents/' + doc.file.filename;
if (!fs.existsSync(file)) {
return;
}
return new PDF(file).convert()
.then((conversion) => {
doc.fullText = conversion.fullText;
Expand All @@ -23,4 +30,8 @@ entities.get({type: 'document'}, {_id: 1})
})
.then(() => {
mongoose.disconnect();
})
.catch((e) => {
console.log(e);
mongoose.disconnect();
});

0 comments on commit 6e17927

Please sign in to comment.