|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Stinger Soft Platform package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Oliver Kotte <[email protected]> |
|
7
|
|
|
* (c) Florian Meyer <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
namespace StingerSoft\PlatformBundle\DataFixtures; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
|
15
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
16
|
|
|
use Psr\Log\LoggerInterface; |
|
17
|
|
|
use Psr\Log\NullLogger; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
19
|
|
|
|
|
20
|
|
|
abstract class AbstractStingerFixture extends AbstractFixture { |
|
21
|
|
|
|
|
22
|
|
|
use ContainerAwareTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* |
|
26
|
|
|
* @var ObjectManager |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $manager; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
* @var LoggerInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
private $logger; |
|
35
|
|
|
|
|
36
|
|
|
public final function load(ObjectManager $manager) { |
|
|
|
|
|
|
37
|
|
|
$this->manager = $manager; |
|
38
|
|
|
if(!$this->skipMe()) { |
|
39
|
|
|
$this->getLogger()->info("Starting import of fixtures ..."); |
|
40
|
|
|
$this->reportMemoryUsage(); |
|
41
|
|
|
// $startTime = microtime(true); |
|
|
|
|
|
|
42
|
|
|
$this->import(); |
|
43
|
|
|
// $endTime = microtime(true); |
|
|
|
|
|
|
44
|
|
|
// $this->info("Finished importing fixtures in " . $this->formatTime($startTime, $endTime)); |
|
|
|
|
|
|
45
|
|
|
$this->reportMemoryUsage(); |
|
46
|
|
|
} else { |
|
47
|
|
|
$this->getLogger()->info('Skipping import of fixtures !'); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected final function reportMemoryUsage() { |
|
|
|
|
|
|
52
|
|
|
// $this->getLogger()->info("Currently using %s of RAM", $this->getMemoryUsage()); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Load data fixtures |
|
57
|
|
|
*/ |
|
58
|
|
|
protected abstract function import(); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Decides whether this fixture should be skipped or not. |
|
62
|
|
|
* |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function skipMe() { |
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* |
|
71
|
|
|
* @return LoggerInterface|null |
|
|
|
|
|
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getLogger() { |
|
74
|
|
|
if(!$this->logger && $this->container && $this->container->has('logger')) { |
|
75
|
|
|
$this->logger = $this->container->get('logger'); |
|
76
|
|
|
} else { |
|
77
|
|
|
$this->logger = new NullLogger(); |
|
78
|
|
|
} |
|
79
|
|
|
return $this->logger; |
|
80
|
|
|
} |
|
81
|
|
|
} |