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