Path: blob/master/src/infrastructure/storage/lisk/LiskMigrationIterator.php
12241 views
<?php12/**3* Iterate over every object of a given type, without holding all of them in4* memory. This is useful for performing database migrations.5*6* $things = new LiskMigrationIterator(new LiskThing());7* foreach ($things as $thing) {8* // do something9* }10*11* NOTE: This only works on objects with a normal `id` column.12*13* @task storage14*/15final class LiskMigrationIterator extends PhutilBufferedIterator {1617private $object;18private $cursor;1920public function __construct(LiskDAO $object) {21$this->object = $object;22}2324protected function didRewind() {25$this->cursor = 0;26}2728public function key() {29return $this->current()->getID();30}3132protected function loadPage() {33$results = $this->object->loadAllWhere(34'id > %d ORDER BY id ASC LIMIT %d',35$this->cursor,36$this->getPageSize());3738if ($results) {39$this->cursor = last($results)->getID();40}4142return $results;43}4445}464748