diff options
author | Lauri Ojansivu <x@xet7.org> | 2020-05-24 03:13:53 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2020-05-24 03:13:53 +0300 |
commit | 055b5285328f495203a7e225fdecd04bcf5c8b32 (patch) | |
tree | 361621362801c5409a08d60f45ebedb9f1cf9c02 /server/migrations.js | |
parent | fda392e662a842aa7e686ce13870c8adb35c35ab (diff) | |
parent | 921460db4031134db863e32101c0ad60a17416b5 (diff) | |
download | wekan-055b5285328f495203a7e225fdecd04bcf5c8b32.tar.gz wekan-055b5285328f495203a7e225fdecd04bcf5c8b32.tar.bz2 wekan-055b5285328f495203a7e225fdecd04bcf5c8b32.zip |
Merge branch 'lib-change' of https://github.com/PDIS/wekan into
PDIS-lib-change
Diffstat (limited to 'server/migrations.js')
-rw-r--r-- | server/migrations.js | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/server/migrations.js b/server/migrations.js index 5655bd1d..72b39ea7 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -80,7 +80,7 @@ Migrations.add('lowercase-board-permission', () => { Migrations.add('change-attachments-type-for-non-images', () => { const newTypeForNonImage = 'application/octet-stream'; Attachments.find().forEach(file => { - if (!file.isImage()) { + if (!file.isImage) { Attachments.update( file._id, { @@ -1044,3 +1044,46 @@ Migrations.add('add-sort-field-to-boards', () => { } }); }); + +import { MongoInternals } from 'meteor/mongo'; + +Migrations.add('change-attachment-library', () => { + 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); + let store = Attachments.storagePath(); + if (store.charAt(store.length - 1) === '/') { + store = store.substring(0, store.length - 1); + } + const path = `${store}/${file.name()}`; + const fd = fs.createWriteStream(path); + reader.pipe(fd); + reader.on('end', () => { + let opts = { + fileName: file.name(), + type: file.type(), + size: file.size(), + 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', file.name(), err); + } + }); + }); + }); +}); + |