@@ -57,6 +57,24 @@ private function convertLogLevel($log_level) {
57
57
return Logger::INFO ;
58
58
}
59
59
60
+ // serilize only not null field.
61
+ protected function filterNullVariable ($ haystack )
62
+ {
63
+ foreach ($ haystack as $ key => $ value ) {
64
+ if (is_array ($ value ) ) {
65
+ $ haystack [$ key ] = $ this ->filterNullVariable ($ haystack [$ key ]);
66
+ } else if (is_object ($ value )) {
67
+ $ haystack [$ key ] = $ this ->filterNullVariable (get_class_vars (get_class ($ value )));
68
+ }
69
+
70
+ if (is_null ($ haystack [$ key ]) || empty ($ haystack [$ key ])) {
71
+ unset($ haystack [$ key ]);
72
+ }
73
+ }
74
+
75
+ return $ haystack ;
76
+ }
77
+
60
78
public function __construct ($ config )
61
79
{
62
80
$ this ->json_mapper = new \JsonMapper ();
@@ -102,11 +120,11 @@ public function exec($context, $post_data = null, $custom_request = null) {
102
120
if (!is_null ($ post_data )) {
103
121
// PUT REQUEST
104
122
if (!is_null ($ custom_request ) && $ custom_request == "PUT " ) {
105
- curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , "PUT " );
123
+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "PUT " );
106
124
curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ post_data );
107
125
}
108
126
if (!is_null ($ custom_request ) && $ custom_request == "DELETE " ) {
109
- curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , "DELETE " );
127
+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "DELETE " );
110
128
}
111
129
else {
112
130
curl_setopt ($ ch , CURLOPT_POST , true );
@@ -130,8 +148,15 @@ public function exec($context, $post_data = null, $custom_request = null) {
130
148
131
149
// if request failed.
132
150
if (!$ response ) {
151
+ $ this ->http_response = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
133
152
$ body = curl_error ($ ch );
134
153
curl_close ($ ch );
154
+
155
+ //The server successfully processed the request, but is not returning any content.
156
+ if ($ this ->http_response == 204 ){
157
+ return "" ;
158
+ }
159
+
135
160
// HostNotFound, No route to Host, etc Network error
136
161
$ this ->log ->addError ("CURL Error: = " . $ body );
137
162
throw new JIRAException ("CURL Error: = " . $ body );
@@ -173,11 +198,13 @@ public function upload($context, $upload_file) {
173
198
'file' => '@' . realpath($upload_file)
174
199
);
175
200
*/
176
- $ attachments = new \CURLFile (realpath ($ upload_file ));
201
+ $ attachments = realpath ($ upload_file );
202
+ $ filename = basename ($ upload_file );
177
203
178
204
// send file
179
205
curl_setopt ($ ch , CURLOPT_POST , true );
180
- curl_setopt ($ ch , CURLOPT_POSTFIELDS , array ('file ' => $ attachments ));
206
+ curl_setopt ($ ch , CURLOPT_POSTFIELDS ,
207
+ array ('file ' => '@ ' . $ attachments . ';filename= ' . $ filename ));
181
208
182
209
curl_setopt ($ ch , CURLOPT_USERPWD , "$ this ->username : $ this ->password " );
183
210
@@ -198,9 +225,16 @@ public function upload($context, $upload_file) {
198
225
$ response = curl_exec ($ ch );
199
226
200
227
// if request failed.
201
- if (!$ response ) {
228
+ if (!$ response ) {
229
+ $ this ->http_response = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
202
230
$ body = curl_error ($ ch );
203
231
curl_close ($ ch );
232
+
233
+ //The server successfully processed the request, but is not returning any content.
234
+ if ($ this ->http_response == 204 ){
235
+ return "" ;
236
+ }
237
+
204
238
// HostNotFound, No route to Host, etc Network error
205
239
$ this ->log ->addError ("CURL Error: = " . $ body );
206
240
throw new JIRAException ("CURL Error: = " . $ body );
0 commit comments