|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Attribute\Actions\Processors\CatalogAttributeUpdateProcessor |
|
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-attribute |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Attribute\Actions\Processors; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Attribute\Utils\SqlStatements; |
|
24
|
|
|
use TechDivision\Import\Actions\Processors\AbstractUpdateProcessor; |
|
25
|
|
|
use TechDivision\Import\Utils\EntityStatus; |
|
26
|
|
|
use TechDivision\Import\Attribute\Utils\MemberNames; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The EAV catalog attribute update processor implementation. |
|
30
|
|
|
* |
|
31
|
|
|
* @author Tim Wagner <[email protected]> |
|
32
|
|
|
* @copyright 2016 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-attribute |
|
35
|
|
|
* @link http://www.techdivision.com |
|
36
|
|
|
*/ |
|
37
|
|
|
class CatalogAttributeUpdateProcessor extends AbstractUpdateProcessor |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Return's the array with the SQL statements that has to be prepared. |
|
42
|
|
|
* |
|
43
|
|
|
* @return array The SQL statements to be prepared |
|
44
|
|
|
* @see \TechDivision\Import\Actions\Processors\AbstractBaseProcessor::getStatements() |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function getStatements() |
|
47
|
|
|
{ |
|
48
|
|
|
return array(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Implements the CRUD functionality the processor is responsible for, |
|
53
|
|
|
* can be one of CREATE, READ, UPDATE or DELETE a entity. |
|
54
|
|
|
* |
|
55
|
|
|
* @param array $row The data to handle |
|
56
|
|
|
* @param string|null $name The name of the prepared statement to execute |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function execute($row, $name = null) |
|
61
|
|
|
{ |
|
62
|
|
|
|
|
63
|
|
|
// load the field names |
|
64
|
|
|
$keys = array_keys($row); |
|
65
|
|
|
|
|
66
|
|
|
// create a unique name for the prepared statement |
|
67
|
|
|
$name = sprintf('%s-%s', $name, md5(implode('-', $keys))); |
|
68
|
|
|
|
|
69
|
|
|
// query whether or not the statement has been prepared |
|
70
|
|
|
if (!$this->hasPreparedStatement($name)) { |
|
71
|
|
|
// remove the last value as PK from the array with the keys |
|
72
|
|
|
$pk = $keys[array_search(MemberNames::ATTRIBUTE_ID, $row, true)]; |
|
73
|
|
|
|
|
74
|
|
|
// remove the entity status from the keys |
|
75
|
|
|
unset($keys[array_search(MemberNames::ATTRIBUTE_ID, $keys, true)]); |
|
76
|
|
|
unset($keys[array_search(EntityStatus::MEMBER_NAME, $keys, true)]); |
|
77
|
|
|
|
|
78
|
|
|
// prepare the SET part of the SQL statement |
|
79
|
|
|
array_walk($keys, function (&$value, $key) { |
|
|
|
|
|
|
80
|
|
|
$value = sprintf('%s=:%s', $value, $value); |
|
81
|
|
|
}); |
|
82
|
|
|
|
|
83
|
|
|
// create the prepared UPDATE statement |
|
84
|
|
|
$statement = sprintf($this->getUtilityClass()->find(SqlStatements::UPDATE_CATALOG_ATTRIBUTE), implode(',', $keys), $pk); |
|
85
|
|
|
|
|
86
|
|
|
error_log($statement); |
|
87
|
|
|
|
|
88
|
|
|
// prepare the statement |
|
89
|
|
|
$this->addPreparedStatement($name, $this->getConnection()->prepare($statement)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
error_log(print_r($row, true)); |
|
93
|
|
|
|
|
94
|
|
|
// pass the call to the parent method |
|
95
|
|
|
return parent::execute($row, $name); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.