Skip to content

Commit

Permalink
Merge pull request #187 from pluginpal/feature/fix-i18n-issue
Browse files Browse the repository at this point in the history
fix: make sure the URL alias localizations are correct when using the…
  • Loading branch information
boazpoolman authored Sep 1, 2024
2 parents 82cbcca + bcbbc3e commit ea5e49b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-schools-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pluginpal/webtools-core": patch
---

Update all the URL alias localizations on update/create/clone in the query layer decorator
45 changes: 45 additions & 0 deletions packages/core/server/admin-api/services/query-layer-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ const decorator = (service: IDecoratedService) => ({
});
}

// Update all the URL alias localizations.
await Promise.all(urlAliasLocalizations.map(async (localization) => {
await strapi.db.query('plugin::webtools.url-alias').update({
where: {
id: localization,
},
data: {
localizations: [
...(urlAliasLocalizations.filter((loc) => loc !== localization)),
urlAliasEntity.id,
],
},
});
}));

// Eventually update the entity to include the URL alias.
const dataWithUrlAlias = { ...opts.data, url_alias: urlAliasEntity.id };
const updatedEntity = await service.update.call(this, uid, newEntity.id, {
Expand Down Expand Up @@ -216,6 +231,21 @@ const decorator = (service: IDecoratedService) => ({
});
}

// Update all the URL alias localizations.
await Promise.all(urlAliasLocalizations.map(async (localization) => {
await strapi.db.query('plugin::webtools.url-alias').update({
where: {
id: localization,
},
data: {
localizations: [
...(urlAliasLocalizations.filter((loc) => loc !== localization)),
urlAliasEntity.id,
],
},
});
}));

// Eventually update the entity.
return service.update.call(this, uid, entityId, {
...opts,
Expand Down Expand Up @@ -322,6 +352,21 @@ const decorator = (service: IDecoratedService) => ({
localizations: urlAliasLocalizations,
});

// Update all the URL alias localizations.
await Promise.all(urlAliasLocalizations.map(async (localization) => {
await strapi.db.query('plugin::webtools.url-alias').update({
where: {
id: localization,
},
data: {
localizations: [
...(urlAliasLocalizations.filter((loc) => loc !== localization)),
newUrlAlias.id,
],
},
});
}));

// Update the cloned entity with the new URL alias id
return service.update.call(this, uid, clonedEntity.id, { data: { url_alias: newUrlAlias.id }, populate: ['url_alias'] });
},
Expand Down

0 comments on commit ea5e49b

Please sign in to comment.