1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Item; |
4
|
|
|
|
5
|
|
|
use Akeneo\Bundle\BatchBundle\Entity\StepExecution; |
6
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
7
|
|
|
use Akeneo\Bundle\BatchBundle\Item\AbstractConfigurableStepElement; |
8
|
|
|
use Akeneo\Bundle\BatchBundle\Step\StepExecutionAwareInterface; |
9
|
|
|
use Actualys\Bundle\DrupalCommerceConnectorBundle\Webservice\Webservice; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DrupalItemStep |
13
|
|
|
* |
14
|
|
|
* @package Actualys\Bundle\DrupalCommerceConnectorBundle\Item |
15
|
|
|
* |
16
|
|
|
*/ |
17
|
|
|
abstract class DrupalItemStep extends AbstractConfigurableStepElement implements StepExecutionAwareInterface |
18
|
|
|
{ |
19
|
|
|
/** @var StepExecution */ |
20
|
|
|
protected $stepExecution; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
* @Assert\NotBlank(groups={"Execution"}) |
25
|
|
|
*/ |
26
|
|
|
protected $baseUrl; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
* @Assert\NotBlank(groups={"Execution"}) |
31
|
|
|
*/ |
32
|
|
|
protected $endpoint; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
* @Assert\NotBlank(groups={"Execution"}) |
37
|
|
|
*/ |
38
|
|
|
protected $resourcePath; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string Http login |
42
|
|
|
* @Assert\NotBlank(groups={"Execution"}) |
43
|
|
|
*/ |
44
|
|
|
protected $httpLogin; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string Http password |
48
|
|
|
* @Assert\NotBlank(groups={"Execution"}) |
49
|
|
|
*/ |
50
|
|
|
protected $httpPassword; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var Webservice webservice |
54
|
|
|
*/ |
55
|
|
|
protected $webservice; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Function called before all item step execution |
59
|
|
|
*/ |
60
|
|
|
public function initialize() |
61
|
|
|
{ |
62
|
|
|
if ($this->webservice) { |
63
|
|
|
$this->webservice->setParameters($this->getClientParameters()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Webservice $webservice |
69
|
|
|
*/ |
70
|
|
|
public function setWebservice(Webservice $webservice) |
71
|
|
|
{ |
72
|
|
|
$this->webservice = $webservice; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return Webservice |
77
|
|
|
*/ |
78
|
|
|
public function getWebservice() |
79
|
|
|
{ |
80
|
|
|
return $this->webservice; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the drupal rest client parameters |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
protected function getClientParameters() |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
'base_url' => $this->baseUrl, |
92
|
|
|
'endpoint' => $this->endpoint, |
93
|
|
|
'resource_path' => $this->resourcePath, |
94
|
|
|
'user' => $this->httpLogin, |
95
|
|
|
'pwd' => $this->httpPassword, |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get fields for the twig |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
|
public function getConfigurationFields() |
105
|
|
|
{ |
106
|
|
|
return [ |
107
|
|
|
'baseUrl' => [ |
108
|
|
|
'options' => [ |
109
|
|
|
'required' => true, |
110
|
|
|
'help' => 'actualys_drupal_commerce_connector.export.baseUrl.help', |
111
|
|
|
'label' => 'actualys_drupal_commerce_connector.export.baseUrl.label', |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
'endpoint' => [ |
115
|
|
|
'options' => [ |
116
|
|
|
'required' => true, |
117
|
|
|
'help' => 'actualys_drupal_commerce_connector.export.endpoint.help', |
118
|
|
|
'label' => 'actualys_drupal_commerce_connector.export.endpoint.label', |
119
|
|
|
], |
120
|
|
|
], |
121
|
|
|
'resourcePath' => [ |
122
|
|
|
'options' => [ |
123
|
|
|
'required' => true, |
124
|
|
|
'help' => 'actualys_drupal_commerce_connector.export.resourcePath.help', |
125
|
|
|
'label' => 'actualys_drupal_commerce_connector.export.resourcePath.label', |
126
|
|
|
], |
127
|
|
|
], |
128
|
|
|
'httpLogin' => [ |
129
|
|
|
'options' => [ |
130
|
|
|
'required' => false, |
131
|
|
|
'help' => 'actualys_drupal_commerce_connector.export.httpLogin.help', |
132
|
|
|
'label' => 'actualys_drupal_commerce_connector.export.httpLogin.label', |
133
|
|
|
], |
134
|
|
|
], |
135
|
|
|
'httpPassword' => [ |
136
|
|
|
'options' => [ |
137
|
|
|
'required' => false, |
138
|
|
|
'help' => 'actualys_drupal_commerce_connector.export.httpPassword.help', |
139
|
|
|
'label' => 'actualys_drupal_commerce_connector.export.httpPassword.label', |
140
|
|
|
], |
141
|
|
|
] |
142
|
|
|
]; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getHttpLogin() |
149
|
|
|
{ |
150
|
|
|
return $this->httpLogin; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param string $httpLogin |
155
|
|
|
*/ |
156
|
|
|
public function setHttpLogin($httpLogin) |
157
|
|
|
{ |
158
|
|
|
$this->httpLogin = $httpLogin; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function getHttpPassword() |
165
|
|
|
{ |
166
|
|
|
return $this->httpPassword; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $httpPassword |
171
|
|
|
*/ |
172
|
|
|
public function setHttpPassword($httpPassword) |
173
|
|
|
{ |
174
|
|
|
$this->httpPassword = $httpPassword; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param StepExecution $stepExecution |
179
|
|
|
*/ |
180
|
|
|
public function setStepExecution(StepExecution $stepExecution) |
181
|
|
|
{ |
182
|
|
|
$this->stepExecution = $stepExecution; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function getBaseUrl() |
189
|
|
|
{ |
190
|
|
|
return $this->baseUrl; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string $baseUrl |
195
|
|
|
*/ |
196
|
|
|
public function setBaseUrl($baseUrl) |
197
|
|
|
{ |
198
|
|
|
$this->baseUrl = $baseUrl; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return string |
203
|
|
|
*/ |
204
|
|
|
public function getResourcePath() |
205
|
|
|
{ |
206
|
|
|
return $this->resourcePath; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param string $resourcePath |
211
|
|
|
*/ |
212
|
|
|
public function setResourcePath($resourcePath) |
213
|
|
|
{ |
214
|
|
|
$this->resourcePath = $resourcePath; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return string |
219
|
|
|
*/ |
220
|
|
|
public function getEndpoint() |
221
|
|
|
{ |
222
|
|
|
return $this->endpoint; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param string $endpoint |
227
|
|
|
*/ |
228
|
|
|
public function setEndpoint($endpoint) |
229
|
|
|
{ |
230
|
|
|
$this->endpoint = $endpoint; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|