-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportBlunders.php
39 lines (29 loc) · 942 Bytes
/
importBlunders.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use App\Entity\APIBlunder;
use App\Exception\ExceptionHandler;
use App\Service\Fen\FenFormatService;
include __DIR__.'/core/bootstrap.php';
$fenFormatService = new FenFormatService();
try {
$filepath = config('lichess', 'file_path');
$file = fopen($filepath, 'r');
$key = 0;
$batchSize = 50000;
while (($data = fgetcsv($file)) !== false) {
$apiBlunder = new APIBlunder();
$apiBlunder->setJson($data);
entityManager()->persist($apiBlunder);
if ($key % $batchSize === 0) {
echo "Persisting batch...";
entityManager()->flush();
entityManager()->clear();
}
echo "Blunder $key imported\n";
$key++;
}
fclose($file);
entityManager()->flush();
} catch (Throwable $throwable) {
$exceptionHandler = new ExceptionHandler();
$exceptionHandler->handle($throwable, basename(__FILE__, '.php'));
}