Remove product literal strings in "pht()", part 18
[phabricator.git] / src / infrastructure / storage / lisk / LiskMigrationIterator.php
blobedd31c8123de1bc00e58806f7e96587a83ad0b3b
1 <?php
3 /**
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) {
9 * // do something
10 * }
12 * NOTE: This only works on objects with a normal `id` column.
14 * @task storage
16 final class LiskMigrationIterator extends PhutilBufferedIterator {
18 private $object;
19 private $cursor;
21 public function __construct(LiskDAO $object) {
22 $this->object = $object;
25 protected function didRewind() {
26 $this->cursor = 0;
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',
36 $this->cursor,
37 $this->getPageSize());
39 if ($results) {
40 $this->cursor = last($results)->getID();
43 return $results;