1 | <?php |
||
32 | final class VersionRepository implements VersionRepositoryInterface |
||
33 | { |
||
34 | /** @var VersionMapperInterface */ |
||
35 | private $mapper; |
||
36 | |||
37 | /** |
||
38 | * VersionRepository constructor. |
||
39 | * |
||
40 | * @param VersionMapperInterface $mapper |
||
41 | */ |
||
42 | 11 | public function __construct(VersionMapperInterface $mapper) |
|
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | 4 | final public function fetchAll() |
|
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | 4 | final public function update(DeltaInterface $version) |
|
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | 2 | public function updateAll(CollectionInterface $versions) |
|
79 | { |
||
80 | 2 | if ($versions->isEmpty()) { |
|
81 | 1 | return true; // nothing to do - exit early |
|
82 | } |
||
83 | |||
84 | $mapToIds = function(DeltaInterface $v) { |
||
85 | 1 | return $v->getId(); |
|
86 | 1 | }; |
|
87 | /** @var CollectionInterface $migrated */ |
||
88 | /** @var CollectionInterface $notMigrated */ |
||
89 | 1 | list($migrated, $notMigrated) = $versions->partition(function($i, DeltaInterface $v) { |
|
90 | 1 | return $v->isMigrated(); |
|
91 | 1 | }); |
|
92 | 1 | $migratedIds = $migrated->map($mapToIds); |
|
93 | 1 | $notMigratedIds = $notMigrated->map($mapToIds); |
|
94 | |||
95 | 1 | $saveResult = $this->mapper->saveAll($migratedIds); |
|
96 | 1 | $deleteResult = $this->mapper->deleteAll($notMigratedIds); |
|
97 | |||
98 | 1 | return $saveResult && $deleteResult; |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * @inheritdoc |
||
103 | */ |
||
104 | 2 | public function save(DeltaInterface $version) |
|
108 | |||
109 | /** |
||
110 | * @inheritdoc |
||
111 | */ |
||
112 | 2 | public function delete(DeltaInterface $version) |
|
116 | |||
117 | /** |
||
118 | * @inheritdoc |
||
119 | */ |
||
120 | 1 | public function fetch($id) |
|
127 | } |
||
128 |