1 | <?php |
||
9 | class DiffStorageStore implements DiffStorageStoreInterface { |
||
10 | /** @var PDO */ |
||
11 | private $pdo; |
||
12 | /** @var PDOStatement */ |
||
13 | private $insertStmt; |
||
14 | /** @var PDOStatement */ |
||
15 | private $replaceStmt; |
||
16 | /** @var PDOStatement */ |
||
17 | private $selectStmt; |
||
18 | /** @var PDOStatement */ |
||
19 | private $updateStmt; |
||
20 | /** @var string */ |
||
21 | private $storeA; |
||
22 | /** @var string */ |
||
23 | private $storeB; |
||
24 | /** @var int */ |
||
25 | private $counter = 0; |
||
26 | /** @var callable */ |
||
27 | private $duplicateKeyHandler; |
||
28 | /** @var array */ |
||
29 | private $converter; |
||
30 | /** @var string[] */ |
||
31 | private $keys; |
||
32 | /** @var string[] */ |
||
33 | private $valueKeys; |
||
34 | |||
35 | /** |
||
36 | * @param PDO $pdo |
||
37 | * @param string $keySchema |
||
38 | * @param string $valueSchema |
||
39 | * @param string[] $keys |
||
40 | * @param string[] $valueKeys |
||
41 | * @param array $converter |
||
42 | * @param string $storeA |
||
43 | * @param string $storeB |
||
44 | * @param callable $duplicateKeyHandler |
||
45 | */ |
||
46 | public function __construct(PDO $pdo, $keySchema, $valueSchema, array $keys, array $valueKeys, array $converter, $storeA, $storeB, $duplicateKeyHandler) { |
||
59 | |||
60 | /** |
||
61 | * @param array $data |
||
62 | * @param array $translation |
||
63 | * @param callable $duplicateKeyHandler |
||
64 | */ |
||
65 | public function addRow(array $data, array $translation = null, $duplicateKeyHandler = null) { |
||
105 | |||
106 | /** |
||
107 | * @param Traversable|array $rows |
||
108 | * @param array $translation |
||
109 | * @param callable $duplicateKeyHandler |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function addRows($rows, array $translation = null, $duplicateKeyHandler = null) { |
||
118 | |||
119 | /** |
||
120 | * Returns true whenever there is any changed, added or removed data available |
||
121 | */ |
||
122 | public function hasAnyChanges() { |
||
133 | |||
134 | /** |
||
135 | * Get all rows, that are present in this store, but not in the other |
||
136 | * |
||
137 | * @return Generator|DiffStorageStoreRow[] |
||
138 | */ |
||
139 | public function getNew() { |
||
159 | |||
160 | /** |
||
161 | * Get all rows, that have a different value hash in the other store |
||
162 | * |
||
163 | * @return Generator|DiffStorageStoreRow[] |
||
164 | */ |
||
165 | public function getChanged() { |
||
185 | |||
186 | /** |
||
187 | * @return Generator|DiffStorageStoreRow[] |
||
188 | */ |
||
189 | public function getNewOrChanged() { |
||
213 | |||
214 | /** |
||
215 | * Get all rows, that are present in the other store, but not in this |
||
216 | * |
||
217 | * @return Generator|DiffStorageStoreRow[] |
||
218 | */ |
||
219 | public function getMissing() { |
||
239 | |||
240 | /** |
||
241 | * @return $this |
||
242 | */ |
||
243 | public function clearAll() { |
||
248 | |||
249 | /** |
||
250 | * @param string $query |
||
251 | * @param callable $stringFormatter |
||
252 | * @return DiffStorageStoreRow[]|Generator |
||
253 | */ |
||
254 | private function query($query, $stringFormatter) { |
||
264 | |||
265 | /** |
||
266 | * @return Traversable|array[] |
||
267 | */ |
||
268 | public function getIterator() { |
||
290 | |||
291 | /** |
||
292 | * @param array $data |
||
293 | * @param array $translation |
||
294 | * @return array |
||
295 | */ |
||
296 | private function translate(array $data, array $translation = null) { |
||
309 | |||
310 | /** |
||
311 | * @return int |
||
312 | */ |
||
313 | public function count() { |
||
327 | |||
328 | /** |
||
329 | * @param array $localData |
||
330 | * @param array $foreignData |
||
331 | * @param callable $stringFormatter |
||
332 | * @return DiffStorageStoreRow |
||
333 | */ |
||
334 | private function instantiateRow(array $localData = null, array $foreignData = null, $stringFormatter) { |
||
337 | |||
338 | /** |
||
339 | * @param DiffStorageStoreRowInterface $row |
||
340 | * @return string |
||
341 | */ |
||
342 | private function formatNewRow(DiffStorageStoreRowInterface $row) { |
||
347 | |||
348 | /** |
||
349 | * @param DiffStorageStoreRowInterface $row |
||
350 | * @return string |
||
351 | */ |
||
352 | private function formatChangedRow(DiffStorageStoreRowInterface $row) { |
||
358 | |||
359 | /** |
||
360 | * @param DiffStorageStoreRowInterface $row |
||
361 | * @return string |
||
362 | */ |
||
363 | private function formatMissingRow(DiffStorageStoreRowInterface $row) { |
||
368 | |||
369 | /** |
||
370 | * @param array $keyValues |
||
371 | * @return string |
||
372 | */ |
||
373 | private function formatKeyValuePairs($keyValues) { |
||
386 | } |
||
387 |