Skip to content

Commit

Permalink
Add filter for schema file path as well
Browse files Browse the repository at this point in the history
  • Loading branch information
pwtyler committed Dec 4, 2024
1 parent e16b8f4 commit b238090
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions includes/class-solrpower-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,25 @@ function submit_schema() {
/*
* Solarium does not currently support submitting schemas to the server.
* So we'll do it ourselves.
* Let's check for a custom Schema.xml. It MUST be located in
* wp-content/uploads/solr-for-wordpress-on-pantheon/schema.xml.
* Let's check for a custom Schema.xml. It defaults to
* wp-content/uploads/solr-for-wordpress-on-pantheon/schema.xml
* and can be overridden with the filter 'solr_power_customer_schema_file_path'.
*/

$schema = SOLR_POWER_PATH . '/schema.xml';
$upload_dir = wp_upload_dir();
$custom_schema_file = path_join( $upload_dir['basedir'], 'solr-for-wordpress-on-pantheon/schema.xml' );
if ( file_exists( $custom_schema_file ) ) {
$custom_schema_file_path = path_join( $upload_dir['basedir'], 'solr-for-wordpress-on-pantheon/schema.xml' );

/**
* Filter the custom schema file path
*
* @param string $custom_schema_file_path The default message.
*/
$custom_schema_file_path = apply_filters( 'solr_power_customer_schema_file_path', $custom_schema_file_path );

if ( file_exists( $custom_schema_file_path ) ) {
error_log( 'Solr Power: Uploading Schema from custom location' );
$schema = $custom_schema_file;
$schema = $custom_schema_file_path;
}

$path = $this->compute_path();
Expand Down Expand Up @@ -162,7 +171,7 @@ function submit_schema() {
if ( 200 === (int) $curl_opts['http_code'] ) {
// Schema Upload Success.
$return_value = 'Schema Upload Success: ' . $curl_opts['http_code'];
if ( $schema == $custom_schema_file ) {
if ( $schema == $custom_schema_file_path ) {
$return_value = 'Custom ' . $return_value;
}
return $return_value;
Expand Down

0 comments on commit b238090

Please sign in to comment.