From 66eb52aab8484ca7224f68639ef67d5e6e9fe55f Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Tue, 16 May 2023 15:32:40 +0200 Subject: [PATCH] chore: remove enableReviewWorkflows as it is not necessary anymore --- .../review-workflows/review-workflows.js | 41 +------------------ .../admin/ee/server/utils/review-workflows.js | 6 --- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/packages/core/admin/ee/server/services/review-workflows/review-workflows.js b/packages/core/admin/ee/server/services/review-workflows/review-workflows.js index b7b2a45cb4..8b6133b054 100644 --- a/packages/core/admin/ee/server/services/review-workflows/review-workflows.js +++ b/packages/core/admin/ee/server/services/review-workflows/review-workflows.js @@ -1,7 +1,6 @@ 'use strict'; const { set, forEach, pipe, map } = require('lodash/fp'); -const { mapAsync } = require('@strapi/utils'); const { getService } = require('../../utils'); const { getVisibleContentTypesUID } = require('../../utils/review-workflows'); @@ -9,10 +8,9 @@ const defaultStages = require('../../constants/default-stages.json'); const defaultWorkflow = require('../../constants/default-workflow.json'); const { ENTITY_STAGE_ATTRIBUTE } = require('../../constants/workflows'); -const { getDefaultWorkflow } = require('../../utils/review-workflows'); const { persistTables, removePersistedTablesWithSuffix } = require('../../utils/persisted-tables'); -async function initDefaultWorkflow({ workflowsService, stagesService, strapi }) { +async function initDefaultWorkflow({ workflowsService, stagesService }) { const wfCount = await workflowsService.count(); const stagesCount = await stagesService.count(); @@ -25,8 +23,6 @@ async function initDefaultWorkflow({ workflowsService, stagesService, strapi }) }; await workflowsService.create({ data: workflow }); - // If there is any manually activated RW on content-types, we want to migrate the related entities - await enableReviewWorkflow({ strapi })({ contentTypes: strapi.contentTypes }); } } @@ -52,40 +48,6 @@ function extendReviewWorkflowContentTypes({ strapi }) { ])(strapi.contentTypes); } -/** - * Enables the review workflow for the given content types. - * @param {Object} strapi - Strapi instance - */ -function enableReviewWorkflow({ strapi }) { - /** - * @param {Array} contentTypes - Content type UIDs to enable the review workflow for. - * @returns {Promise} - Promise that resolves when the review workflow is enabled. - */ - return async ({ contentTypes }) => { - const defaultWorkflow = await getDefaultWorkflow({ strapi }); - // This is possible if this is the first start of EE, there won't be any workflow in DB before bootstrap - if (!defaultWorkflow) { - return; - } - const firstStage = defaultWorkflow.stages[0]; - const stagesService = getService('stages', { strapi }); - - const updateEntitiesStage = async (contentTypeUID) => { - // Update CT entities stage - return stagesService.updateEntitiesStage(contentTypeUID, { - fromStageId: null, - toStageId: firstStage.id, - }); - }; - - return pipe([ - getVisibleContentTypesUID, - // Iterate over UIDs to extend the content-type - (contentTypesUIDs) => mapAsync(contentTypesUIDs, updateEntitiesStage), - ])(contentTypes); - }; -} - function persistStagesJoinTables({ strapi }) { return async ({ contentTypes }) => { const getStageTableToPersist = (contentTypeUID) => { @@ -115,7 +77,6 @@ module.exports = ({ strapi }) => { }, async register() { extendReviewWorkflowContentTypes({ strapi }); - strapi.hook('strapi::content-types.afterSync').register(enableReviewWorkflow({ strapi })); strapi.hook('strapi::content-types.afterSync').register(persistStagesJoinTables({ strapi })); }, }; diff --git a/packages/core/admin/ee/server/utils/review-workflows.js b/packages/core/admin/ee/server/utils/review-workflows.js index cd8b3a39f3..7ac616c5ed 100644 --- a/packages/core/admin/ee/server/utils/review-workflows.js +++ b/packages/core/admin/ee/server/utils/review-workflows.js @@ -1,11 +1,6 @@ 'use strict'; const { getOr, keys, pickBy, pipe } = require('lodash/fp'); -const { WORKFLOW_MODEL_UID } = require('../constants/workflows'); - -// TODO To be refactored when multiple workflows are added -const getDefaultWorkflow = async ({ strapi }) => - strapi.query(WORKFLOW_MODEL_UID).findOne({ populate: ['stages'] }); const getVisibleContentTypesUID = pipe([ // Pick only content-types visible in the content-manager @@ -15,6 +10,5 @@ const getVisibleContentTypesUID = pipe([ ]); module.exports = { - getDefaultWorkflow, getVisibleContentTypesUID, };