From 17b9fd4bf9e4ccb1daba6065a3fb754820439c73 Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Wed, 17 May 2023 09:40:14 +0200 Subject: [PATCH] chore: udpate jsdocs --- .../services/review-workflows/stages.js | 41 +++++++++++-------- .../workflows/content-types.js | 9 ++-- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/core/admin/ee/server/services/review-workflows/stages.js b/packages/core/admin/ee/server/services/review-workflows/stages.js index c2e597a0ff..2035a41400 100644 --- a/packages/core/admin/ee/server/services/review-workflows/stages.js +++ b/packages/core/admin/ee/server/services/review-workflows/stages.js @@ -133,9 +133,15 @@ module.exports = ({ strapi }) => { }, /** - * Updates the stage of all entities of a content type that are in a specific stage + * Updates entity stages of a content type: + * - If fromStageId is undefined, all entities with an existing stage will be assigned the new stage + * - If fromStageId is null, all entities without a stage will be assigned the new stage + * - If fromStageId is a number, all entities with that stage will be assigned the new stage + * + * For performance reasons we use knex queries directly. + * * @param {string} contentTypeUID - * @param {number} fromStageId + * @param {number | undefined | null} fromStageId * @param {number} toStageId * @returns */ @@ -145,6 +151,17 @@ module.exports = ({ strapi }) => { const joinColumn = joinTable.joinColumn.name; const invJoinColumn = joinTable.inverseJoinColumn.name; + if (fromStageId === undefined) { + // Update all already existing links to the new stage + return strapi.db.transaction(async ({ trx }) => + strapi.db + .getConnection() + .from(joinTable.name) + .update({ [invJoinColumn]: toStageId }) + .transacting(trx) + ); + } + return strapi.db.transaction(async ({ trx }) => { const selectStatement = strapi.db .getConnection() @@ -167,21 +184,11 @@ module.exports = ({ strapi }) => { }); }, - async updateAllEntitiesStage(contentTypeUID, { toStageId }) { - const { attributes } = strapi.db.metadata.get(contentTypeUID); - const joinTable = attributes[ENTITY_STAGE_ATTRIBUTE].joinTable; - const invJoinColumn = joinTable.inverseJoinColumn.name; - - // Move all entries to the specified stage - return strapi.db.transaction(async ({ trx }) => - strapi.db - .getConnection() - .from(joinTable.name) - .update({ [invJoinColumn]: toStageId }) - .transacting(trx) - ); - }, - + /** + * Deletes all entity stages of a content type + * @param {string} contentTypeUID + * @returns + */ async deleteAllEntitiesStage(contentTypeUID) { const { attributes } = strapi.db.metadata.get(contentTypeUID); const joinTable = attributes[ENTITY_STAGE_ATTRIBUTE].joinTable; diff --git a/packages/core/admin/ee/server/services/review-workflows/workflows/content-types.js b/packages/core/admin/ee/server/services/review-workflows/workflows/content-types.js index fa79bae980..c156f8853e 100644 --- a/packages/core/admin/ee/server/services/review-workflows/workflows/content-types.js +++ b/packages/core/admin/ee/server/services/review-workflows/workflows/content-types.js @@ -7,7 +7,7 @@ const { WORKFLOW_MODEL_UID } = require('../../../constants/workflows'); module.exports = ({ strapi }) => ({ /** - * Migrate content types entities assigned to a workflow + * Migrates entities stages. Used when a content type is assigned to a workflow. * @param {*} options * @param {Array} options.srcContentTypes - The content types assigned to the previous workflow * @param {Array} options.destContentTypes - The content types assigned to the new workflow @@ -20,12 +20,12 @@ module.exports = ({ strapi }) => ({ // If it was assigned to another workflow, transfer it from the previous workflow const srcWorkflow = await getService('workflows').getAssignedWorkflow(uid); if (srcWorkflow) { - // Updates all entities stages links to the new stage - await getService('stages').updateAllEntitiesStage(uid, { toStageId: stageId }); + // Updates all existing entities stages links to the new stage + await getService('stages').updateEntitiesStage(uid, { toStageId: stageId }); return this.transferContentType(srcWorkflow, uid); } - // Create entity stages links to the new stage + // Create new stages links to the new stage return getService('stages').updateEntitiesStage(uid, { fromStageId: null, toStageId: stageId, @@ -38,6 +38,7 @@ module.exports = ({ strapi }) => ({ }, /** + * Filters the content types assigned to the previous workflow. * @param {Workflow} srcWorkflow - The workflow to transfer from * @param {string} uid - The content type uid */