1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Media\Subjects\MediaSubject |
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-media |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Media\Subjects; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
24
|
|
|
use TechDivision\Import\Subjects\FileUploadTrait; |
25
|
|
|
use TechDivision\Import\Subjects\ExportableTrait; |
26
|
|
|
use TechDivision\Import\Subjects\FileUploadSubjectInterface; |
27
|
|
|
use TechDivision\Import\Subjects\ExportableSubjectInterface; |
28
|
|
|
use TechDivision\Import\Subjects\CleanUpColumnsSubjectInterface; |
29
|
|
|
use TechDivision\Import\Product\Media\Utils\ConfigurationKeys; |
30
|
|
|
use TechDivision\Import\Product\Subjects\AbstractProductSubject; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The subject implementation for the product media handling. |
34
|
|
|
* |
35
|
|
|
* @author Tim Wagner <[email protected]> |
36
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
37
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
38
|
|
|
* @link https://github.com/techdivision/import-product-media |
39
|
|
|
* @link http://www.techdivision.com |
40
|
|
|
*/ |
41
|
|
|
class MediaSubject extends AbstractProductSubject implements FileUploadSubjectInterface, CleanUpColumnsSubjectInterface, ExportableSubjectInterface |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The trait that provides file upload functionality. |
46
|
|
|
* |
47
|
|
|
* @var \TechDivision\Import\Subjects\FileUploadTrait |
48
|
|
|
*/ |
49
|
|
|
use FileUploadTrait; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The trait that provides media import functionality. |
53
|
|
|
* |
54
|
|
|
* @var \TechDivision\Import\Product\Media\Subjects\MediaSubjectTrait |
55
|
|
|
*/ |
56
|
|
|
use MediaSubjectTrait; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The trait with the exportable functionality. |
60
|
|
|
* |
61
|
|
|
* @var \TechDivision\Import\Subjects\ExportableTrait |
62
|
|
|
*/ |
63
|
|
|
use ExportableTrait; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Intializes the previously loaded global data for exactly one variants. |
67
|
|
|
* |
68
|
|
|
* @param string $serial The serial of the actual import |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
public function setUp($serial) |
73
|
|
|
{ |
74
|
|
|
|
75
|
|
|
// invoke parent method |
76
|
|
|
parent::setUp($serial); |
77
|
|
|
|
78
|
|
|
// load the entity manager and the registry processor |
79
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
80
|
|
|
|
81
|
|
|
// load the status of the actual import process |
82
|
|
|
$status = $registryProcessor->getAttribute(RegistryKeys::STATUS); |
83
|
|
|
|
84
|
|
|
// load the SKU => entity ID mapping |
85
|
|
|
$this->skuEntityIdMapping = isset($status[RegistryKeys::SKU_ENTITY_ID_MAPPING]) ? $status[RegistryKeys::SKU_ENTITY_ID_MAPPING] : array(); |
86
|
|
|
|
87
|
|
|
// initialize media directory => can be absolute or relative |
88
|
|
View Code Duplication |
if ($this->getConfiguration()->hasParam(ConfigurationKeys::MEDIA_DIRECTORY)) { |
|
|
|
|
89
|
|
|
try { |
90
|
|
|
$this->setMediaDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY))); |
91
|
|
|
} catch (\InvalidArgumentException $iae) { |
92
|
|
|
$this->getSystemLogger()->warning($iae->getMessage()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// initialize images directory => can be absolute or relative |
97
|
|
View Code Duplication |
if ($this->getConfiguration()->hasParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)) { |
|
|
|
|
98
|
|
|
try { |
99
|
|
|
$this->setImagesFileDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY))); |
100
|
|
|
} catch (\InvalidArgumentException $iae) { |
101
|
|
|
$this->getSystemLogger()->warning($iae->getMessage()); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Merge the columns from the configuration with all image type columns to define which |
108
|
|
|
* columns should be cleaned-up. |
109
|
|
|
* |
110
|
|
|
* @return array The columns that has to be cleaned-up |
111
|
|
|
*/ |
112
|
|
|
public function getCleanUpColumns() |
113
|
|
|
{ |
114
|
|
|
|
115
|
|
|
// initialize the array for the columns that has to be cleaned-up |
116
|
|
|
$cleanUpColumns = array(); |
117
|
|
|
|
118
|
|
|
// query whether or not an array has been specified in the configuration |
119
|
|
|
if ($this->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS)) { |
120
|
|
|
$cleanUpColumns = $this->getConfiguration()->getParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// return the array with the column names |
124
|
|
|
return $cleanUpColumns; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
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.