From 042618fe930a3b3bc563b65347d99efd46c39cc8 Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 15 Nov 2021 19:37:49 +0400 Subject: [PATCH] Fixed failing tests refs https://github.com/TryGhost/Ghost/commit/5a62253466eace5624a37a4685c9b367416f63b9 - The UrlService was relying on a "hidden" identifier field that was passed along with a router object. Now it's passed as an explicit parameter from the "frontend" to the backend's UrlService --- core/frontend/services/routing/router-manager.js | 9 +++++++-- core/server/services/url/UrlGenerator.js | 4 +++- core/server/services/url/UrlService.js | 12 +++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/frontend/services/routing/router-manager.js b/core/frontend/services/routing/router-manager.js index 2af965a73f..ab8bebd28c 100644 --- a/core/frontend/services/routing/router-manager.js +++ b/core/frontend/services/routing/router-manager.js @@ -43,7 +43,12 @@ class RouterManager { return; } - this.urlService.onRouterAddedType(router.filter, router.getResourceType(), router.getPermalinks().getValue()); + this.urlService.onRouterAddedType( + router.identifier, + router.filter, + router.getResourceType(), + router.getPermalinks().getValue() + ); } /** @@ -179,7 +184,7 @@ class RouterManager { if (collectionRouter.getPermalinks().getValue().match(/:year|:month|:day/)) { debug('handleTimezoneEdit: trigger regeneration'); - this.urlService.onRouterUpdated(collectionRouter); + this.urlService.onRouterUpdated(collectionRouter.identifier); } } } diff --git a/core/server/services/url/UrlGenerator.js b/core/server/services/url/UrlGenerator.js index c57ee936b1..75de6737b6 100644 --- a/core/server/services/url/UrlGenerator.js +++ b/core/server/services/url/UrlGenerator.js @@ -35,6 +35,7 @@ const EXPANSIONS = [{ class UrlGenerator { /** * @param {Object} options + * @param {String} options.identifier frontend router ID reference * @param {String} options.filter NQL filter string * @param {String} options.resourceType resource type (e.g. 'posts', 'tags') * @param {String} options.permalink permalink string @@ -43,7 +44,8 @@ class UrlGenerator { * @param {Object} options.urls instance of the backend URLs (used to store the urls) * @param {Number} options.position an ID of the generator */ - constructor({filter, resourceType, permalink, queue, resources, urls, position}) { + constructor({identifier, filter, resourceType, permalink, queue, resources, urls, position}) { + this.identifier = identifier; this.resourceType = resourceType; this.permalink = permalink; this.queue = queue; diff --git a/core/server/services/url/UrlService.js b/core/server/services/url/UrlService.js index 0cee50d9e2..a7f414f4b9 100644 --- a/core/server/services/url/UrlService.js +++ b/core/server/services/url/UrlService.js @@ -81,14 +81,16 @@ class UrlService { /** * @description Router was created, connect it with a url generator. + * @param {String} identifier frontend router ID reference * @param {String} filter NQL filter * @param {String} resourceType * @param {String} permalink */ - onRouterAddedType(filter, resourceType, permalink) { + onRouterAddedType(identifier, filter, resourceType, permalink) { debug('Registering route: ', filter, resourceType, permalink); let urlGenerator = new UrlGenerator({ + identifier, filter, resourceType, permalink, @@ -102,10 +104,10 @@ class UrlService { /** * @description Router update handler - regenerates it's resources - * @param {ExpressRouter} router + * @param {String} identifier router ID linked to the UrlGenerator */ - onRouterUpdated(router) { - const generator = this.urlGenerators.find(g => g.router.id === router.id); + onRouterUpdated(identifier) { + const generator = this.urlGenerators.find(g => g.identifier === identifier); generator.regenerateResources(); } @@ -264,7 +266,7 @@ class UrlService { let urlGenerator; this.urlGenerators.every((_urlGenerator) => { - if (_urlGenerator.router.identifier === routerId) { + if (_urlGenerator.identifier === routerId) { urlGenerator = _urlGenerator; return false; }