1 | <?php |
||
19 | class DoctrineWriter implements Writer, FlushableWriter |
||
20 | { |
||
21 | /** |
||
22 | * @var EntityManagerInterface |
||
23 | */ |
||
24 | protected $entityManager; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $entityName; |
||
30 | |||
31 | /** |
||
32 | * @var EntityRepository |
||
33 | */ |
||
34 | protected $entityRepository; |
||
35 | |||
36 | /** |
||
37 | * @var ClassMetadata |
||
38 | */ |
||
39 | protected $entityMetadata; |
||
40 | |||
41 | /** |
||
42 | * Original Doctrine logger |
||
43 | * |
||
44 | * @var SQLLogger |
||
45 | */ |
||
46 | protected $originalLogger; |
||
47 | |||
48 | /** |
||
49 | * Whether to truncate the table first |
||
50 | * |
||
51 | * @var boolean |
||
52 | */ |
||
53 | protected $truncate = true; |
||
54 | |||
55 | /** |
||
56 | * List of fields used to lookup an entity |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $lookupFields = array(); |
||
61 | |||
62 | /** |
||
63 | * @param EntityManagerInterface $entityManager |
||
64 | * @param string $entityName |
||
65 | * @param string|array $index Field or fields to find current entities by |
||
66 | */ |
||
67 | 4 | public function __construct(EntityManagerInterface $entityManager, $entityName, $index = null) |
|
82 | |||
83 | /** |
||
84 | * @return boolean |
||
85 | */ |
||
86 | public function getTruncate() |
||
90 | |||
91 | /** |
||
92 | * Set whether to truncate the table first |
||
93 | * |
||
94 | * @param boolean $truncate |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setTruncate($truncate) |
||
104 | |||
105 | /** |
||
106 | * Disable truncation |
||
107 | * |
||
108 | * @return $this |
||
109 | */ |
||
110 | public function disableTruncate() |
||
116 | |||
117 | /** |
||
118 | * Disable Doctrine logging |
||
119 | * |
||
120 | * @return $this |
||
121 | */ |
||
122 | public function prepare() |
||
130 | |||
131 | /** |
||
132 | * Return a new instance of the entity |
||
133 | * |
||
134 | * @return object |
||
135 | */ |
||
136 | 3 | protected function getNewInstance() |
|
146 | |||
147 | /** |
||
148 | * Call a setter of the entity |
||
149 | * |
||
150 | * @param object $entity |
||
151 | * @param mixed $value |
||
152 | * @param string $setter |
||
153 | */ |
||
154 | 3 | protected function setValue($entity, $value, $setter) |
|
160 | |||
161 | /** |
||
162 | * Re-enable Doctrine logging |
||
163 | * |
||
164 | * @return $this |
||
165 | */ |
||
166 | 1 | public function finish() |
|
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | 3 | public function writeItem(array $item) |
|
184 | |||
185 | /** |
||
186 | * @param array $item |
||
187 | * @param object $entity |
||
188 | */ |
||
189 | 3 | protected function updateEntity(array $item, $entity) |
|
212 | |||
213 | /** |
||
214 | * Add the associated objects in case the item have for persist its relation |
||
215 | * |
||
216 | * @param array $item |
||
217 | * @param object $entity |
||
218 | */ |
||
219 | 3 | protected function loadAssociationObjectsToEntity(array $item, $entity) |
|
236 | |||
237 | /** |
||
238 | * Truncate the database table for this writer |
||
239 | */ |
||
240 | protected function truncateTable() |
||
247 | |||
248 | /** |
||
249 | * Disable Doctrine logging |
||
250 | */ |
||
251 | protected function disableLogging() |
||
257 | |||
258 | /** |
||
259 | * Re-enable Doctrine logging |
||
260 | */ |
||
261 | 1 | protected function reEnableLogging() |
|
266 | |||
267 | /** |
||
268 | * Finds existing entity or create a new instance |
||
269 | * |
||
270 | * @param array $item |
||
271 | */ |
||
272 | 3 | protected function findOrCreateItem(array $item) |
|
297 | |||
298 | /** |
||
299 | * Flush and clear the entity manager |
||
300 | */ |
||
301 | 1 | public function flush() |
|
306 | } |
||
307 |