|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Actions\Processors\StockStatusCreateProcessor |
|
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 2016 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 |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Actions\Processors; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\EntityStatus; |
|
24
|
|
|
use TechDivision\Import\Product\Utils\SqlStatements; |
|
25
|
|
|
use TechDivision\Import\Actions\Processors\AbstractCreateProcessor; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The stock status create processor implementation. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/techdivision/import-product |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
View Code Duplication |
class StockStatusCreateProcessor extends AbstractCreateProcessor |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Implements the CRUD functionality the processor is responsible for, |
|
41
|
|
|
* can be one of CREATE, READ, UPDATE or DELETE a entity. |
|
42
|
|
|
* |
|
43
|
|
|
* @param array $row The data to handle |
|
44
|
|
|
* @param string|null $name The name of the prepared statement to execute |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function execute($row, $name = null) |
|
49
|
|
|
{ |
|
50
|
|
|
|
|
51
|
|
|
// load the field names |
|
52
|
|
|
$keys = array_keys($row); |
|
53
|
|
|
|
|
54
|
|
|
// create a unique name for the prepared statement |
|
55
|
|
|
$name = sprintf('%s-%s', $name, md5(implode('-', $keys))); |
|
56
|
|
|
|
|
57
|
|
|
// query whether or not the statement has been prepared |
|
58
|
|
|
if (!$this->hasPreparedStatement($name)) { |
|
59
|
|
|
// remove the entity status from the keys |
|
60
|
|
|
unset($keys[array_search(EntityStatus::MEMBER_NAME, $keys)]); |
|
61
|
|
|
|
|
62
|
|
|
// create the prepared UPDATE statement |
|
63
|
|
|
$statement = sprintf($this->getUtilityClass()->find(SqlStatements::CREATE_STOCK_STATUS), implode(',', $keys), implode(',:', $keys)); |
|
64
|
|
|
|
|
65
|
|
|
// prepare the statement |
|
66
|
|
|
$this->addPreparedStatement($name, $this->getConnection()->prepare($statement)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// pass the call to the parent method |
|
70
|
|
|
return parent::execute($row, $name); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.