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\DataFixtures\DependentFixtureInterface; |
16
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
18
|
|
|
use Psr\Log\LoggerInterface; |
19
|
|
|
use Psr\Log\NullLogger; |
20
|
|
|
|
21
|
|
|
abstract class AbstractStingerFixture extends AbstractFixture implements DependentFixtureInterface { |
22
|
|
|
|
23
|
|
|
use ContainerAwareTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* |
27
|
|
|
* @var ObjectManager |
28
|
|
|
*/ |
29
|
|
|
protected $manager; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
* @var LoggerInterface |
34
|
|
|
*/ |
35
|
|
|
private $logger; |
36
|
|
|
|
37
|
|
|
public final function load(ObjectManager $manager) { |
|
|
|
|
38
|
|
|
$this->manager = $manager; |
39
|
|
|
if(!$this->skipMe()) { |
40
|
|
|
$this->info("Starting import of fixtures ..."); |
|
|
|
|
41
|
|
|
$this->reportMemoryUsage(); |
42
|
|
|
// $startTime = microtime(true); |
|
|
|
|
43
|
|
|
$this->import(); |
44
|
|
|
// $endTime = microtime(true); |
|
|
|
|
45
|
|
|
// $this->info("Finished importing fixtures in " . $this->formatTime($startTime, $endTime)); |
46
|
|
|
$this->reportMemoryUsage(); |
47
|
|
|
} else { |
48
|
|
|
$this->info('Skipping import of fixtures !'); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected final function reportMemoryUsage() { |
|
|
|
|
53
|
|
|
$this->info("Currently using %s of RAM", $this->getMemoryUsage()); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Load data fixtures |
58
|
|
|
*/ |
59
|
|
|
protected abstract function import(); |
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Decides whether this fixture should be skipped or not. |
63
|
|
|
* |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
protected function skipMe() { |
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
* @return LoggerInterface|null |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
protected function getLogger() { |
76
|
|
|
if(!$this->logger && $this->container && $this->container->has('logger')) { |
77
|
|
|
$this->logger = $this->container->get('logger'); |
78
|
|
|
} else { |
79
|
|
|
$this->logger = new NullLogger(); |
80
|
|
|
} |
81
|
|
|
return $this->logger; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
*/ |
86
|
|
|
protected function getDependencies() { |
87
|
|
|
} |
88
|
|
|
} |