@@ -57,6 +57,24 @@ private function convertLogLevel($log_level) {
5757 return Logger::INFO ;
5858 }
5959
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+
6078 public function __construct ($ config )
6179 {
6280 $ this ->json_mapper = new \JsonMapper ();
@@ -102,11 +120,11 @@ public function exec($context, $post_data = null, $custom_request = null) {
102120 if (!is_null ($ post_data )) {
103121 // PUT REQUEST
104122 if (!is_null ($ custom_request ) && $ custom_request == "PUT " ) {
105- curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , "PUT " );
123+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "PUT " );
106124 curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ post_data );
107125 }
108126 if (!is_null ($ custom_request ) && $ custom_request == "DELETE " ) {
109- curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , "DELETE " );
127+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "DELETE " );
110128 }
111129 else {
112130 curl_setopt ($ ch , CURLOPT_POST , true );
@@ -130,8 +148,15 @@ public function exec($context, $post_data = null, $custom_request = null) {
130148
131149 // if request failed.
132150 if (!$ response ) {
151+ $ this ->http_response = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
133152 $ body = curl_error ($ ch );
134153 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+
135160 // HostNotFound, No route to Host, etc Network error
136161 $ this ->log ->addError ("CURL Error: = " . $ body );
137162 throw new JIRAException ("CURL Error: = " . $ body );
@@ -173,11 +198,13 @@ public function upload($context, $upload_file) {
173198 'file' => '@' . realpath($upload_file)
174199 );
175200 */
176- $ attachments = new \CURLFile (realpath ($ upload_file ));
201+ $ attachments = realpath ($ upload_file );
202+ $ filename = basename ($ upload_file );
177203
178204 // send file
179205 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 ));
181208
182209 curl_setopt ($ ch , CURLOPT_USERPWD , "$ this ->username : $ this ->password " );
183210
@@ -198,9 +225,16 @@ public function upload($context, $upload_file) {
198225 $ response = curl_exec ($ ch );
199226
200227 // if request failed.
201- if (!$ response ) {
228+ if (!$ response ) {
229+ $ this ->http_response = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
202230 $ body = curl_error ($ ch );
203231 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+
204238 // HostNotFound, No route to Host, etc Network error
205239 $ this ->log ->addError ("CURL Error: = " . $ body );
206240 throw new JIRAException ("CURL Error: = " . $ body );
0 commit comments