mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 15:30:13 +01:00
Fixed migrations.
Thanks to xet7 !
This commit is contained in:
parent
e8453783da
commit
63c314ca18
5 changed files with 314 additions and 187 deletions
|
|
@ -5,24 +5,44 @@
|
|||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { ReactiveVar } from 'meteor/reactive-var';
|
||||
import { check } from 'meteor/check';
|
||||
import { ReactiveCache } from '/imports/reactiveCache';
|
||||
import Attachments from '/models/attachments';
|
||||
|
||||
// Reactive variables for tracking migration progress
|
||||
const migrationProgress = new ReactiveVar(0);
|
||||
const migrationStatus = new ReactiveVar('');
|
||||
const unconvertedAttachments = new ReactiveVar([]);
|
||||
|
||||
// Track migrated boards on server side
|
||||
const migratedBoards = new Set();
|
||||
|
||||
class AttachmentMigrationService {
|
||||
constructor() {
|
||||
this.migrationCache = new Map();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a board has been migrated
|
||||
* @param {string} boardId - The board ID
|
||||
* @returns {boolean} - True if board has been migrated
|
||||
*/
|
||||
isBoardMigrated(boardId) {
|
||||
return migratedBoards.has(boardId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate all attachments for a board
|
||||
* @param {string} boardId - The board ID
|
||||
*/
|
||||
async migrateBoardAttachments(boardId) {
|
||||
try {
|
||||
// Check if board has already been migrated
|
||||
if (this.isBoardMigrated(boardId)) {
|
||||
console.log(`Board ${boardId} has already been migrated, skipping`);
|
||||
return { success: true, message: 'Board already migrated' };
|
||||
}
|
||||
|
||||
console.log(`Starting attachment migration for board: ${boardId}`);
|
||||
|
||||
// Get all attachments for the board
|
||||
|
|
@ -61,7 +81,12 @@ class AttachmentMigrationService {
|
|||
migrationStatus.set('Attachment migration completed');
|
||||
migrationProgress.set(100);
|
||||
|
||||
// Mark board as migrated
|
||||
migratedBoards.add(boardId);
|
||||
console.log(`Attachment migration completed for board: ${boardId}`);
|
||||
console.log(`Marked board ${boardId} as migrated`);
|
||||
|
||||
return { success: true, message: 'Migration completed' };
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Error migrating attachments for board ${boardId}:`, error);
|
||||
|
|
@ -176,15 +201,19 @@ const attachmentMigrationService = new AttachmentMigrationService();
|
|||
|
||||
// Meteor methods
|
||||
Meteor.methods({
|
||||
'attachmentMigration.migrateBoardAttachments'(boardId) {
|
||||
async 'attachmentMigration.migrateBoardAttachments'(boardId) {
|
||||
check(boardId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
||||
return attachmentMigrationService.migrateBoardAttachments(boardId);
|
||||
return await attachmentMigrationService.migrateBoardAttachments(boardId);
|
||||
},
|
||||
|
||||
'attachmentMigration.getProgress'(boardId) {
|
||||
check(boardId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
|
@ -193,11 +222,23 @@ Meteor.methods({
|
|||
},
|
||||
|
||||
'attachmentMigration.getUnconvertedAttachments'(boardId) {
|
||||
check(boardId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
||||
return attachmentMigrationService.getUnconvertedAttachments(boardId);
|
||||
},
|
||||
|
||||
'attachmentMigration.isBoardMigrated'(boardId) {
|
||||
check(boardId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
|
||||
return attachmentMigrationService.isBoardMigrated(boardId);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue