Skip to content

Commit

Permalink
Community Bugfix: Updating localization for an existing entry fails (#34
Browse files Browse the repository at this point in the history
)

* WIP: patch to fix DZ issue with Localazy working but not yet ready to publish

* Proposed path to fix download errors of Localazy translations

---------

Co-authored-by: emanuelec-dacoco <emanuelec@dacoco.io>
  • Loading branch information
david-vaclavek and emanuelec-dacoco authored Sep 6, 2023
1 parent 4607c20 commit ef416e3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server/services/strapi-i18n-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down Expand Up @@ -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 <emanuele.c@dacoco.io>:
// 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,
Expand Down

0 comments on commit ef416e3

Please sign in to comment.