aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggBatch.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-13 04:34:20 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-13 04:34:20 +0000
commit767a9310e2bd88e26ab3ab92b7cb6a52a935787b (patch)
tree691029d3d407933da01df09afe02a641e92d6ab6 /engine/classes/ElggBatch.php
parent05d4ef9de74cd4fc22e1573571f5ed325fcf59db (diff)
downloadelgg-767a9310e2bd88e26ab3ab92b7cb6a52a935787b.tar.gz
elgg-767a9310e2bd88e26ab3ab92b7cb6a52a935787b.tar.bz2
Fixed ElggBatch problems when specifying a limit of 0. Fixed a shoot yourself in the foot situation if passing a dumb number to chunk size.
git-svn-id: http://code.elgg.org/elgg/trunk@8196 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes/ElggBatch.php')
-rw-r--r--engine/classes/ElggBatch.php37
1 files changed, 20 insertions, 17 deletions
diff --git a/engine/classes/ElggBatch.php b/engine/classes/ElggBatch.php
index bbc4de0bc..a69fb9dc9 100644
--- a/engine/classes/ElggBatch.php
+++ b/engine/classes/ElggBatch.php
@@ -138,6 +138,10 @@ class ElggBatch
$this->callback = $callback;
$this->chunkSize = $chunk_size;
+ if ($this->chunkSize <= 0) {
+ $this->chunkSize = 25;
+ }
+
// store these so we can compare later
$this->offset = elgg_get_array_value('offset', $options, 0);
$this->limit = elgg_get_array_value('limit', $options, 10);
@@ -173,24 +177,24 @@ class ElggBatch
return false;
}
- if ($this->retrievedResults >= $this->limit) {
- return false;
- }
+ $limit = $this->chunkSize;
- // if original limit < chunk size, set limit to original limit
- if ($this->limit < $this->chunkSize) {
- $limit = $this->limit;
- }
+ // if someone passed limit = 0 they want everything.
+ if ($this->limit != 0) {
+ if ($this->retrievedResults >= $this->limit) {
+ return false;
+ }
- // if the number of results we'll fetch is greater than the original limit,
- // set the limit to the number of results remaining in the original limit
- elseif ($this->retrievedResults + $this->chunkSize > $this->limit) {
- $limit = $this->limit - $this->retrievedResults;
- }
+ // if original limit < chunk size, set limit to original limit
+ if ($this->limit < $this->chunkSize) {
+ $limit = $this->limit;
+ }
- // everything else is the chunk size
- else {
- $limit = $this->chunkSize;
+ // if the number of results we'll fetch is greater than the original limit,
+ // set the limit to the number of results remaining in the original limit
+ elseif ($this->retrievedResults + $this->chunkSize > $this->limit) {
+ $limit = $this->limit - $this->retrievedResults;
+ }
}
$current_options = array(
@@ -199,7 +203,6 @@ class ElggBatch
);
$options = array_merge($this->options, $current_options);
-
$getter = $this->getter;
if (is_string($getter)) {
@@ -268,7 +271,7 @@ class ElggBatch
*/
public function next() {
// if we'll be at the end.
- if ($this->processedResults + 1 >= $this->limit) {
+ if ($this->processedResults + 1 >= $this->limit && $this->limit > 0) {
$this->results = array();
return false;
}