mirror of
https://github.com/strapi/strapi.git
synced 2025-12-29 16:16:20 +00:00
Update settings config and auto delete unused connectors
This commit is contained in:
parent
dd18a57ebc
commit
87aa2f4acd
@ -1,6 +1,6 @@
|
||||
{
|
||||
"customComponents": {
|
||||
"editForm": ["general", "advanced"],
|
||||
"editForm": ["application", "advanced"],
|
||||
"list": ["languages"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"menu.section.global-settings": "Global settings",
|
||||
"menu.item.general": "General",
|
||||
"menu.item.application": "Application",
|
||||
"menu.item.languages": "Languages",
|
||||
"menu.item.advanced": "Advanced",
|
||||
|
||||
@ -33,12 +33,12 @@
|
||||
"form.database.item.provider.sqlite3": "SQlite3",
|
||||
"form.database.item.provider.redis": "Redis",
|
||||
|
||||
"form.general.name": "General",
|
||||
"form.general.description": "Configure your general settings.",
|
||||
"form.application.name": "Application",
|
||||
"form.application.description": "Configure your application settings.",
|
||||
|
||||
"form.general.item.name": "Name",
|
||||
"form.general.item.description": "Description",
|
||||
"form.general.item.version": "Version",
|
||||
"form.application.item.name": "Name",
|
||||
"form.application.item.description": "Description",
|
||||
"form.application.item.version": "Version",
|
||||
|
||||
"form.advanced.name": "Advanced",
|
||||
"form.advanced.description": "Configure your advanced settings.",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"menu.section.global-settings": "Configuration général",
|
||||
"menu.item.general": "Général",
|
||||
"menu.item.application": "Application",
|
||||
"menu.item.languages": "Langues",
|
||||
"menu.item.advanced": "Avancé",
|
||||
|
||||
@ -33,12 +33,12 @@
|
||||
"form.database.item.provider.sqlite3": "SQlite3",
|
||||
"form.database.item.provider.redis": "Redis",
|
||||
|
||||
"form.general.name": "Général",
|
||||
"form.general.description": "Modification des configurations général.",
|
||||
"form.application.name": "Application",
|
||||
"form.application.description": "Modification des configurations de l'application.",
|
||||
|
||||
"form.general.item.name": "Nom",
|
||||
"form.general.item.description": "Description",
|
||||
"form.general.item.version": "Version",
|
||||
"form.application.item.name": "Nom",
|
||||
"form.application.item.description": "Description",
|
||||
"form.application.item.version": "Version",
|
||||
|
||||
"form.advanced.name": "Avancé",
|
||||
"form.advanced.description": "Modification des configurations avancé.",
|
||||
|
||||
@ -203,35 +203,44 @@ module.exports = {
|
||||
|
||||
const newName = _.get(params, `database.connections.${name}.name`);
|
||||
|
||||
const settings = _.assign(_.clone(strapi.config.environments[env].database.connections[name].settings), params.database.connections[name].settings);
|
||||
params = _.assign(_.clone(strapi.config.environments[env].database.connections[name]), params.database.connections[name]);
|
||||
params.settings = settings;
|
||||
|
||||
delete params.name;
|
||||
|
||||
const connections = _.clone(strapi.config.environments[env].database.connections);
|
||||
|
||||
if (newName && newName !== name) {
|
||||
const settings = _.assign(_.clone(strapi.config.environments[env].database.connections[name].settings), params.database.connections[name].settings);
|
||||
params = _.assign(_.clone(strapi.config.environments[env].database.connections[name]), params.database.connections[name]);
|
||||
params.settings = settings;
|
||||
|
||||
delete params.name;
|
||||
|
||||
const connections = _.clone(strapi.config.environments[env].database.connections);
|
||||
connections[newName] = params;
|
||||
connections[name] = undefined;
|
||||
|
||||
params = { database: { connections }};
|
||||
|
||||
items = [{ target: 'database.connections' }];
|
||||
|
||||
if (strapi.config.environments[env].database.defaultConnection === name) {
|
||||
params.database.defaultConnection = newName;
|
||||
items.push({
|
||||
target: 'database.defaultConnection'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
connections[name] = params;
|
||||
}
|
||||
|
||||
params = { database: { connections }};
|
||||
|
||||
items = [{ target: 'database.connections' }];
|
||||
|
||||
const newClient = _.get(params, `database.connections.${name}.settings.client`);
|
||||
|
||||
if (newClient) params.database.connections[name].connector = Service.getClientConnector(newClient);
|
||||
|
||||
strapi.reload.isWatching = false;
|
||||
|
||||
const cleanErrors = Service.cleanDependency(env, params);
|
||||
|
||||
if (!_.isEmpty(cleanErrors)) {
|
||||
return ctx.badRequest(null, Service.formatErrors(cleanErrors));
|
||||
}
|
||||
|
||||
Service.installDependency(params, name);
|
||||
|
||||
const updateErrors = Service.updateSettings(params, items, env);
|
||||
|
||||
@ -12,8 +12,8 @@ module.exports = {
|
||||
name: 'menu.section.global-settings',
|
||||
items: [
|
||||
{
|
||||
slug: 'general',
|
||||
name: 'menu.item.general',
|
||||
slug: 'application',
|
||||
name: 'menu.item.application',
|
||||
icon: 'globe'
|
||||
},
|
||||
{
|
||||
@ -61,15 +61,15 @@ module.exports = {
|
||||
]
|
||||
},
|
||||
|
||||
general: () => ({
|
||||
name: 'form.general.name',
|
||||
description: 'form.general.description',
|
||||
application: () => ({
|
||||
name: 'form.application.name',
|
||||
description: 'form.application.description',
|
||||
sections: [
|
||||
{
|
||||
name: '',
|
||||
items: [
|
||||
{
|
||||
name: 'form.general.item.name',
|
||||
name: 'form.application.item.name',
|
||||
target: 'application.name',
|
||||
type: 'string',
|
||||
value: _.get(strapi.config, 'name', null),
|
||||
@ -79,7 +79,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'form.general.item.description',
|
||||
name: 'form.application.item.description',
|
||||
target: 'application.description',
|
||||
type: 'string',
|
||||
value: _.get(strapi.config, 'description', null),
|
||||
@ -89,7 +89,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'form.general.item.version',
|
||||
name: 'form.application.item.version',
|
||||
target: 'package.version',
|
||||
type: 'string',
|
||||
value: _.get(strapi.config, 'info.version', null),
|
||||
@ -560,9 +560,7 @@ module.exports = {
|
||||
target: `database.connections.${name}.settings.username`,
|
||||
type: 'string',
|
||||
value: _.get(strapi.config, `environments.${env}.database.connections.${name}.settings.username`, null),
|
||||
validations: {
|
||||
required: true
|
||||
}
|
||||
validations: {}
|
||||
},
|
||||
{
|
||||
name: 'form.database.item.password',
|
||||
@ -863,5 +861,62 @@ module.exports = {
|
||||
const installed = _.indexOf(_.keys(strapi.config.info.dependencies), connector) !== -1;
|
||||
|
||||
if (connector && !installed) exec(`npm install ${connector}@alpha`);
|
||||
},
|
||||
|
||||
cleanDependency: (env, config) => {
|
||||
const availableConnectors = ['strapi-mongoose', 'strapi-bookshelf', 'strapi-redis'];
|
||||
let usedConnectors = [];
|
||||
const errors = [];
|
||||
|
||||
_.forEach(_.keys(strapi.config.environments), environment => {
|
||||
let connections = strapi.config.environments[environment].database.connections;
|
||||
|
||||
if (environment === env) {
|
||||
connections = config.database.connections;
|
||||
}
|
||||
|
||||
_.forEach(connections, connection => {
|
||||
usedConnectors.push(connection.connector);
|
||||
});
|
||||
});
|
||||
|
||||
usedConnectors = _.uniq(usedConnectors);
|
||||
|
||||
_.forEach(availableConnectors, connector => {
|
||||
const installed = _.indexOf(_.keys(strapi.config.info.dependencies), connector) !== -1;
|
||||
const used = _.indexOf(usedConnectors, connector) !== -1;
|
||||
|
||||
if (installed && !used) {
|
||||
const filePath = path.join(strapi.config.appPath, 'package.json');
|
||||
|
||||
try {
|
||||
const fileContent = require(filePath);
|
||||
|
||||
_.set(fileContent, `dependencies.${connector}`, undefined);
|
||||
|
||||
try {
|
||||
fs.writeFileSync(filePath, JSON.stringify(fileContent, null, 2), 'utf8');
|
||||
} catch (e) {
|
||||
errors.push({
|
||||
target,
|
||||
message: 'request.error.config',
|
||||
params: {
|
||||
filePath: filePath
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
errors.push({
|
||||
target,
|
||||
message: 'request.error.config',
|
||||
params: {
|
||||
filePath: filePath
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return errors;
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user