4 * Iterate over every object of a given type, without holding all of them in
5 * memory. This is useful for performing database migrations.
7 * $things = new LiskMigrationIterator(new LiskThing());
8 * foreach ($things as $thing) {
12 * NOTE: This only works on objects with a normal `id` column.
16 final class LiskMigrationIterator
extends PhutilBufferedIterator
{
21 public function __construct(LiskDAO
$object) {
22 $this->object = $object;
25 protected function didRewind() {
29 public function key() {
30 return $this->current()->getID();
33 protected function loadPage() {
34 $results = $this->object->loadAllWhere(
35 'id > %d ORDER BY id ASC LIMIT %d',
37 $this->getPageSize());
40 $this->cursor
= last($results)->getID();