New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#590 duplicate root route when it in config #992
Conversation
Wait pls, forgot to check lint. |
src/Route/RoutePageGenerator.php
Outdated
]); | ||
} | ||
} | ||
$root = ($root) ? $root : $this->pageManager->create([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the parenthesis? Also $root ?: $this->pageManager->create([…
should be equivalent, right?
Please write a changelog directed at end users. Keep in mind that they probably do not care what file or class you changed, but what features you provided / what bugs you fixed. Try to answer the question "What benefit do I get from upgrading?" |
src/Route/RoutePageGenerator.php
Outdated
@@ -89,7 +89,22 @@ public function update(SiteInterface $site, OutputInterface $output = null, $cle | |||
|
|||
// no root url for the given website, create one | |||
if (!$root) { | |||
$root = $this->pageManager->create([ | |||
// first search for a route | |||
foreach ($this->router->getRouteCollection()->all() as $name => $route) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please create a separate method for this.
Travis said, that lint issues in another files (tests). Should i fix this, or not? |
src/Route/RoutePageGenerator.php
Outdated
* If root path available in config - create from config | ||
* Else - generate it statically. | ||
* | ||
* @param SiteInterface $site |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this phpdoc
src/Route/RoutePageGenerator.php
Outdated
if ('/' === $route->getPath()) { | ||
$requirements = $route->getRequirements(); | ||
$name = trim($name); | ||
$root = $this->pageManager->create([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return here directly? This would make the rest of the code less complex.
I only meant the line with |
Why param should be removed from PHPDoc? |
What information does it bring? None. It's just noise, and we want people to read our comments, not ignore them because 90% of them are tautologic. |
Use |
Please kindly squash your commits together. If you don't, we'll try to remember to do it for you but it's best if you save us this trouble. How to do that?
|
@greg0ire Thank you for your patience and reviewing this request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested:
- first, i created a Controller with one action, available on "/" route; then i created a site, then executed
bin/console sonata:page:update-core-routes --site=all
- in pages tree view a controller action became a root for all other pages. so, everything is good here
- then i updated controller action annotation from
@Route(path="/")
to@Route(path="/test")
and executedsonata:page:update-core-routes
again - in pages tree view a path to controller action was updated to "/test", no Homepage route created
- i cleared a cache and executed
sonata:page:update-core-routes
again, a new Homepage page appeared, controller action became a child page for Homepage - then i updated controller action annotation from
@Route(path="/test")
to@Route(path="/")
, cleared cache and executedsonata:page:update-core-routes
again - from this moment two pages have Url === '/', and this cannot be solved easily
After i added controller action with "/" route into existing project with Homepage page, two pages with '/' route have '/' as Url to. I could not update a page-for-controller-action (there was a error about Url), and when i deleted Homepage, all pages were deleted too =)
@covex-nn i tried to reproduce your comment, and i saw, that we don't check duplicating pages in config.
System will create 2 pages with same route, and we can not edit any of this page in admin panel (we will see error about already used URL). So I think - we need to add check in this file for routes duplicates inside this loop (RoutePageGenerator.php):
What do you think, guys? It should to be fixed in this PR, or will better to create new PR for this? |
@sonata-project/ekino can you review this PR ? |
src/Route/RoutePageGenerator.php
Outdated
* | ||
* @return object root page | ||
*/ | ||
public function createRootPage(SiteInterface $site) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private or at least final
ea9fd8a
to
cddc340
Compare
Changed access modifier. Any update of this? |
Can you please rebase your PR? |
Could you please rebase your PR and fix merge conflicts? |
a385ce6
to
5f8e133
Compare
Hi. I did. Unfortunately i have no time to test it manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just dropped php < 7.1, you can use type hints now.
Thanks @moshenskyDV 👍 |
I am targeting this branch, because its patch.
Closes #590
Code is not my idea, thank @grimpows
Changelog
Updated RoutePageGenerator. Now, homepage creates statically, and it stay as root page for another config pages by default. If we will create in config page with root path ("/") - they same as other will child page (it means it will available by two slashes path ("example.com//").
This patch, before creating homepage looks in config page and search any page with root path. If it will found - we will use that config page as root.
So, after patch, possible configure bundle for homepage in routing file.
Fixed
Creating homepage from router config (check if page available in config - we will not create default Homepage.
Security
I checked this on my project. Looks good. Checked generating new routes and update previously routes.
Please double check this code.