1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Converter\Plugins\GenericExportableConverterPlugin |
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 2019 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-converter |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Converter\Plugins; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\CacheKeys; |
24
|
|
|
use TechDivision\Import\ApplicationInterface; |
25
|
|
|
use TechDivision\Import\Converter\Utils\ConfigurationKeys; |
26
|
|
|
use TechDivision\Import\Plugins\SubjectPlugin; |
27
|
|
|
use TechDivision\Import\Plugins\ExportableTrait; |
28
|
|
|
use TechDivision\Import\Plugins\ExportablePluginInterface; |
29
|
|
|
use TechDivision\Import\Services\RegistryProcessorInterface; |
30
|
|
|
use TechDivision\Import\Subjects\SubjectExecutorInterface; |
31
|
|
|
use TechDivision\Import\Subjects\FileResolver\FileResolverFactoryInterface; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Plugin that exports artefacts with type names defined in configuration. |
35
|
|
|
* |
36
|
|
|
* @author Tim Wagner <[email protected]> |
37
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
38
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
39
|
|
|
* @link https://github.com/techdivision/import-converter |
40
|
|
|
* @link http://www.techdivision.com |
41
|
|
|
*/ |
42
|
|
|
class GenericExportableConverterPlugin extends SubjectPlugin implements ExportablePluginInterface |
43
|
|
|
{ |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The trait that provides export functionality. |
47
|
|
|
* |
48
|
|
|
* @var \TechDivision\Import\Plugins\ExportableTrait |
49
|
|
|
*/ |
50
|
|
|
use ExportableTrait; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The registry processor instance. |
54
|
|
|
* |
55
|
|
|
* @var \TechDivision\Import\Services\RegistryProcessorInterface |
56
|
|
|
*/ |
57
|
|
|
protected $registryProcessor; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Initializes the plugin with the application instance. |
61
|
|
|
* |
62
|
|
|
* @param \TechDivision\Import\ApplicationInterface $application The application instance |
63
|
|
|
* @param \TechDivision\Import\Subjects\SubjectExecutorInterface $subjectExecutor The subject executor instance |
64
|
|
|
* @param \TechDivision\Import\Subjects\FileResolver\FileResolverFactoryInterface $fileResolverFactory The file resolver instance |
65
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
66
|
|
|
*/ |
67
|
|
|
public function __construct( |
68
|
|
|
ApplicationInterface $application, |
69
|
|
|
SubjectExecutorInterface $subjectExecutor, |
70
|
|
|
FileResolverFactoryInterface $fileResolverFactory, |
71
|
|
|
RegistryProcessorInterface $registryProcessor |
72
|
|
|
) { |
73
|
|
|
|
74
|
|
|
// call the parent constructor |
75
|
|
|
parent::__construct($application, $subjectExecutor, $fileResolverFactory); |
76
|
|
|
|
77
|
|
|
// set the subject executor and the file resolver factory |
78
|
|
|
$this->registryProcessor = $registryProcessor; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns the array with the exportable artefact types from the configuration. |
83
|
|
|
* |
84
|
|
|
* @return array The artefact types |
85
|
|
|
*/ |
86
|
|
|
protected function getExportableArtefactTypes() |
87
|
|
|
{ |
88
|
|
|
|
89
|
|
|
// query whether or not the configuration value is available |
90
|
|
|
if ($this->getPluginConfiguration()->hasParam(ConfigurationKeys::EXPORTABLE_ARTEFACT_TYPES)) { |
91
|
|
|
return $this->getPluginConfiguration()->getParam(ConfigurationKeys::EXPORTABLE_ARTEFACT_TYPES); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// return an empty array if the param has NOT been set |
95
|
|
|
return array(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Return's the artefacts for post-processing. |
100
|
|
|
* |
101
|
|
|
* @return array The artefacts |
102
|
|
|
*/ |
103
|
|
|
public function getArtefacts() |
104
|
|
|
{ |
105
|
|
|
|
106
|
|
|
// load the available artefacts |
107
|
|
|
$artefacts = $this->registryProcessor->getAttribute(CacheKeys::ARTEFACTS); |
108
|
|
|
|
109
|
|
|
// initialize the array for the artefacts that has to be exported |
110
|
|
|
$toExport = array(); |
111
|
|
|
|
112
|
|
|
// load the artefacts that has to be exported |
113
|
|
|
foreach ($this->getExportableArtefactTypes() as $exportableArtefactType) { |
114
|
|
|
if (isset($artefacts[$exportableArtefactType]) && is_array($artefacts[$exportableArtefactType])) { |
115
|
|
|
$toExport[$exportableArtefactType] = $artefacts[$exportableArtefactType]; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// return the array with the exportable artefac types |
120
|
|
|
return $toExport; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Return's the target directory for the artefact export. |
125
|
|
|
* |
126
|
|
|
* @return string The target directory for the artefact export |
127
|
|
|
*/ |
128
|
|
|
public function getTargetDir() |
129
|
|
|
{ |
130
|
|
|
return sprintf('%s/%s', $this->getConfiguration()->getTargetDir(), $this->getSerial()); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Reset the array with the artefacts to free the memory. |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
public function resetArtefacts() |
139
|
|
|
{ |
140
|
|
|
// do nothing here, because we can't remove only one key from the array with artefacts in a multiprocess compatible manner |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|