Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2895166
LiskMigrationIterator.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
989 B
Referenced Files
None
Subscribers
None
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
;
public
function
__construct
(
LiskDAO
$object
)
{
$this
->
object
=
$object
;
}
protected
function
didRewind
(
)
{
$this
->
cursor
=
0
;
}
#[\ReturnTypeWillChange]
public
function
key
(
)
{
return
$this
->
current
(
)
->
getID
(
)
;
}
protected
function
loadPage
(
)
{
$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
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Jan 19 2025, 21:01 (6 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1118934
Default Alt Text
LiskMigrationIterator.php (989 B)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment