mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 08:04:51 +00:00
chore: udpate jsdocs
This commit is contained in:
parent
df8efe760a
commit
17b9fd4bf9
@ -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;
|
||||
|
||||
@ -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<string>} options.srcContentTypes - The content types assigned to the previous workflow
|
||||
* @param {Array<string>} 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
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user