@@ -173,7 +173,7 @@ public function exec($context, $post_data = null, $custom_request = null)
173
173
{
174
174
$ url = $ this ->createUrlByContext ($ context );
175
175
176
- $ this ->log ->addDebug ("Curl $ url JsonData= " .$ post_data );
176
+ $ this ->log ->addInfo ("Curl $ custom_request : $ url JsonData= " .$ post_data );
177
177
178
178
$ ch = curl_init ();
179
179
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
@@ -192,6 +192,10 @@ public function exec($context, $post_data = null, $custom_request = null)
192
192
curl_setopt ($ ch , CURLOPT_POST , true );
193
193
curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ post_data );
194
194
}
195
+ } else {
196
+ if (!is_null ($ custom_request ) && $ custom_request == 'DELETE ' ) {
197
+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'DELETE ' );
198
+ }
195
199
}
196
200
197
201
$ this ->authorization ($ ch );
@@ -493,4 +497,81 @@ public function toHttpQueryParameter($paramArray)
493
497
494
498
return $ queryParam ;
495
499
}
500
+
501
+ /**
502
+ * download and save into outDir
503
+ *
504
+ * @param $url full url
505
+ * @param $outDir save dir
506
+ * @param $file save filename
507
+ * @return bool|mixed
508
+ * @throws JiraException
509
+ */
510
+ public function download ($ url , $ outDir , $ file )
511
+ {
512
+ $ file = fopen ($ outDir .DIRECTORY_SEPARATOR .$ file , 'w ' );
513
+
514
+ $ ch = curl_init ();
515
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
516
+ curl_setopt ($ ch , CURLOPT_URL , $ url );
517
+
518
+ // output to file handle
519
+ curl_setopt ($ ch , CURLOPT_FILE , $ file );
520
+
521
+ $ this ->authorization ($ ch );
522
+
523
+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , $ this ->getConfiguration ()->isCurlOptSslVerifyHost ());
524
+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , $ this ->getConfiguration ()->isCurlOptSslVerifyPeer ());
525
+
526
+ // curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set
527
+ if (!function_exists ('ini_get ' ) || !ini_get ('open_basedir ' )) {
528
+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
529
+ }
530
+
531
+ curl_setopt ($ ch , CURLOPT_HTTPHEADER ,
532
+ ['Accept: */* ' , 'Content-Type: application/json ' , 'X-Atlassian-Token: no-check ' ]);
533
+
534
+ curl_setopt ($ ch , CURLOPT_VERBOSE , $ this ->getConfiguration ()->isCurlOptVerbose ());
535
+
536
+ $ this ->log ->addDebug ('Curl exec= ' .$ url );
537
+ $ response = curl_exec ($ ch );
538
+
539
+ // if request failed.
540
+ if (!$ response ) {
541
+ $ this ->http_response = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
542
+ $ body = curl_error ($ ch );
543
+ curl_close ($ ch );
544
+ fclose ($ file );
545
+
546
+ /*
547
+ * 201: The request has been fulfilled, resulting in the creation of a new resource.
548
+ * 204: The server successfully processed the request, but is not returning any content.
549
+ */
550
+ if ($ this ->http_response === 204 || $ this ->http_response === 201 ) {
551
+ return true ;
552
+ }
553
+
554
+ // HostNotFound, No route to Host, etc Network error
555
+ $ msg = sprintf ('CURL Error: http response=%d, %s ' , $ this ->http_response , $ body );
556
+
557
+ $ this ->log ->addError ($ msg );
558
+
559
+ throw new JiraException ($ msg );
560
+ } else {
561
+ // if request was ok, parsing http response code.
562
+ $ this ->http_response = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
563
+
564
+ curl_close ($ ch );
565
+ fclose ($ file );
566
+
567
+ // don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION
568
+ if ($ this ->http_response != 200 && $ this ->http_response != 201 ) {
569
+ throw new JiraException ('CURL HTTP Request Failed: Status Code : '
570
+ .$ this ->http_response .', URL: ' .$ url
571
+ ."\nError Message : " .$ response , $ this ->http_response );
572
+ }
573
+ }
574
+
575
+ return $ response ;
576
+ }
496
577
}
0 commit comments