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

Page order by header sorts integers different on webserver than on localhost #3167

Closed
NicoHood opened this issue Jan 21, 2021 · 8 comments
Closed
Assignees

Comments

@NicoHood
Copy link
Contributor

I have multiple pages with headers like footer: 10. I am generating an ordered list of this pages as footer.

{% set footer_pages = page.collection({'items': '@root.descendants', 'order': {'by': 'header.footer'}})|filter(x => x.header.footer == true) %}
{% if footer_pages|length %}
  <ul class="footer-list">
    {% for p in footer_pages %}
      {% set active_page = (p.active) ? 'active' : '' %}
      <li>
        <a href="{{ p.url }}" class="{{ active_page }}">
          {{p.header.footer}}{{ p.menu }}
        </a>
      </li>
    {% endfor %}
  </ul>

On localhost:
grafik

On Server:
grafik

It looks like the server is sorting the integers maybe via string compare rather than normal int compare. Both run php 7.4, but the server uses apache, while on localhost I am running via php -S 0.0.0.0:8000 system/router.php.

Do you have any hint why this could happen?

@mahagr
Copy link
Member

mahagr commented Jan 26, 2021

Looks like the first ordering is using natural ordering and the second is using character-by-character ordering. Look at the last method in system/src/Grav/Common/Page/Pages.php

@NicoHood
Copy link
Contributor Author

NicoHood commented Jan 26, 2021

Localhost uses:
https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Page/Pages.php#L1979

Server uses (Collator::SORT_STRING):
https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Page/Pages.php#L1974

It seems extension_loaded('intl') is not loaded locally. Now from the admin panel this seems to be not a required dependency, however the sort seems wrong with the extension anyways.

I guess there is something wrong with the implementation: array_shift($list_vals) contains the following and is (of course) always not numeric:

/var/www/vhosts/hosting00000000000000000000000000123456.a123eee0000000000000000000000123456.netcup.net/httpdocs/test.mydomain.de/user/pages/00000000000000000000000000000001.home

@mahagr
Copy link
Member

mahagr commented Jan 29, 2021

@NicoHood Try setting collator up: $col->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON);

@mahagr mahagr self-assigned this Jan 29, 2021
@NicoHood
Copy link
Contributor Author

That works!

@mahagr
Copy link
Member

mahagr commented Feb 1, 2021

Let me fix that.

@NicoHood
Copy link
Contributor Author

NicoHood commented Feb 1, 2021

Thanks, nice!

And the other options are not affected? To me it looks like numeric sorting is now always applied. I have no knowledge about that at all, so I might be wrong. Also I am wondering why the full path (see post above) is used for sorting, is that correct?

@mahagr
Copy link
Member

mahagr commented Feb 1, 2021

It is what is applied to normal search, too. Basically, it just sorts numbers as 1 < 10 < 100 < 1000, otherwise it works like normal sort.

@NicoHood
Copy link
Contributor Author

NicoHood commented Feb 1, 2021

Guess this can be closed then

@NicoHood NicoHood closed this as completed Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants