diff --git a/packages/core/content-type-builder/services/content-types.js b/packages/core/content-type-builder/services/content-types.js index 4035b2ebf3..a2df64b020 100644 --- a/packages/core/content-type-builder/services/content-types.js +++ b/packages/core/content-type-builder/services/content-types.js @@ -7,7 +7,6 @@ const generator = require('@strapi/generate'); const { nameToSlug, contentTypes: contentTypesUtils } = require('@strapi/utils'); const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes'); const createBuilder = require('./schema-builder'); -const apiHandler = require('./api-handler'); const { coreUids, pluginsUids } = require('./constants'); const isContentTypeVisible = model => @@ -187,6 +186,7 @@ const editContentType = async (uid, { contentType, components = [] }) => { }); if (newKind !== previousKind) { + const apiHandler = strapi.service('plugin::content-type-builder.api-handler'); await apiHandler.backup(uid); try { @@ -213,6 +213,7 @@ const editContentType = async (uid, { contentType, components = [] }) => { const deleteContentTypes = async uids => { const builder = createBuilder(); + const apiHandler = strapi.service('plugin::content-type-builder.api-handler'); for (const uid of uids) { await deleteContentType(uid, builder); @@ -237,6 +238,8 @@ const deleteContentTypes = async uids => { const deleteContentType = async (uid, defaultBuilder = undefined) => { const builder = defaultBuilder || createBuilder(); // make a backup + const apiHandler = strapi.service('plugin::content-type-builder.api-handler'); + await new Promise(resolve => setTimeout(resolve, 3000)); await apiHandler.backup(uid); const contentType = builder.deleteContentType(uid); diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 330fc0d44e..eae53fd005 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -78,6 +78,10 @@ class Strapi { return ee({ dir: this.dir, logger: this.log }); } + service(uid) { + return this.container.get('services').get(uid); + } + plugin(name) { return this.container.get('modules').get(`plugin::${name}`); } diff --git a/packages/plugins/users-permissions/services/users-permissions.js b/packages/plugins/users-permissions/services/users-permissions.js index a77409dd46..10f1c3d811 100644 --- a/packages/plugins/users-permissions/services/users-permissions.js +++ b/packages/plugins/users-permissions/services/users-permissions.js @@ -232,7 +232,7 @@ module.exports = ({ strapi }) => ({ return acc.concat(_.get(strapi.api[current].config, 'routes', [])); }, []); const pluginsRoutes = Object.keys(strapi.plugins).reduce((acc, current) => { - const routes = strapi.container.plugin(current).routes.reduce((acc, curr) => { + const routes = strapi.plugin(current).routes.reduce((acc, curr) => { const prefix = curr.config.prefix; const path = prefix !== undefined ? `${prefix}${curr.path}` : `/${current}${curr.path}`; _.set(curr, 'path', path); diff --git a/test/helpers/generators.js b/test/helpers/generators.js index a8d6fe1adb..2d851e8c58 100644 --- a/test/helpers/generators.js +++ b/test/helpers/generators.js @@ -18,11 +18,11 @@ module.exports = { author: { type: 'relation', relation: 'manyToOne', - target: 'plugins::users-permissions.user', + target: 'plugin::users-permissions.user', targetAttribute: 'articles', }, }, - uid: 'application::article.article', + uid: 'api::article.article', name: 'article', description: '', collectionName: '', @@ -35,11 +35,11 @@ module.exports = { articles: { type: 'relation', relation: 'manyToMany', - target: 'application::article.article', + target: 'api::article.article', targetAttribute: 'tags', }, }, - uid: 'application::tag.tag', + uid: 'api::tag.tag', name: 'tag', description: '', collectionName: '', @@ -52,11 +52,11 @@ module.exports = { articles: { type: 'relation', relation: 'oneToMany', - target: 'application::article.article', + target: 'api::article.article', targetAttribute: 'category', }, }, - uid: 'application::category.category', + uid: 'api::category.category', name: 'category', description: '', collectionName: '', @@ -69,16 +69,16 @@ module.exports = { article: { type: 'relation', relation: 'oneToOne', - target: 'application::article.article', + target: 'api::article.article', targetAttribute: 'reference', }, tag: { type: 'relation', relation: 'oneToOne', - target: 'application::tag.tag', + target: 'api::tag.tag', }, }, - uid: 'application::reference.reference', + uid: 'api::reference.reference', name: 'reference', description: '', collectionName: 'refs', @@ -95,7 +95,7 @@ module.exports = { type: 'boolean', }, }, - uid: 'application::product.product', + uid: 'api::product.product', name: 'product', description: '', collectionName: '', @@ -108,10 +108,10 @@ module.exports = { tags: { type: 'relation', relation: 'oneToMany', - target: 'application::tag.tag', + target: 'api::tag.tag', }, }, - uid: 'application::articlewit.articlewit', + uid: 'api::articlewit.articlewit', name: 'articlewithtag', description: '', collectionName: '', diff --git a/test/helpers/models.js b/test/helpers/models.js index 70622273d8..e122456662 100644 --- a/test/helpers/models.js +++ b/test/helpers/models.js @@ -4,7 +4,7 @@ const { isFunction, isNil, prop } = require('lodash/fp'); const { createStrapiInstance } = require('./strapi'); const toUID = name => { - return name.includes('::') ? name : `application::${name}.${name}`; + return name.includes('::') ? name : `api::${name}.${name}`; }; const createHelpers = async ({ strapi: strapiInstance = null, ...options } = {}) => {