2021-01-04 22:01:37 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
2021-03-18 12:38:36 +01:00
|
|
|
const { PUBLISHED_AT_ATTRIBUTE } = require('strapi-utils').contentTypes.constants;
|
2021-02-17 18:30:06 +01:00
|
|
|
|
2021-02-15 11:24:28 +01:00
|
|
|
const { getService } = require('../../utils');
|
2021-02-18 18:42:28 +01:00
|
|
|
const fieldMigration = require('./migrations/field');
|
2021-01-04 22:01:37 +01:00
|
|
|
|
|
|
|
module.exports = () => {
|
2021-02-17 18:30:06 +01:00
|
|
|
const contentTypeService = getService('content-types');
|
|
|
|
const coreApiService = getService('core-api');
|
|
|
|
|
|
|
|
Object.values(strapi.contentTypes).forEach(contentType => {
|
|
|
|
if (contentTypeService.isLocalized(contentType)) {
|
|
|
|
const { attributes, modelName } = contentType;
|
|
|
|
|
|
|
|
_.set(attributes, 'localizations', {
|
2021-03-12 14:34:04 +01:00
|
|
|
writable: true,
|
2021-01-04 22:01:37 +01:00
|
|
|
private: false,
|
|
|
|
configurable: false,
|
2021-03-12 14:34:04 +01:00
|
|
|
visible: false,
|
2021-02-17 18:30:06 +01:00
|
|
|
collection: modelName,
|
2021-03-18 12:38:36 +01:00
|
|
|
populate: ['id', 'locale', PUBLISHED_AT_ATTRIBUTE],
|
2021-01-04 22:01:37 +01:00
|
|
|
});
|
|
|
|
|
2021-02-17 18:30:06 +01:00
|
|
|
_.set(attributes, 'locale', {
|
2021-03-12 14:34:04 +01:00
|
|
|
writable: true,
|
2021-01-04 22:01:37 +01:00
|
|
|
private: false,
|
|
|
|
configurable: false,
|
2021-03-12 14:34:04 +01:00
|
|
|
visible: false,
|
2021-01-04 22:01:37 +01:00
|
|
|
type: 'string',
|
|
|
|
});
|
2021-02-15 11:27:01 +01:00
|
|
|
|
2021-02-17 18:30:06 +01:00
|
|
|
coreApiService.addCreateLocalizationAction(contentType);
|
2021-01-04 22:01:37 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-18 18:42:28 +01:00
|
|
|
strapi.db.migrations.register(fieldMigration);
|
2021-01-04 22:01:37 +01:00
|
|
|
};
|