1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Subjects\AbstractAttributeSubject |
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\Subjects; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
24
|
|
|
use TechDivision\Import\Subjects\AbstractSubject; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The abstract product subject implementation that provides basic attribute |
28
|
|
|
* handling business logic. |
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-attribute |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
abstract class AbstractAttributeSubject extends AbstractSubject implements AttributeSubjectInterface |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The array with the available entity types. |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
protected $entityTypes = array(); |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Mappings for attribute code => CSV column header. |
48
|
|
|
* |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
protected $headerMappings = array(); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Intializes the previously loaded global data for exactly one bunch. |
55
|
|
|
* |
56
|
|
|
* @param string $serial The serial of the actual import |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
* @see \Importer\Csv\Actions\ProductImportAction::prepare() |
60
|
|
|
*/ |
61
|
|
|
public function setUp($serial) |
62
|
|
|
{ |
63
|
|
|
|
64
|
|
|
// load the status of the actual import |
65
|
|
|
$status = $this->getRegistryProcessor()->getAttribute($serial); |
66
|
|
|
|
67
|
|
|
// load the global data we've prepared initially |
68
|
|
|
$this->entityTypes = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::ENTITY_TYPES]; |
69
|
|
|
|
70
|
|
|
// prepare the callbacks |
71
|
|
|
parent::setUp($serial); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Clean up the global data after importing the bunch. |
76
|
|
|
* |
77
|
|
|
* @param string $serial The serial of the actual import |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function tearDown($serial) |
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
// invoke the parent method |
85
|
|
|
parent::tearDown($serial); |
86
|
|
|
|
87
|
|
|
// update the status |
88
|
|
|
$this->getRegistryProcessor()->mergeAttributesRecursive( |
89
|
|
|
$serial, |
90
|
|
|
array( |
91
|
|
|
RegistryKeys::FILES => array($this->getFilename() => array(RegistryKeys::STATUS => 1)) |
92
|
|
|
) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Return's the header mappings for the actual entity. |
98
|
|
|
* |
99
|
|
|
* @return array The header mappings |
100
|
|
|
*/ |
101
|
|
|
public function getHeaderMappings() |
102
|
|
|
{ |
103
|
|
|
return $this->headerMappings; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Return's the entity type for the passed code. |
108
|
|
|
* |
109
|
|
|
* @param string $entityTypeCode The entity type code |
110
|
|
|
* |
111
|
|
|
* @return array The requested entity type |
112
|
|
|
* @throws \Exception Is thrown, if the entity type with the passed code is not available |
113
|
|
|
*/ |
114
|
|
|
public function getEntityType($entityTypeCode) |
115
|
|
|
{ |
116
|
|
|
|
117
|
|
|
// query whether or not, the entity type with the passed code is available |
118
|
|
|
if (isset($this->entityTypes[$entityTypeCode])) { |
119
|
|
|
return $this->entityTypes[$entityTypeCode]; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// throw an exception, if not |
123
|
|
|
throw new \Exception( |
124
|
|
|
sprintf( |
125
|
|
|
'Can\'t find entity type with code %s in file %s on line %d', |
126
|
|
|
$entityTypeCode, |
127
|
|
|
$this->getFilename(), |
128
|
|
|
$this->getLineNumber() |
129
|
|
|
) |
130
|
|
|
); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|