mirror of
https://github.com/wekan/wekan.git
synced 2025-12-30 22:28:49 +01:00
Migrating attachments
This commit is contained in:
parent
5899b9366c
commit
0a1bfd37b3
2 changed files with 247 additions and 3 deletions
|
|
@ -1039,9 +1039,41 @@ Migrations.add('fix-incorrect-dates', () => {
|
|||
console.log('cas', cas);
|
||||
});
|
||||
|
||||
import { MongoInternals } from 'meteor/mongo';
|
||||
|
||||
Migrations.add('change-attachment-library', () => {
|
||||
console.log('migration called here');
|
||||
Migrations.rollback('change-attachment-library');
|
||||
console.log('migration rollbacked');
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
CFSAttachments.find().forEach(file => {
|
||||
const bucket = new MongoInternals.NpmModule.GridFSBucket(MongoInternals.defaultRemoteCollectionDriver().mongo.db, {bucketName: 'cfs_gridfs.attachments'});
|
||||
const gfsId = new MongoInternals.NpmModule.ObjectID(file.copies.attachments.key);
|
||||
const reader = bucket.openDownloadStream(gfsId);
|
||||
const path = `/var/attachments/${file.name()}`;
|
||||
const fd = fs.createWriteStream(path);
|
||||
reader.pipe(fd);
|
||||
let opts = {
|
||||
fileName: file.name(),
|
||||
type: file.type(),
|
||||
fileId: file._id,
|
||||
meta: {
|
||||
userId: file.userId,
|
||||
boardId: file.boardId,
|
||||
cardId: file.cardId
|
||||
}
|
||||
};
|
||||
if (file.listId) {
|
||||
opts.meta.listId = file.listId;
|
||||
}
|
||||
if (file.swimlaneId) {
|
||||
opts.meta.swimlaneId = file.swimlaneId;
|
||||
}
|
||||
Attachments.addFile(path, opts, (err, fileRef) => {
|
||||
if (err) {
|
||||
console.log('error when migrating ', fileName, err);
|
||||
} else {
|
||||
file.remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue