Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Pagination - Pagination for Default Language Shown Regardless of Current Language

Status Resolved
Add-on / Version Publisher 1.6.1
Severity Critical
EE Version 2.9.2

Nick Benson

Mar 03, 2015

We’re encountering an issue where pagination generated by and are showing the page counts for the primary language, rather than the current language.

For example, on a simple category index page, there might be 30 entries in English (default language) but only 2 in French. Both the English and French indexes will show pagination as if there were 30 entries.

Thoughts, any?

Structure 3.3.14.7 is also being used, if that’s of any help in your diagnostic process - everything’s up to date, I believe.

#1

BoldMinded (Brian)

Haven’t encountered this one yet, but I’ll be able to look into it early next week.

#2

BoldMinded (Brian)

Can you be more specific? Are the pagination links correct and the total count is incorrect? Is the results tag inside of the entries tag? Are both tags showing incorrect counts or just low_search? Can you attach examples of template code you are using and screenshots of output?

#3

Nick Benson

I attached an image, which I believe you can see.

Template is as follows:

{exp:channel:entries channel="resources" status="open" limit="5" paginate="bottom" dynamic="no"}
 <a href="http://{page_ur}">{title}</a>

    {paginate}
        Page {current_page} of {total_pages} pages {pagination_links}
    {/paginate}
{/exp:channel:entries}

In this case, there are ~1850 entries in English, 2 in French, and 0 in German. In all three languages, the “Last Page” link goes to …/P370.

In each case, the “last” link goes to …/P370/

#4

BoldMinded (Brian)

Can you do me a favor and go into the models/publisher_entry.php file, around line 1240. You’ll see a conditional where it tries to modify the query for pagination… just add a var_dump in there somewhere to see if the $sql = str_replace() function is getting called or not.

#5

BoldMinded (Brian)

It sounds like you have Entry Persistence on, in which case it will not try to alter the count b/c if you are viewing a secondary language, it will still show the entries from the default language. Try turning off that setting to see if the results are different.

#6

BoldMinded (Brian)

I did some more testing last night and there is definitely something wrong with the pagination. I 99.9% sure this was working some time ago, so not sure what the issue is. I’ll dig into it more this weekend or early next week.

#7

Nick Benson

Excellent, appreciate you taking a look.

We initially had persistence turned on, but, all three settings for it have been set to “No” for quite some time now (several months); not sure if that’s pertinent or not.

The pagination function in models/publisher_entry.php starts at line 1408 in the latest version of Publisher that’s on Devot:ee, if that’s noteworthy; in any event, it looks like it’s doing what it supposed to do, I think…

Modified with a pair of var_dumps:

public function get_pagination_entries(Channel $channel)
    {
        // Get the queries and reverse the list so it does fewer loops.
        $current_queries = array_reverse(ee()->db->queries);
        $entry_ids = array();
        $limit = 100;
        $offset = 0;
        $count = 0;
        $limit_sql = '';

        foreach ($current_queries as $query)
        {
            if (
                (strpos($query, 'SELECT t.entry_id FROM '. ee()->db->dbprefix . 'channel_titles AS t') !== FALSE) ||
                (strpos($query, 'SELECT DISTINCT(t.entry_id) FROM '. ee()->db->dbprefix .'channel_titles AS t') !== FALSE)
            ){

                var_dump($query);

                // Modify the query and use the offset and limit to grab the current
                // subset of results for the current page.
                $sql = str_replace(
                    'WHERE',
                    'LEFT JOIN exp_publisher_titles AS pt ON pt.entry_id = t.entry_id
                        WHERE pt.publisher_lang_id = '.ee()->publisher_lib->lang_id .'
                        AND pt.publisher_status = "'.ee()->publisher_lib->status .'" AND ',
                    $query
                );

                var_dump($sql);

                // Find our new set of entry_ids with original offset and limit
                $qry = ee()->db->query($sql);

                foreach ($qry->result_array() as $row)
                {
                    $entry_ids[] = $row['entry_id'];
                }

                // Remove the offset and limit so we can grab the count
                // and update the pagination class.
                $sql = preg_replace('/LIMIT [0-9,\s]+$/', '', $sql);

                $qry = ee()->db->query($sql);
                $count = $qry->num_rows();

                // Exit the loop, found what we need.
                break;
            }
        }[/code]

English:

[code]string(523) "SELECT t.entry_id FROM exp_channel_titles AS t
    LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date <  425658339  AND (t.expirati OR t.expiration_date > 1425658339) AND t.channel_id IN (9) AND t.status = 'open' AND t.status != 'closed' ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 5
#APP/modules/channel/mod.channel.php L:277  Channel::build_sql_query() "

string(699) "SELECT t.entry_id FROM exp_channel_titles AS t
    LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id LEFT JOIN exp_publisher_titles AS pt ON pt.entry_id = t.entry_id
                        WHERE pt.publisher_lang_id = 1
                        AND pt.publisher_status = "open" AND  t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date <  425658339  AND (t.expirati OR t.expiration_date > 1425658339) AND t.channel_id IN (9) AND t.status = 'open' AND t.status != 'closed' ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 5
#APP/modules/channel/mod.channel.php L:277  Channel::build_sql_query() "

French:

string(523) "SELECT t.entry_id FROM exp_channel_titles AS t
    LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date <  425658406  AND (t.expirati OR t.expiration_date > 1425658406) AND t.channel_id IN (9) AND t.status = 'open' AND t.status != 'closed' ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 5
#APP/modules/channel/mod.channel.php L:277  Channel::build_sql_query() "

string(699) "SELECT t.entry_id FROM exp_channel_titles AS t
    LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id LEFT JOIN exp_publisher_titles AS pt ON pt.entry_id = t.entry_id
                        WHERE pt.publisher_lang_id = 2
                        AND pt.publisher_status = "open" AND  t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date <  425658406  AND (t.expirati OR t.expiration_date > 1425658406) AND t.channel_id IN (9) AND t.status = 'open' AND t.status != 'closed' ORDER BY t.sticky desc, t.entry_date desc, t.entry_id desc LIMIT 0, 5
#APP/modules/channel/mod.channel.php L:277  Channel::build_sql_query() "
#8

BoldMinded (Brian)

Fixed, new build emailed.

#9

Nick Benson

Excellent!

  • More than one page of results in current language: check
  • One page of results in current language: check
  • Zero results in current language: fail

In this instance, there are no results in German, but, it displays the pagination as if there were as many entries as the primary language (same behavior as before the bug fix, I think), output as is follows:

“Page 1 of 0 pages 1 2 3 > Letzte ยป”

I imagine I can work around this with a conditional, probably, but, still worth looking at at some point, I think, maybe?

Thanks again!

#10

BoldMinded (Brian)

Nick, find line 1492 of models/publisher_entry.php and change it to <= 1 instead of == 1, e.g. https://www.dropbox.com/s/04o59z1sywh89lh/Screenshot 2015-03-09 22.16.07.png?dl=0

#11

Nick Benson

Excellent! Resolved, insofar as I’m concerned, thank you!

Login to reply