1
0
Fork 0
mirror of synced 2024-06-27 10:41:00 +12:00

fix(migration): change loop dependent integers scope

This commit is contained in:
Torsten Dittmann 2021-01-14 15:09:48 +01:00
parent a6a7f896c1
commit d7276aa502

View file

@ -12,8 +12,7 @@ abstract class Migration
protected \PDO $db; protected \PDO $db;
protected int $limit = 30; protected int $limit = 30;
protected int $sum = 30;
protected int $offset = 0;
protected Document $project; protected Document $project;
protected Database $projectDB; protected Database $projectDB;
@ -43,16 +42,19 @@ abstract class Migration
*/ */
public function forEachDocument(callable $callback) public function forEachDocument(callable $callback)
{ {
while ($this->sum >= 30) { $sum = 30;
$offset = 0;
while ($sum >= 30) {
$all = $this->projectDB->getCollection([ $all = $this->projectDB->getCollection([
'limit' => $this->limit, 'limit' => $this->limit,
'offset' => $this->offset, 'offset' => $offset,
'orderType' => 'DESC', 'orderType' => 'DESC',
]); ]);
$this->sum = \count($all); $sum = \count($all);
Console::log('Migrating: ' . $this->offset . ' / ' . $this->projectDB->getSum()); Console::log('Migrating: ' . $offset . ' / ' . $this->projectDB->getSum());
foreach ($all as $document) { foreach ($all as $document) {
@ -75,7 +77,7 @@ abstract class Migration
} }
} }
$this->offset = $this->offset + $this->limit; $offset += $this->limit;
} }
} }