fixed propfind_iterator sometimes not returning any item

This commit is contained in:
Ralf Becker 2010-03-03 08:18:48 +00:00
parent 31be31954e
commit 671a0293ef

View File

@ -390,6 +390,13 @@ class groupdav_propfind_iterator implements Iterator
*/ */
const CHUNK_SIZE = 500; const CHUNK_SIZE = 500;
/**
* Log calls via error_log()
*
* @var boolean
*/
public $debug = false;
/** /**
* Constructor * Constructor
* *
@ -399,6 +406,8 @@ class groupdav_propfind_iterator implements Iterator
*/ */
public function __construct(groupdav_handler $handler,array $filter,array &$files=null) public function __construct(groupdav_handler $handler,array $filter,array &$files=null)
{ {
if ($this->debug) error_log(__METHOD__."(,".array2string($filter).",)");
$this->handler = $handler; $this->handler = $handler;
$this->filter = $filter; $this->filter = $filter;
$this->files = $files; $this->files = $files;
@ -412,6 +421,8 @@ class groupdav_propfind_iterator implements Iterator
*/ */
public function current() public function current()
{ {
if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files)));
return current($this->files); return current($this->files);
} }
@ -424,6 +435,7 @@ class groupdav_propfind_iterator implements Iterator
{ {
$current = $this->current(); $current = $this->current();
if ($this->debug) error_log(__METHOD__."() returning ".array2string($current['path']));
return $current['path']; // we return path as key return $current['path']; // we return path as key
} }
@ -434,10 +446,14 @@ class groupdav_propfind_iterator implements Iterator
{ {
if (next($this->files) !== false) if (next($this->files) !== false)
{ {
if ($this->debug) error_log(__METHOD__."() returning TRUE");
return true; return true;
} }
if (!$this->handler) if (is_array($this->files) && count($this->files) < self::CHUNK_SIZE) // less entries then asked --> no further available
{ {
if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)");
return false; // no further entries return false; // no further entries
} }
// try query further files via propfind callback of handler and store result in $this->files // try query further files via propfind callback of handler and store result in $this->files
@ -445,10 +461,7 @@ class groupdav_propfind_iterator implements Iterator
$this->start += self::CHUNK_SIZE; $this->start += self::CHUNK_SIZE;
reset($this->files); reset($this->files);
if (count($this->files) < self::CHUNK_SIZE) // less entries then asked --> no further available if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false));
{
unset($this->handler);
}
return current($this->files) !== false; return current($this->files) !== false;
} }
@ -457,7 +470,13 @@ class groupdav_propfind_iterator implements Iterator
*/ */
public function rewind() public function rewind()
{ {
if ($this->debug) error_log(__METHOD__."()");
// query first set of files via propfind callback of handler and store result in $this->files
$this->start = 0;
$this->files = $this->handler->propfind_callback($this->filter,array($this->start,self::CHUNK_SIZE));
$this->start += self::CHUNK_SIZE;
reset($this->files);
} }
/** /**
@ -467,6 +486,7 @@ class groupdav_propfind_iterator implements Iterator
*/ */
public function valid () public function valid ()
{ {
if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false));
return current($this->files) !== false; return current($this->files) !== false;
} }
} }