refactor: On workflow deletion, cascade delete all entities associated with it (#5102)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-01-10 09:23:44 +01:00
committed by GitHub
parent 7df0728999
commit 0e955760a1
9 changed files with 247 additions and 41 deletions

View File

@@ -420,4 +420,34 @@ export class WorkflowsService {
executionId,
};
}
static async delete(user: User, workflowId: string): Promise<WorkflowEntity | undefined> {
await ExternalHooks().run('workflow.delete', [workflowId]);
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
relations: ['workflow', 'role'],
where: whereClause({
user,
entityType: 'workflow',
entityId: workflowId,
roles: ['owner'],
}),
});
if (!sharedWorkflow) {
return;
}
if (sharedWorkflow.workflow.active) {
// deactivate before deleting
await ActiveWorkflowRunner.getInstance().remove(workflowId);
}
await Db.collections.Workflow.delete(workflowId);
void InternalHooksManager.getInstance().onWorkflowDeleted(user, workflowId, false);
await ExternalHooks().run('workflow.afterDelete', [workflowId]);
return sharedWorkflow.workflow;
}
}