Skip to content
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

Merged
merged 1 commit into from Mar 8, 2019

Conversation

moshenskyDV
Copy link
Contributor

@moshenskyDV moshenskyDV commented Jun 11, 2018

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.

@greg0ire greg0ire added the patch label Jun 11, 2018
@moshenskyDV
Copy link
Contributor Author

Wait pls, forgot to check lint.

]);
}
}
$root = ($root) ? $root : $this->pageManager->create([
Copy link
Contributor

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?

@greg0ire
Copy link
Contributor

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?"
More on http://keepachangelog.com

@@ -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) {
Copy link
Member

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.

@moshenskyDV
Copy link
Contributor Author

Travis said, that lint issues in another files (tests). Should i fix this, or not?

* If root path available in config - create from config
* Else - generate it statically.
*
* @param SiteInterface $site
Copy link
Contributor

@greg0ire greg0ire Jun 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this phpdoc

if ('/' === $route->getPath()) {
$requirements = $route->getRequirements();
$name = trim($name);
$root = $this->pageManager->create([
Copy link
Contributor

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.

@greg0ire
Copy link
Contributor

Please remove this phpdoc

I only meant the line with @param

@moshenskyDV
Copy link
Contributor Author

Why param should be removed from PHPDoc?

@greg0ire
Copy link
Contributor

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.

@greg0ire
Copy link
Contributor

Use make cs-fix to fix the build.

@greg0ire
Copy link
Contributor

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?

  1. git rebase -i origin/3.x, assuming origin is a git remote that points to this repository, and not your fork. If you're not sure what your remotes are, run git remote -vvv, there should be your fork and the holy/reference/base/origin/whatever-you-call-it repository.
  2. A window will show up with many lines, replace pick with fixup on every line but the first one
  3. Close your editor, git should do its magic, and you should end up with one commit
  4. Use git push --force to overwrite what you already pushed. Don't forget the --force option otherwise git will try to merge both things together.

greg0ire
greg0ire previously approved these changes Jun 13, 2018
@moshenskyDV
Copy link
Contributor Author

@greg0ire Thank you for your patience and reviewing this request
Looks like squashed normally.

greg0ire
greg0ire previously approved these changes Jun 13, 2018
@greg0ire greg0ire requested review from core23 and a team June 13, 2018 21:01
Copy link
Contributor

@covex-nn covex-nn left a 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 executed sonata: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 executed sonata: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 =)

@moshenskyDV
Copy link
Contributor Author

moshenskyDV commented Jun 14, 2018

@covex-nn i tried to reproduce your comment, and i saw, that we don't check duplicating pages in config.
If we will create something like this in route config:

contact:
    resource: "@ContactBundle/Resources/config/routing.yml"
    prefix:   /contact
contact2:
    resource: "@Contact2Bundle/Resources/config/routing.yml"
    prefix:   /contact

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):

// Iterate over declared routes from the routing mechanism
        foreach ($this->router->getRouteCollection()->all() as $name => $route) {

What do you think, guys? It should to be fixed in this PR, or will better to create new PR for this?

@rande
Copy link
Member

rande commented Oct 11, 2018

@sonata-project/ekino can you review this PR ?

*
* @return object root page
*/
public function createRootPage(SiteInterface $site)
Copy link
Member

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

@moshenskyDV
Copy link
Contributor Author

Changed access modifier. Any update of this?
(I not understood what coveralls wants from me, other tests passed)

src/Route/RoutePageGenerator.php Outdated Show resolved Hide resolved
core23
core23 previously approved these changes Oct 30, 2018
core23
core23 previously approved these changes Nov 1, 2018
@OskarStark
Copy link
Member

Can you please rebase your PR?

@SonataCI
Copy link
Collaborator

Could you please rebase your PR and fix merge conflicts?

@moshenskyDV
Copy link
Contributor Author

Hi. I did. Unfortunately i have no time to test it manually.

Copy link
Contributor

@greg0ire greg0ire left a 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.

src/Route/RoutePageGenerator.php Outdated Show resolved Hide resolved
src/Route/RoutePageGenerator.php Outdated Show resolved Hide resolved
src/Route/RoutePageGenerator.php Outdated Show resolved Hide resolved
@core23 core23 requested a review from greg0ire March 7, 2019 18:12
@core23 core23 merged commit 1a291b3 into sonata-project:3.x Mar 8, 2019
@core23
Copy link
Member

core23 commented Mar 8, 2019

Thanks @moshenskyDV 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants