@@ -171,16 +171,6 @@ function pantheon_apachesolr_platform_detected() {
171171 return isset($_ENV['PANTHEON_ENVIRONMENT']);
172172}
173173
174- /**
175- * Return the path to the directory containing the certificates.
176- */
177- function pantheon_apachesolr_certs_dir() {
178- if (pantheon_apachesolr_platform_detected()) {
179- return $_ENV['HOME'] . '/certs';
180- }
181- return './';
182- }
183-
184174/**
185175 * Display an error message if not running on the Pantheon platform.
186176 */
@@ -224,7 +214,7 @@ function pantheon_apachesolr_post_schema_exec($schema) {
224214
225215 $url = 'https://'. $host .'/'. $path;
226216
227- list($ch, $opts) = pantheon_curl_setup ($url, NULL, PANTHEON_APACHESOLR_PORT, NULL );
217+ list($ch, $opts) = pantheon_apachesolr_curl_setup ($url, PANTHEON_APACHESOLR_PORT);
228218
229219 $file = fopen($schema, 'r');
230220 // set (or override) remaining headers
@@ -368,7 +358,7 @@ function pantheon_apachesolr_query_submit($form, &$form_state) {
368358 $path = 'sites/self/environments/'. variable_get('pantheon_environment', 'dev') .'/index';
369359 $url = 'https://'. $host .'/'. $path . $form_state['values']['query'];
370360
371- list($ch, $opts) = pantheon_curl_setup ($url, NULL, PANTHEON_APACHESOLR_PORT, NULL );
361+ list($ch, $opts) = pantheon_apachesolr_curl_setup ($url, PANTHEON_APACHESOLR_PORT);
372362 $opts = pantheon_apachesolr_curlopts($opts);
373363 $opts[CURLOPT_HEADER] = 0;
374364
@@ -548,7 +538,7 @@ function pantheon_apachesolr_status($form, &$form_state) {
548538
549539 $url = 'https://'. $host . '/' . $path;
550540
551- list($ch, $opts) = pantheon_curl_setup ($url, NULL, PANTHEON_APACHESOLR_PORT, NULL );
541+ list($ch, $opts) = pantheon_apachesolr_curl_setup ($url, PANTHEON_APACHESOLR_PORT);
552542
553543 $opts = pantheon_apachesolr_curlopts($opts);
554544 $opts[CURLOPT_CONNECTTIMEOUT] = 5;
@@ -620,7 +610,7 @@ function pantheon_apachesolr_status($form, &$form_state) {
620610 $url = 'https://'. $host . '/' . $path;
621611
622612 $opts = array();
623- list($ch, $opts) = pantheon_curl_setup ($url, NULL, PANTHEON_APACHESOLR_PORT, NULL );
613+ list($ch, $opts) = pantheon_apachesolr_curl_setup ($url, PANTHEON_APACHESOLR_PORT);
624614
625615 unset($opts[CURLOPT_HTTPHEADER]);
626616 $opts[CURLOPT_CONNECTTIMEOUT] = 5;
@@ -719,7 +709,7 @@ function pantheon_apachesolr_requirements($phase) {
719709
720710 $url = 'https://'. $host . '/' . $path;
721711
722- list($ch, $opts) = pantheon_curl_setup ($url, NULL, PANTHEON_APACHESOLR_PORT, NULL );
712+ list($ch, $opts) = pantheon_apachesolr_curl_setup ($url, PANTHEON_APACHESOLR_PORT);
723713 $opts = pantheon_apachesolr_curlopts($opts);
724714
725715
@@ -759,3 +749,39 @@ function pantheon_apachesolr_requirements($phase) {
759749 }
760750 return $requirements;
761751}
752+
753+ /**
754+ * Initializes a cURL handle with default options, or delegates to Pantheon's
755+ * `pantheon_curl_setup()` if available.
756+ *
757+ * When running on the Pantheon platform, this function uses the pre-configured
758+ * `pantheon_curl_setup()` logic. Otherwise, it sets up a basic cURL handle with
759+ * common defaults for communicating with Apache Solr.
760+ *
761+ * @param string $url The URL to set via CURLOPT_URL.
762+ * @param int $port The port to set via CURLOPT_PORT.
763+ *
764+ * @return array{0: resource, 1: array} An array containing the initialized cURL handle
765+ * and an array of the options applied.
766+ */
767+ function pantheon_apachesolr_curl_setup($url, $port) {
768+ // If on pantheon, handled in prepend...
769+ if (function_exists("pantheon_curl_setup")) {
770+ return pantheon_curl_setup($url, NULL, $port, NULL);
771+ }
772+
773+ // create a new cURL resource
774+ $ch = curl_init();
775+
776+ // default options for most cases
777+ $opts = array(
778+ CURLOPT_URL => $url,
779+ CURLOPT_HEADER => 1,
780+ CURLOPT_PORT => $port,
781+ CURLOPT_RETURNTRANSFER => 1,
782+ CURLOPT_HTTPHEADER => array('Content-Type: application/json', 'X-Ignore-Agent: 1'),
783+ );
784+
785+ curl_setopt_array($ch, $opts);
786+ return array($ch, $opts);
787+ }
0 commit comments