Skip to content

Commit ea5e49b

Browse files
authored
Merge pull request #187 from pluginpal/feature/fix-i18n-issue
fix: make sure the URL alias localizations are correct when using the…
2 parents 82cbcca + bcbbc3e commit ea5e49b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.changeset/eleven-schools-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pluginpal/webtools-core": patch
3+
---
4+
5+
Update all the URL alias localizations on update/create/clone in the query layer decorator

packages/core/server/admin-api/services/query-layer-decorator.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ const decorator = (service: IDecoratedService) => ({
105105
});
106106
}
107107

108+
// Update all the URL alias localizations.
109+
await Promise.all(urlAliasLocalizations.map(async (localization) => {
110+
await strapi.db.query('plugin::webtools.url-alias').update({
111+
where: {
112+
id: localization,
113+
},
114+
data: {
115+
localizations: [
116+
...(urlAliasLocalizations.filter((loc) => loc !== localization)),
117+
urlAliasEntity.id,
118+
],
119+
},
120+
});
121+
}));
122+
108123
// Eventually update the entity to include the URL alias.
109124
const dataWithUrlAlias = { ...opts.data, url_alias: urlAliasEntity.id };
110125
const updatedEntity = await service.update.call(this, uid, newEntity.id, {
@@ -216,6 +231,21 @@ const decorator = (service: IDecoratedService) => ({
216231
});
217232
}
218233

234+
// Update all the URL alias localizations.
235+
await Promise.all(urlAliasLocalizations.map(async (localization) => {
236+
await strapi.db.query('plugin::webtools.url-alias').update({
237+
where: {
238+
id: localization,
239+
},
240+
data: {
241+
localizations: [
242+
...(urlAliasLocalizations.filter((loc) => loc !== localization)),
243+
urlAliasEntity.id,
244+
],
245+
},
246+
});
247+
}));
248+
219249
// Eventually update the entity.
220250
return service.update.call(this, uid, entityId, {
221251
...opts,
@@ -322,6 +352,21 @@ const decorator = (service: IDecoratedService) => ({
322352
localizations: urlAliasLocalizations,
323353
});
324354

355+
// Update all the URL alias localizations.
356+
await Promise.all(urlAliasLocalizations.map(async (localization) => {
357+
await strapi.db.query('plugin::webtools.url-alias').update({
358+
where: {
359+
id: localization,
360+
},
361+
data: {
362+
localizations: [
363+
...(urlAliasLocalizations.filter((loc) => loc !== localization)),
364+
newUrlAlias.id,
365+
],
366+
},
367+
});
368+
}));
369+
325370
// Update the cloned entity with the new URL alias id
326371
return service.update.call(this, uid, clonedEntity.id, { data: { url_alias: newUrlAlias.id }, populate: ['url_alias'] });
327372
},

0 commit comments

Comments
 (0)