Skip to content

Commit 6f1ca00

Browse files
committed
fix: resolve relations for non-translated documents
1 parent b532792 commit 6f1ca00

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

packages/core/server/middlewares/generate-url-alias.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ const generateUrlAliasMiddleware: Modules.Documents.Middleware.Middleware = asyn
2121

2222
// Fetch the URL pattern for this content type.
2323
let relations: string[] = [];
24-
let languages: string[] = [undefined];
2524
let urlAliasEntity: Data.ContentType<'plugin::webtools.url-alias'> | undefined;
2625

27-
languages = [];
28-
const locales = await strapi.entityService.findMany('plugin::i18n.locale', {});
29-
languages = locales.map((locale) => locale.code);
26+
let languages: (string | undefined)[] = [undefined];
27+
if (params.locale) {
28+
const locales = await strapi.entityService.findMany('plugin::i18n.locale', {});
29+
languages = locales.map((locale) => locale.code);
30+
}
3031

3132
await Promise.all(languages.map(async (lang) => {
3233
const urlPatterns = await getPluginService('url-pattern').findByUid(uid, lang);

packages/core/server/services/bulk-generate.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,12 @@ const generateUrlAliases = async (params: GenerateParams): Promise<number> => {
3636

3737
let relations: string[] = [];
3838

39-
const locales = await strapi.documents('plugin::i18n.locale').findMany({});
40-
const languages = locales.map((locale) => locale.code);
41-
42-
// Get all relations for the type
43-
await Promise.all(languages.map(async (lang) => {
44-
const urlPatterns = await getPluginService('url-pattern').findByUid(type, lang);
45-
urlPatterns.forEach((urlPattern) => {
46-
const languageRelations = getPluginService('url-pattern').getRelationsFromPattern(urlPattern);
47-
relations = [...relations, ...languageRelations];
48-
});
49-
}));
39+
// Get all relations for the type from all patterns for all languages.
40+
const urlPatterns = await getPluginService('url-pattern').findByUid(type);
41+
urlPatterns.forEach((urlPattern) => {
42+
const languageRelations = getPluginService('url-pattern').getRelationsFromPattern(urlPattern);
43+
relations = [...relations, ...languageRelations];
44+
});
5045

5146
// Query all the entities of the type that do not have a corresponding URL alias.
5247
const entities = await strapi.documents(type as 'api::test.test').findMany({
@@ -70,9 +65,10 @@ const generateUrlAliases = async (params: GenerateParams): Promise<number> => {
7065
*/
7166
// eslint-disable-next-line no-restricted-syntax
7267
for (const entity of entities) {
68+
// FIXME: just filter the `urlPatterns` we already have.
7369
// eslint-disable-next-line no-await-in-loop
74-
const urlPatterns = await getPluginService('url-pattern').findByUid(type, entity.locale);
75-
const resolvedPath = getPluginService('url-pattern').resolvePattern(type, entity, urlPatterns[0]);
70+
const entityUrlPatterns = await getPluginService('url-pattern').findByUid(type, entity.locale);
71+
const resolvedPath = getPluginService('url-pattern').resolvePattern(type, entity, entityUrlPatterns[0]);
7672

7773
// eslint-disable-next-line no-await-in-loop
7874
const newUrlAlias = await strapi.documents('plugin::webtools.url-alias').create({

0 commit comments

Comments
 (0)