diff --git a/server/services/strapi-i18n-service.js b/server/services/strapi-i18n-service.js index ec8a0ea..ee300d1 100644 --- a/server/services/strapi-i18n-service.js +++ b/server/services/strapi-i18n-service.js @@ -5,6 +5,7 @@ const intlDisplayName = require("../utils/intl-display-name.js"); const merge = require("lodash/merge"); const cloneDeep = require("lodash/cloneDeep"); const omitDeep = require("../utils/omit-deep.js"); +const { forEach, map, find } = require("lodash") module.exports = ({ strapi }) => ({ async getLocales(ctx = {}) { @@ -115,9 +116,28 @@ module.exports = ({ strapi }) => ({ }, async updateLocalizationForAnExistingEntry(uid, updateEntryId, data) { try { + const StrapiService = strapi.plugin("localazy").service("strapiService"); + const strapiContentTypesModels = await StrapiService.getModels(); const populate = await StrapiService.getPopulateObject(uid); + // Bugfix by : + // Prevents IDs to be appended when updating a localized entry. When IDs are present + // Strapi attempts to update a not yet existent ID into the DB + if(strapiContentTypesModels) { + const filtered = find(strapiContentTypesModels, (model) => model.uid === uid) + if(filtered?.attributes) { + for(let attribute in filtered.attributes) { + if(filtered.attributes[attribute]?.type === 'dynamiczone') { + if(!populate[attribute] || populate[attribute] !== 'deep') { + populate[attribute] = 'deep' + } + forEach(data[attribute], (prop) => { if(prop?.id) delete prop.id}) + } + } + } + } + const updatedEntry = await strapi.entityService.update( uid, updateEntryId,