-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.php
33 lines (28 loc) · 917 Bytes
/
import.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
<?php
use AKaplya\Orm\Entity\Mapper;
use AKaplya\Orm\Entity\Repository;
use AKaplya\Orm\Sql\Dml;
use AKaplya\Orm\Demo\ProductFactory;
require_once "bootstrap.php";
echo "<pre>";
$productFactory = new ProductFactory();
$productMapper = new Mapper(new Dml(), $connection, $productFactory);
$productRepository = new Repository($productMapper);
$uow = new AKaplya\Orm\Entity\UnitOfWork(
new AKaplya\Orm\Entity\Config(), ['products' => $productRepository]
);
$t = 0;
$time = microtime(true);
$file = fopen('./tmp/products.data', 'r');
if ($file) {
while (($buffer = fgets($file, 4096)) !== false) {
$entity = unserialize($buffer);
$uow->getRepository('products')->registerEntity($entity);
} $t++;
if (!feof($file)) {
echo "Error: unexpected exception\n";
}
fclose($file);
}
$uow->flush();
echo 'Processed ' . $t . ' items for ' . (microtime(true) - $time) . ' sec.';