Issue #1958470 by olli | yuriy.babenko: Fixed Division by zero in pager_default_initialize().
parent
ba3423f534
commit
f24e7123e6
|
@ -57,7 +57,7 @@ class Mini extends SqlBase {
|
||||||
|
|
||||||
// Don't query for the next page if we have a pager that has a limited
|
// Don't query for the next page if we have a pager that has a limited
|
||||||
// amount of pages.
|
// amount of pages.
|
||||||
if (empty($this->options['total_pages']) || ($this->getCurrentPage() < $this->options['total_pages'])) {
|
if ($this->getItemsPerPage() > 0 && (empty($this->options['total_pages']) || ($this->getCurrentPage() < $this->options['total_pages']))) {
|
||||||
// Increase the items in the query in order to be able to find out whether
|
// Increase the items in the query in order to be able to find out whether
|
||||||
// there is another page.
|
// there is another page.
|
||||||
$limit = $this->view->query->getLimit();
|
$limit = $this->view->query->getLimit();
|
||||||
|
@ -79,7 +79,7 @@ class Mini extends SqlBase {
|
||||||
public function postExecute(&$result) {
|
public function postExecute(&$result) {
|
||||||
// In query() one more item might have been retrieved than necessary. If so,
|
// In query() one more item might have been retrieved than necessary. If so,
|
||||||
// the next link needs to be displayed and the item removed.
|
// the next link needs to be displayed and the item removed.
|
||||||
if (count($result) > $this->getItemsPerPage()) {
|
if ($this->getItemsPerPage() > 0 && count($result) > $this->getItemsPerPage()) {
|
||||||
array_pop($result);
|
array_pop($result);
|
||||||
// Make sure the pager shows the next link by setting the total items to
|
// Make sure the pager shows the next link by setting the total items to
|
||||||
// the biggest possible number but prevent failing calculations like
|
// the biggest possible number but prevent failing calculations like
|
||||||
|
@ -89,7 +89,7 @@ class Mini extends SqlBase {
|
||||||
else {
|
else {
|
||||||
$total = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
|
$total = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
|
||||||
}
|
}
|
||||||
pager_default_initialize($total, $this->getItemsPerPage(), $this->options['id']);
|
$this->total_items = $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -183,13 +183,12 @@ abstract class PagerPluginBase extends PluginBase {
|
||||||
$this->total_items -= $this->options['offset'];
|
$this->total_items -= $this->options['offset'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->updatePageInfo();
|
|
||||||
return $this->total_items;
|
return $this->total_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If there are pagers that need global values set, this method can
|
* If there are pagers that need global values set, this method can
|
||||||
* be used to set them. It will be called when the count query is run.
|
* be used to set them. It will be called after the query is run.
|
||||||
*/
|
*/
|
||||||
public function updatePageInfo() {
|
public function updatePageInfo() {
|
||||||
|
|
||||||
|
|
|
@ -1431,9 +1431,8 @@ class Sql extends QueryPluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
$view->pager->postExecute($view->result);
|
$view->pager->postExecute($view->result);
|
||||||
if ($view->pager->useCountQuery() || !empty($view->get_total_rows)) {
|
$view->pager->updatePageInfo();
|
||||||
$view->total_rows = $view->pager->getTotalItems();
|
$view->total_rows = $view->pager->getTotalItems();
|
||||||
}
|
|
||||||
|
|
||||||
// Load all entities contained in the results.
|
// Load all entities contained in the results.
|
||||||
$this->loadEntities($view->result);
|
$this->loadEntities($view->result);
|
||||||
|
|
|
@ -91,6 +91,13 @@ class MiniPagerTest extends PluginTestBase {
|
||||||
$this->assertText('‹‹');
|
$this->assertText('‹‹');
|
||||||
$this->assertText($this->nodes[19]->label());
|
$this->assertText($this->nodes[19]->label());
|
||||||
|
|
||||||
|
$this->drupalGet('test_mini_pager_all');
|
||||||
|
$this->assertNoText('‹‹ test', 'The previous link does not appear on the page.');
|
||||||
|
$this->assertText('Page 1', 'The current page info shows the only page.');
|
||||||
|
$this->assertNoText('test ››', 'The next link does not appear on the page.');
|
||||||
|
$result = $this->xpath('//div[contains(@class, "views-row")]');
|
||||||
|
$this->assertEqual(count($result), count($this->nodes), 'All rows appear on the page.');
|
||||||
|
|
||||||
// Remove all items beside 1, so there should be no links shown.
|
// Remove all items beside 1, so there should be no links shown.
|
||||||
for ($i = 0; $i < 19; $i++) {
|
for ($i = 0; $i < 19; $i++) {
|
||||||
$this->nodes[$i]->delete();
|
$this->nodes[$i]->delete();
|
||||||
|
@ -105,7 +112,7 @@ class MiniPagerTest extends PluginTestBase {
|
||||||
$view = views_get_view('test_mini_pager');
|
$view = views_get_view('test_mini_pager');
|
||||||
$this->executeView($view);
|
$this->executeView($view);
|
||||||
$this->assertIdentical($view->get_total_rows, NULL, 'The query was not forced to calculate the total number of results.');
|
$this->assertIdentical($view->get_total_rows, NULL, 'The query was not forced to calculate the total number of results.');
|
||||||
$this->assertIdentical($view->total_rows, NULL, 'The query did not return the total number of rows.');
|
$this->assertIdentical($view->total_rows, 1, 'The pager calculated the total number of rows.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,19 @@ display:
|
||||||
type: mini
|
type: mini
|
||||||
options:
|
options:
|
||||||
items_per_page: '1'
|
items_per_page: '1'
|
||||||
|
page_3:
|
||||||
|
display_plugin: page
|
||||||
|
id: page_3
|
||||||
|
display_title: Page
|
||||||
|
position: ''
|
||||||
|
display_options:
|
||||||
|
path: test_mini_pager_all
|
||||||
|
defaults:
|
||||||
|
pager: '0'
|
||||||
|
pager:
|
||||||
|
type: mini
|
||||||
|
options:
|
||||||
|
items_per_page: '0'
|
||||||
base_field: nid
|
base_field: nid
|
||||||
status: '1'
|
status: '1'
|
||||||
module: views
|
module: views
|
||||||
|
|
Loading…
Reference in New Issue