[BUGFIX] Ensure rootline order is respected detecting closest template #4391
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this pr does
When detecting the closest template inside a rootline, it is necessary, respecting the order of the rootline itself.
The current database call has a random sorting, which does not respect the ordering, therefore, could return a wrong dataset if multiple templates are given in the root line.
To ensure the order is respected, every page inside rootline is called single against the database and returns the pid if a template record exists.
How to test
Given a rootline with multiple siteroots, the database query does not respect the order of the elements and only returns the first hit form the database, which could be the right looked up, but not has to be.
Example build:
The system calls with the rootline:
And the database always returns
271as the found pid, which is wrong.Fixes: #4012