|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Modules\PluginModule |
|
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 |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Modules; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\ApplicationInterface; |
|
24
|
|
|
use TechDivision\Import\ConfigurationManagerInterface; |
|
25
|
|
|
use TechDivision\Import\Plugins\PluginExecutorInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* A module implementation that provides plug-in functionality. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2019 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 |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
|
class PluginModule implements ModuleInterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The application instance. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \TechDivision\Import\ApplicationInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $application; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The plugin executor instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @var \TechDivision\Import\Plugins\PluginExecutorInterface |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $pluginExecutor; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* The configuration manager instance. |
|
55
|
|
|
* |
|
56
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $configurationManager; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Initializes the module with the application, configuration and plug-in executor instance. |
|
62
|
|
|
* |
|
63
|
|
|
* @param \TechDivision\Import\ApplicationInterface $application The application instance |
|
64
|
|
|
* @param \TechDivision\Import\ConfigurationManagerInterface $configurationManager The configuration manager instance |
|
65
|
|
|
* @param \TechDivision\Import\Plugins\PluginExecutorInterface $pluginExecutor The plug-in executor instance |
|
66
|
|
|
*/ |
|
67
|
|
|
public function __construct( |
|
68
|
|
|
ApplicationInterface $application, |
|
69
|
|
|
ConfigurationManagerInterface $configurationManager, |
|
70
|
|
|
PluginExecutorInterface $pluginExecutor |
|
71
|
|
|
) { |
|
72
|
|
|
|
|
73
|
|
|
// initialize the application, the configuration and the plugin executor |
|
74
|
|
|
$this->application = $application; |
|
75
|
|
|
$this->configurationManager = $configurationManager; |
|
|
|
|
|
|
76
|
|
|
$this->pluginExecutor = $pluginExecutor; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Return's the application instance. |
|
81
|
|
|
* |
|
82
|
|
|
* @return \TechDivision\Import\ApplicationInterface The application instance |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function getApplication() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->application; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Return's the configuration manager instance. |
|
91
|
|
|
* |
|
92
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration manager instance |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function getConfigurationManager() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->configurationManager; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Return's the plug-in executor instance. |
|
101
|
|
|
* |
|
102
|
|
|
* @return \TechDivision\Import\Plugins\PluginExecutorInterface The plug-in executor instance |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function getPluginExecutor() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->pluginExecutor; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Persist the UUID of the actual import process to the PID file. |
|
111
|
|
|
* |
|
112
|
|
|
* @return void |
|
113
|
|
|
* @throws \Exception Is thrown, if the PID can not be added |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function lock() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->getApplication()->lock(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Remove's the UUID of the actual import process from the PID file. |
|
122
|
|
|
* |
|
123
|
|
|
* @return void |
|
124
|
|
|
* @throws \Exception Is thrown, if the PID can not be removed |
|
125
|
|
|
*/ |
|
126
|
|
|
protected function unlock() |
|
127
|
|
|
{ |
|
128
|
|
|
$this->getApplication()->unlock(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Inovkes the plug-in functionality. |
|
133
|
|
|
* |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
|
|
public function process() |
|
137
|
|
|
{ |
|
138
|
|
|
try { |
|
139
|
|
|
// immediately add the PID to lock this import process |
|
140
|
|
|
$this->lock(); |
|
141
|
|
|
// process the plugins defined in the configuration |
|
142
|
|
|
/** @var \TechDivision\Import\Configuration\PluginConfigurationInterface $pluginConfiguration */ |
|
143
|
|
|
foreach ($this->getConfigurationManager()->getPlugins() as $pluginConfiguration) { |
|
|
|
|
|
|
144
|
|
|
// query whether or not the operation has been stopped |
|
145
|
|
|
if ($this->getApplication()->isStopped()) { |
|
146
|
|
|
break; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
// execute the plugin instance |
|
150
|
|
|
$this->getPluginExecutor()->execute($pluginConfiguration); |
|
151
|
|
|
} |
|
152
|
|
|
} catch (\Exception $e) { |
|
153
|
|
|
// re-throw the exception |
|
154
|
|
|
throw $e; |
|
155
|
|
|
} finally { |
|
156
|
|
|
// finally, if a PID has been set, remove it |
|
157
|
|
|
// from the PID file to unlock the importer |
|
158
|
|
|
$this->unlock(); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..