From 128b26f1ee7239b0818e543d618bab825df2bd1c Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 22 Jul 2019 17:31:20 +0200 Subject: [PATCH] Fix general settings global udpdates --- .../services/GeneralSettings.js | 3 +- .../services/utils/schema.js | 9 +++++- .../services/utils/store.js | 30 +++---------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/packages/strapi-plugin-content-manager/services/GeneralSettings.js b/packages/strapi-plugin-content-manager/services/GeneralSettings.js index b01ad90d7e..c25c0c5927 100644 --- a/packages/strapi-plugin-content-manager/services/GeneralSettings.js +++ b/packages/strapi-plugin-content-manager/services/GeneralSettings.js @@ -25,8 +25,9 @@ module.exports = { strapi.plugins['content-manager'].services.contenttypes; const configurations = await storeUtils.getAllConfigurations(); + await Promise.all( - configurations.map(({ value }) => { + configurations.map(value => { const { uid, source } = value; const settings = { ...value.settings, diff --git a/packages/strapi-plugin-content-manager/services/utils/schema.js b/packages/strapi-plugin-content-manager/services/utils/schema.js index f7efd6c954..430764c6aa 100644 --- a/packages/strapi-plugin-content-manager/services/utils/schema.js +++ b/packages/strapi-plugin-content-manager/services/utils/schema.js @@ -2,7 +2,14 @@ const _ = require('lodash'); -const pickSchemaFields = model => _.pick(model, []); +const pickSchemaFields = model => + _.pick(model, [ + 'connection', + 'collectionName', + 'info', + 'options', + 'attributes', + ]); module.exports = { pickSchemaFields, diff --git a/packages/strapi-plugin-content-manager/services/utils/store.js b/packages/strapi-plugin-content-manager/services/utils/store.js index 6b372813c4..50106a63eb 100644 --- a/packages/strapi-plugin-content-manager/services/utils/store.js +++ b/packages/strapi-plugin-content-manager/services/utils/store.js @@ -15,31 +15,6 @@ const getStore = () => { }); }; -function getAllConfigurationsQuery({ model }) { - if (model.orm === 'mongoose') { - return model - .find({ - $regex: `plugin_content_manager_configuration.*`, - }) - .then(results => - results.map(({ key, value }) => ({ key, value: JSON.parse(value) })) - ); - } - - return model - .query(qb => { - qb.where('key', 'like', `plugin_content_manager_configuration%`); - }) - .fetchAll() - .then(config => config && config.toJSON()) - .then(results => - results.map(({ key, value }) => ({ key, value: JSON.parse(value) })) - ); -} - -const getAllConfigurations = () => - strapi.query('core_store').custom(getAllConfigurationsQuery)(); - /** General settings */ const getGeneralSettings = () => @@ -99,7 +74,7 @@ function findByKeyQuery({ model }, key) { if (model.orm === 'mongoose') { return model .find({ - $regex: `${key}.*`, + key: { $regex: `${key}.*` }, }) .then(results => results.map(({ value }) => JSON.parse(value))); } @@ -115,6 +90,9 @@ function findByKeyQuery({ model }, key) { const findByKey = key => strapi.query('core_store').custom(findByKeyQuery)(key); +const getAllConfigurations = () => + findByKey('plugin_content_manager_configuration'); + module.exports = { getGeneralSettings, setGeneralSettings,