Skip to content

Commit d44c166

Browse files
author
Romaric Mourgues
committed
Fix migration tool not running queue for previews
1 parent 9c50ebf commit d44c166

File tree

8 files changed

+19
-12
lines changed

8 files changed

+19
-12
lines changed

twake/backend/node/src/cli/cmds/migration_cmds/drive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const services = [
1818
"tracker",
1919
"websocket",
2020
"email-pusher",
21+
"files",
2122
];
2223

2324
const command: yargs.CommandModule<unknown, unknown> = {

twake/backend/node/src/cli/cmds/migration_cmds/php-drive-file/drive-migrator-service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ class DriveMigrator {
8080
logger.info(`Migrating company ${company.id}`);
8181

8282
const companyAdminOrOwnerId = await this.getCompanyOwnerOrAdminId(company.id, context);
83+
if (!companyAdminOrOwnerId) {
84+
return;
85+
}
8386
const workspaceList = await globalResolver.services.workspaces.getAllForCompany(company.id);
87+
if (!workspaceList || workspaceList.length === 0) {
88+
return;
89+
}
8490

8591
for (const workspace of workspaceList) {
8692
const wsContext = {
@@ -252,6 +258,9 @@ class DriveMigrator {
252258
context,
253259
);
254260

261+
logger.info(
262+
`Migrating version ${version.id} of item ${item.id}... (downloading then uploading...)`,
263+
);
255264
const file = await this.phpDriveService.migrate(
256265
version.file_id,
257266
item.workspace_id,
@@ -331,6 +340,9 @@ class DriveMigrator {
331340
{ pagination },
332341
context,
333342
);
343+
if (!companyUsers.getEntities().length && !pagination?.page_token) {
344+
return null;
345+
}
334346

335347
pagination = companyUsers.nextPage as Pagination;
336348

@@ -341,7 +353,7 @@ class DriveMigrator {
341353
if (companyAdminOrOwner) {
342354
companyOwnerOrAdminId = companyAdminOrOwner.id;
343355
}
344-
} while (pagination && !companyOwnerOrAdminId);
356+
} while (pagination?.page_token && !companyOwnerOrAdminId);
345357

346358
return companyOwnerOrAdminId;
347359
};

twake/backend/node/src/cli/cmds/migration_cmds/php-drive-file/php-drive-file-entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const TYPE = "drive_file";
1212
})
1313
export class PhpDriveFile {
1414
@Type(() => String)
15-
@Column("workspace_id", "timeuuid")
15+
@Column("workspace_id", "string")
1616
workspace_id: string;
1717

1818
@Type(() => String)

twake/backend/node/src/cli/cmds/migration_cmds/php-drive-file/php-drive-file-version-entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class PhpDriveFileVersion {
1616
id: string;
1717

1818
@Type(() => String)
19-
@Column("file_id", "string")
19+
@Column("file_id", "timeuuid")
2020
file_id: string;
2121

2222
@Type(() => String)

twake/backend/node/src/core/platform/services/message-queue/amqp/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from "../api";
1010
import MessageQueueProxy from "../proxy";
1111
import { AMQPMessageQueueManager } from "./manager";
12-
import { SkipCLI } from "../../../framework/decorators/skip";
1312

1413
const logger = rootLogger.child({
1514
component: "twake.core.platform.services.message-queue.amqp",
@@ -28,7 +27,6 @@ export class AMQPMessageQueueService implements MessageQueueAdapter {
2827
this.clientProxy = new MessageQueueProxy();
2928
}
3029

31-
@SkipCLI()
3230
async init(): Promise<this> {
3331
logger.info("Initializing message-queue service implementation with urls %o", this.urls);
3432
await this.manager.createClient(this.urls);

twake/backend/node/src/core/platform/services/message-queue/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class MessageQueueAdapterFactory {
1717
logger.info("Building Adapter %o", type);
1818

1919
switch (type) {
20-
case "local":
20+
case "local" || process.env.NODE_ENV === "cli":
2121
return new LocalMessageQueueService();
2222
case "amqp":
2323
let urls: string[] = configuration.get<string[]>("amqp.urls", [DEFAULT_AMQP_URL]);

twake/backend/node/src/core/platform/services/message-queue/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import { eventBus } from "./bus";
1010
import { Processor } from "./processor";
1111
import adapterFactory from "./factory";
12-
import { SkipCLI } from "../../framework/decorators/skip";
1312
import config from "../../../../core/config";
1413

1514
const logger = rootLogger.child({
@@ -61,15 +60,13 @@ export class MessageQueueService implements MessageQueueServiceAPI {
6160
this.processor = new Processor(this);
6261
}
6362

64-
@SkipCLI()
6563
async init(): Promise<this> {
6664
logger.info("Initializing message-queue adapter %o", this.adapter.type);
6765
await this.adapter?.init?.();
6866

6967
return this;
7068
}
7169

72-
@SkipCLI()
7370
async start(): Promise<this> {
7471
logger.info("Starting message-queue adapter %o", this.adapter.type);
7572
await this.adapter?.start?.();
@@ -78,7 +75,6 @@ export class MessageQueueService implements MessageQueueServiceAPI {
7875
return this;
7976
}
8077

81-
@SkipCLI()
8278
async stop(): Promise<this> {
8379
logger.info("Stopping message-queue adapter %o", this.adapter.type);
8480
await this.adapter?.stop?.();

twake/backend/node/src/services/files/services/preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class PreviewFinishedProcessor
3030
name = "FilePreviewProcessor";
3131

3232
validate(message: PreviewMessageQueueCallback): boolean {
33-
return !!(message && message.document && message.thumbnails);
33+
return !!(message && message.document);
3434
}
3535

3636
async process(message: PreviewMessageQueueCallback, context?: ExecutionContext): Promise<string> {
@@ -46,7 +46,7 @@ export class PreviewFinishedProcessor
4646
return;
4747
}
4848

49-
entity.thumbnails = message.thumbnails.map((thumb, index) => {
49+
entity.thumbnails = (message.thumbnails || []).map((thumb, index) => {
5050
return {
5151
index,
5252
id: thumb.path.split("/").pop(),

0 commit comments

Comments
 (0)