1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Msi\Services\MsiBunchProcessor |
5
|
|
|
* |
6
|
|
|
* PHP version 7 |
7
|
|
|
* |
8
|
|
|
* @author Tim Wagner <[email protected]> |
9
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @link https://github.com/techdivision/import-product-msi |
12
|
|
|
* @link http://www.techdivision.com |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Product\Msi\Services; |
16
|
|
|
|
17
|
|
|
use TechDivision\Import\Dbal\Actions\ActionInterface; |
18
|
|
|
use TechDivision\Import\Dbal\Connection\ConnectionInterface; |
19
|
|
|
use TechDivision\Import\Product\Msi\Repositories\InventorySourceRepositoryInterface; |
20
|
|
|
use TechDivision\Import\Product\Msi\Repositories\InventorySourceItemRepositoryInterface; |
21
|
|
|
use TechDivision\Import\Product\Repositories\ProductRepositoryInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The inventory source item bunch processor implementation. |
25
|
|
|
* |
26
|
|
|
* @author Tim Wagner <[email protected]> |
27
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license https://opensource.org/licenses/MIT |
29
|
|
|
* @link https://github.com/techdivision/import-product-msi |
30
|
|
|
* @link http://www.techdivision.com |
31
|
|
|
*/ |
32
|
|
|
class MsiBunchProcessor implements MsiBunchProcessorInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* The repository to load the products with. |
36
|
|
|
* |
37
|
|
|
* @var \TechDivision\Import\Product\Repositories\ProductRepositoryInterface |
38
|
|
|
*/ |
39
|
|
|
protected $productRepository; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* A PDO connection initialized with the values from the Doctrine EntityManager. |
43
|
|
|
* |
44
|
|
|
* @var \TechDivision\Import\Dbal\Connection\ConnectionInterface |
45
|
|
|
*/ |
46
|
|
|
protected $connection; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The repository to access inventory sources. |
50
|
|
|
* |
51
|
|
|
* @var \TechDivision\Import\Product\Msi\Repositories\InventorySourceRepositoryInterface |
52
|
|
|
*/ |
53
|
|
|
protected $inventorySourceRepository; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The repository to access inventory source items. |
57
|
|
|
* |
58
|
|
|
* @var \TechDivision\Import\Product\Msi\Repositories\InventorySourceItemRepositoryInterface |
59
|
|
|
*/ |
60
|
|
|
protected $inventorySourceItemRepository; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* The action for product CRUD methods. |
64
|
|
|
* |
65
|
|
|
* @var \TechDivision\Import\Dbal\Actions\ActionInterface |
66
|
|
|
*/ |
67
|
|
|
protected $inventorySourceItemAction; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Initialize the processor with the necessary assembler and repository instances. |
71
|
|
|
* |
72
|
|
|
* @param \TechDivision\Import\Dbal\Connection\ConnectionInterface $connection The connection to use |
73
|
|
|
* @param \TechDivision\Import\Product\Msi\Repositories\InventorySourceRepositoryInterface $inventorySourceRepository The inventory source repository instance |
74
|
|
|
* @param \TechDivision\Import\Product\Msi\Repositories\InventorySourceItemRepositoryInterface $inventorySourceItemRepository The inventory source item repository instance |
75
|
|
|
* @param \TechDivision\Import\Dbal\Actions\ActionInterface $inventorySourceItemAction The inventory source item action instance |
76
|
|
|
*/ |
77
|
|
|
public function __construct( |
78
|
|
|
ConnectionInterface $connection, |
79
|
|
|
InventorySourceRepositoryInterface $inventorySourceRepository, |
80
|
|
|
InventorySourceItemRepositoryInterface $inventorySourceItemRepository, |
81
|
|
|
ActionInterface $inventorySourceItemAction, |
82
|
|
|
ProductRepositoryInterface $productRepository |
83
|
|
|
) { |
84
|
|
|
$this->setConnection($connection); |
85
|
|
|
$this->setInventorySourceRepository($inventorySourceRepository); |
86
|
|
|
$this->setInventorySourceItemRepository($inventorySourceItemRepository); |
87
|
|
|
$this->setInventorySourceItemAction($inventorySourceItemAction); |
88
|
|
|
$this->setProductRepository($productRepository); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set's the passed connection. |
93
|
|
|
* |
94
|
|
|
* @param \TechDivision\Import\Dbal\Connection\ConnectionInterface $connection The connection to set |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function setConnection(ConnectionInterface $connection) |
99
|
|
|
{ |
100
|
|
|
$this->connection = $connection; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Return's the connection. |
105
|
|
|
* |
106
|
|
|
* @return \TechDivision\Import\Dbal\Connection\ConnectionInterface The connection instance |
107
|
|
|
*/ |
108
|
|
|
public function getConnection() |
109
|
|
|
{ |
110
|
|
|
return $this->connection; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
115
|
|
|
* object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
116
|
|
|
* Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
117
|
|
|
* to autocommit mode. |
118
|
|
|
* |
119
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
120
|
|
|
* @link http://php.net/manual/en/pdo.begintransaction.php |
121
|
|
|
*/ |
122
|
|
|
public function beginTransaction() |
123
|
|
|
{ |
124
|
|
|
return $this->connection->beginTransaction(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Commits a transaction, returning the database connection to autocommit mode until the next call to |
129
|
|
|
* ProductProcessor::beginTransaction() starts a new transaction. |
130
|
|
|
* |
131
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
132
|
|
|
* @link http://php.net/manual/en/pdo.commit.php |
133
|
|
|
*/ |
134
|
|
|
public function commit() |
135
|
|
|
{ |
136
|
|
|
return $this->connection->commit(); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
141
|
|
|
* |
142
|
|
|
* If the database was set to autocommit mode, this function will restore autocommit mode after it has |
143
|
|
|
* rolled back the transaction. |
144
|
|
|
* |
145
|
|
|
* Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
146
|
|
|
* language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
147
|
|
|
* COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
148
|
|
|
* |
149
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
150
|
|
|
* @link http://php.net/manual/en/pdo.rollback.php |
151
|
|
|
*/ |
152
|
|
|
public function rollBack() |
153
|
|
|
{ |
154
|
|
|
return $this->connection->rollBack(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set's the repository to load the inventory sources with. |
159
|
|
|
* |
160
|
|
|
* @param \TechDivision\Import\Product\Msi\Repositories\InventorySourceRepositoryInterface $inventorySourceRepository The repository instance |
161
|
|
|
* |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
public function setInventorySourceRepository(InventorySourceRepositoryInterface $inventorySourceRepository) |
165
|
|
|
{ |
166
|
|
|
$this->inventorySourceRepository = $inventorySourceRepository; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Return's the repository to load the inventory sources with. |
171
|
|
|
* |
172
|
|
|
* @return \TechDivision\Import\Product\Msi\Repositories\InventorySourceItemRepositoryInterface The repository instance |
173
|
|
|
*/ |
174
|
|
|
public function getInventorySourceRepository() |
175
|
|
|
{ |
176
|
|
|
return $this->inventorySourceRepository; |
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Set's the repository to load the inventory source items with. |
181
|
|
|
* |
182
|
|
|
* @param \TechDivision\Import\Product\Msi\Repositories\InventorySourceItemRepositoryInterface $inventorySourceItemRepository The repository instance |
183
|
|
|
* |
184
|
|
|
* @return void |
185
|
|
|
*/ |
186
|
|
|
public function setInventorySourceItemRepository(InventorySourceItemRepositoryInterface $inventorySourceItemRepository) |
187
|
|
|
{ |
188
|
|
|
$this->inventorySourceItemRepository = $inventorySourceItemRepository; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Return's the repository to load the inventory source items with. |
193
|
|
|
* |
194
|
|
|
* @return \TechDivision\Import\Product\Msi\Repositories\InventorySourceItemRepositoryInterface The repository instance |
195
|
|
|
*/ |
196
|
|
|
public function getInventorySourceItemRepository() |
197
|
|
|
{ |
198
|
|
|
return $this->inventorySourceItemRepository; |
|
|
|
|
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Set's the action with the inventory source item CRUD methods. |
203
|
|
|
* |
204
|
|
|
* @param \TechDivision\Import\Dbal\Actions\ActionInterface $inventorySourceItemAction The action instance |
205
|
|
|
* |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function setInventorySourceItemAction(ActionInterface $inventorySourceItemAction) |
209
|
|
|
{ |
210
|
|
|
$this->inventorySourceItemAction = $inventorySourceItemAction; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Return's the action with the inventory source item CRUD methods. |
215
|
|
|
* |
216
|
|
|
* @return \TechDivision\Import\Dbal\Actions\ActionInterface The action instance |
217
|
|
|
*/ |
218
|
|
|
public function getInventorySourceItemAction() |
219
|
|
|
{ |
220
|
|
|
return $this->inventorySourceItemAction; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Load's the inventory source item with the passed SKU and source code. |
225
|
|
|
* |
226
|
|
|
* @param string $sku The SKU of the inventory source item to return |
227
|
|
|
* @param string $sourceCode The source code of the inventory source item to return |
228
|
|
|
* |
229
|
|
|
* @return array The inventory source item |
230
|
|
|
*/ |
231
|
|
|
public function loadInventorySourceItemBySkuAndSourceCode($sku, $sourceCode) |
232
|
|
|
{ |
233
|
|
|
return $this->getInventorySourceItemRepository()->findOneBySkuAndSourceCode($sku, $sourceCode); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Load's the available inventory sources. |
238
|
|
|
* |
239
|
|
|
* @return array The available inventory sources |
240
|
|
|
*/ |
241
|
|
|
public function loadInventorySources() |
242
|
|
|
{ |
243
|
|
|
return $this->getInventorySourceRepository()->findAll(); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Persist's the passed inventory source item data. |
248
|
|
|
* |
249
|
|
|
* @param array $inventorySourceItem The inventory source item data to persist |
250
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
251
|
|
|
* |
252
|
|
|
* @return void |
253
|
|
|
*/ |
254
|
|
|
public function persistInventorySourceItem($inventorySourceItem, $name = null) |
255
|
|
|
{ |
256
|
|
|
$this->getInventorySourceItemAction()->persist($inventorySourceItem, $name); |
|
|
|
|
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Delete's the entity with the passed attributes. |
261
|
|
|
* |
262
|
|
|
* @param array $row The attributes of the entity to delete |
263
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
264
|
|
|
* |
265
|
|
|
* @return void |
266
|
|
|
*/ |
267
|
|
|
public function deleteInventorySourceItem($row, $name = null) |
268
|
|
|
{ |
269
|
|
|
$this->getInventorySourceItemAction()->delete($row, $name); |
|
|
|
|
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Clean-Up the repositories to free memory. |
274
|
|
|
* |
275
|
|
|
* @return void |
276
|
|
|
*/ |
277
|
|
|
public function cleanUp() |
278
|
|
|
{ |
279
|
|
|
// not implemented yet |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
public function loadProduct($sku) |
283
|
|
|
{ |
284
|
|
|
return $this->getProductRepository()->findOneBySku($sku); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Set's the repository to load the products with. |
289
|
|
|
* |
290
|
|
|
* @param \TechDivision\Import\Product\Repositories\ProductRepositoryInterface $productRepository The repository instance |
291
|
|
|
* |
292
|
|
|
* @return void |
293
|
|
|
*/ |
294
|
|
|
public function setProductRepository(ProductRepositoryInterface $productRepository) |
295
|
|
|
{ |
296
|
|
|
$this->productRepository = $productRepository; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Return's the repository to load the products with. |
301
|
|
|
* |
302
|
|
|
* @return \TechDivision\Import\Product\Repositories\ProductRepositoryInterface The repository instance |
303
|
|
|
*/ |
304
|
|
|
public function getProductRepository() |
305
|
|
|
{ |
306
|
|
|
return $this->productRepository; |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|