Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92693988
LiskMigrationIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 22, 20:32
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Nov 24, 20:32 (2 d)
Engine
blob
Format
Raw Data
Handle
22488570
Attached To
rPH Phabricator
LiskMigrationIterator.php
View Options
<?php
/**
* Iterate over every object of a given type, without holding all of them in
* memory. This is useful for performing database migrations.
*
* $things = new LiskMigrationIterator(new LiskThing());
* foreach ($things as $thing) {
* // do something
* }
*
* NOTE: This only works on objects with a normal `id` column.
*
* @task storage
*/
final
class
LiskMigrationIterator
extends
PhutilBufferedIterator
{
private
$object
;
private
$cursor
;
private
$set
;
public
function
__construct
(
LiskDAO
$object
)
{
$this
->
set
=
new
LiskDAOSet
();
$this
->
object
=
$object
->
putInSet
(
$this
->
set
);
}
protected
function
didRewind
()
{
$this
->
cursor
=
0
;
}
public
function
key
()
{
return
$this
->
current
()->
getID
();
}
protected
function
loadPage
()
{
$this
->
set
->
clearSet
();
$results
=
$this
->
object
->
loadAllWhere
(
'id > %d ORDER BY id ASC LIMIT %d'
,
$this
->
cursor
,
$this
->
getPageSize
());
if
(
$results
)
{
$this
->
cursor
=
last
(
$results
)->
getID
();
}
return
$results
;
}
}
Event Timeline
Log In to Comment