Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Community Bugfix: Updating localization for an existing entry fails #34

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading