Skip to content

Commit d36f517

Browse files
committed
Improve migration
1 parent 378c0ac commit d36f517

1 file changed

Lines changed: 6 additions & 23 deletions

File tree

app/commands/ConvertTimestamp.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,13 @@ public function __construct()
4141
*/
4242
public function fire()
4343
{
44-
//count number of statements
45-
$count = \Statement::count();
46-
47-
for ($x = 0; $x <= $count; $x = $x + 1000) {
48-
49-
$skip = $x;
50-
$take = 1000;
51-
52-
//get statements
53-
$statements = \Statement::skip($skip)->take($take)->get();
54-
55-
if( $statements ){
56-
57-
foreach( $statements as $s ){
58-
//now add timestamp as a date object for mongodb aggregation in document root
59-
$s->timestamp = new \MongoDate(strtotime($s->statement['timestamp']));
60-
$s->save();
61-
}
62-
44+
Statement::chunk(1000, function($statements){
45+
foreach ($statements as $s){
46+
$s->timestamp = new \MongoDate(strtotime($s->statement['timestamp']));
47+
$s->save();
6348
}
64-
65-
$this->info($x . ' converted');
66-
67-
}
49+
$this->info(count($statements) . ' converted.');
50+
});
6851

6952
$this->info('All finished, hopefully!');
7053
}

0 commit comments

Comments
 (0)