diff --git a/.codacy.yml b/.codacy.yml new file mode 100644 index 00000000..9ac9391d --- /dev/null +++ b/.codacy.yml @@ -0,0 +1,5 @@ +--- +exclude_paths: + - RoboFile.php + - .github/workflows/ci.yml + - .github/workflows/create-branch-on-tag.yml \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 9c620965..d8330229 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,5 @@ /circle.yml export-ignore /.gitattributes export-ignore /.gitignore export-ignore +/codacy.yml export-ignore +/phpcs.xml export-ignore \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dfe4a723..15b86fd1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,7 @@ jobs: SANDBOX_SSH_KEY: ${{ secrets.SANDBOX_SSH_KEY }} BASH_ENV: ~/.bashrc steps: + - name: Checkout uses: actions/checkout@v2 @@ -38,18 +39,21 @@ jobs: - name: Code sniff run: composer run-script code:lint + phpcompatibility: runs-on: ubuntu-latest name: PHP Compatibility steps: + - name: PHPCompatibility uses: pantheon-systems/phpcompatibility-action@v1 with: - test-versions: 7.4- + test-versions: 8.1 + build_test: strategy: matrix: - drupal-version: [ 10 ] + drupal-version: [ 10, 11 ] fail-fast: false runs-on: ubuntu-latest container: @@ -70,6 +74,7 @@ jobs: BASH_ENV: ~/.bashrc DRUPAL_VERSION: ${{ matrix.drupal-version }} steps: + - name: Checkout uses: actions/checkout@v2 @@ -106,6 +111,7 @@ jobs: if: ${{ always() }} run: | ./vendor/bin/robo test:delete-sites + mirror_do: runs-on: ubuntu-latest name: Checkout & push to remote @@ -116,16 +122,19 @@ jobs: WORKSPACE: ${{ github.workspace }} DRUPAL_ORG_REMOTE: ${{ secrets.DRUPAL_ORG_REMOTE }} steps: + - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 + - name: Install SSH key uses: shimataro/ssh-key-action@v2 with: key: ${{ secrets.SSH_KEY }} known_hosts: ${{ secrets.KNOWN_HOSTS }} if_key_exists: ignore + - name: Pushes to drupal.org repository run: | cd $WORKSPACE diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f80bc9cd..9c9eff16 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,10 @@ +Search API Patheon 8.3.0 +-------------------------------------------------- +- Compatible with Pantheon Search (Solr 8) +- Compatible with Drupal 10.x +- Versions of Drupal less than 10 are not supported. +- Versions of PHP less than 8.1 are not supported + Search API Patheon 8.x-8.x-alpha1 -------------------------------------------------- - Compatible with Pantheon Search (Solr 8) diff --git a/RoboFile.php b/RoboFile.php index b953004d..40c252ae 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -12,6 +12,9 @@ use Robo\Tasks; use Symfony\Component\Process\Process; use Symfony\Component\Yaml\Yaml; +use Symfony\Component\Finder\Finder; + +define('STATUS_JQ_FILTER', 'jq -r \'.pantheon_search.status\''); /** * RoboFile is the main entry point for Robo commands. @@ -30,12 +33,77 @@ class RoboFile extends Tasks { */ public DateTime $started; + public array $search_index; + public array $search_server; + /** * Class constructor. */ public function __construct() { $this->started = new DateTime(); require_once 'vendor/autoload.php'; + $this->getInstallConfigs(); + } + + public function test() { + $this->output()->writeln('RoboFile constructor: ' . $this->started->format('Y-m-d H:i:s')); + $this->output()->writeln('Search index: ' . print_r($this->search_index, TRUE)); + $this->output()->writeln('Search server: ' . print_r($this->search_server, TRUE)); + $this->output()->writeln('Hello world!'); + } + + public function getInstallConfigs(): void { + $finder = new Finder(); + try { + $finder->files() + ->in('./config/install') + ->name(['*.yml', '*.yaml']) + ->sortByName(); + if (!$finder->hasResults()) { + throw new \RuntimeException( + 'No YAML files found in the specified directory.' + ); + } + + foreach ($finder as $file) { + $filePath = $file->getRealPath(); + $fileName = $file->getBasename('.yml'); + + // Remove .yaml extension if present + $fileName = str_replace('.yaml', '', $fileName); + + try { + switch (substr($fileName, 0, 16)) { + case 'search_api.index': + $this->search_index = Yaml::parseFile($filePath); + break; + case 'search_api.serve': + $this->search_server = Yaml::parseFile($filePath); + break; + default: + break; + } + } + catch (\Exception $e) { + throw new \RuntimeException( + sprintf( + 'Error parsing YAML file %s: %s', + $filePath, + $e->getMessage() + ) + ); + } + } + } + catch (\Exception $e) { + throw new \RuntimeException( + sprintf( + 'Error accessing directory %s: %s', + $directoryPath, + $e->getMessage() + ) + ); + } } /** @@ -58,7 +126,7 @@ public function testDeleteSites() { /** * Run the full test suite for this project. */ - public function testFull(int $drupal_version = 9, string $site_name = NULL) { + public function testFull(int $drupal_version = 10, string $site_name = NULL) { // Get the right constraint based on current branch/tag. $constraint = $this->getCurrentConstraint(); // Ensure terminus 3 is installed. @@ -72,9 +140,10 @@ public function testFull(int $drupal_version = 9, string $site_name = NULL) { $site_name = substr(\uniqid('test-'), 0, 12); if ($_SERVER['GITHUB_RUN_NUMBER']) { // Ensure that 2 almost parallel runs do not collide. - $site_name .= '-' . $drupal_version . '-'. $_SERVER['GITHUB_RUN_NUMBER']; + $site_name .= '-' . $drupal_version . '-' . $_SERVER['GITHUB_RUN_NUMBER']; } } + $options['drupal_version'] = $drupal_version; // Create site, set connection mode to git and clone it to local. $this->testCreateSite($site_name, $options); @@ -83,12 +152,6 @@ public function testFull(int $drupal_version = 9, string $site_name = NULL) { $this->testAllowPlugins($site_name, $drupal_version); $this->testPhpVersion($site_name, $drupal_version); - // If received Drupal 10, upgrade the recently created site to Drupal 10. - if ($drupal_version === 10) { - // @todo Make it downgrade to Drupal 9 when Drupal 10 becomes the default version. - $this->testUpgradeToDrupal10($site_name); - } - // Composer require the corresponding modules, push to Pantheon and install the site. $this->testRequireSolr($site_name, $constraint); $this->testGitPush($site_name); @@ -113,36 +176,35 @@ public function testFull(int $drupal_version = 9, string $site_name = NULL) { // Test all the Solr things. $this->testSolrEnabled($site_name); - - // Test creating Solr index. - $this->testSolrIndexCreate($site_name, 'dev'); - - // Test running the reload - $this->testPantheonSolrReload($site_name, 'dev'); - $this->testSolrReload($site_name, 'dev'); - // Test select query. $this->testSolrSelect($site_name, 'dev'); // Finally, run Solr diagnose. $this->testSolrDiagnose($site_name, 'dev'); - $this->output()->write( 'All done! 🎉' ); + $this->output()->write('All done! 🎉'); return ResultData::EXITCODE_OK; } /** - * Get current composer constraint depending on whether we're on a tag, a branch or a PR. + * Get current composer constraint depending on whether we're on a tag, a + * branch or a PR. */ protected function getCurrentConstraint(): string { $branch = trim(shell_exec('git rev-parse --abbrev-ref HEAD')); if ($branch !== 'HEAD') { return "{$branch}-dev"; - } else { - $tag = trim(shell_exec('git describe --exact-match --tags $(git log -n1 --pretty=\'%h\')')); + } + else { + $tag = trim( + shell_exec( + 'git describe --exact-match --tags $(git log -n1 --pretty=\'%h\')' + ) + ); if ($tag) { return $tag; - } else { + } + else { // Maybe we are on a PR. $branch = $_SERVER['GITHUB_HEAD_REF']; $branch_parts = explode('/', $branch); @@ -157,16 +219,21 @@ protected function getCurrentConstraint(): string { } /** - * Ensure terminus 3 is installed, otherwise offer installing it using Homebrew. + * Ensure terminus 3 is installed, otherwise offer installing it using + * Homebrew. */ public function testCheckT3() { - if (!file_exists(static::$TERMINUS_EXE) || !is_executable(static::$TERMINUS_EXE)) { + if (!file_exists(static::$TERMINUS_EXE) || !is_executable( + static::$TERMINUS_EXE + )) { $this->confirm( - 'This demo makes extensive use of the Terminus 3 phar. Can I install it for you using homebrew?' - ); - $result = $this->taskExec('brew install pantheon-systems/external/terminus')->run(); + 'This demo makes extensive use of the Terminus 3 phar. Can I install it for you using homebrew?' + ); + $result = $this->taskExec( + 'brew install pantheon-systems/external/terminus' + )->run(); if (!$result->wasSuccessful()) { - exit(1); + exit(ResultData::EXITCODE_ERROR); } // @todo check for build tools plugin "wait" command. } @@ -177,17 +244,25 @@ public function testCheckT3() { * Create site in Pantheon if it doesn't exist. Return site info. * * @param string $site_name - * The machine name of the site to create. + * The machine name of the site to create. * * @return \Robo\Result */ - public function testCreateSite(string $site_name, array $options = ['org' => NULL]) { + public function testCreateSite( + string $site_name, + array $options = ['org' => NULL] + ) { $site_info = $this->siteInfo($site_name); if (empty($site_info)) { $home = $_SERVER['HOME']; $toReturn = $this->taskExec(static::$TERMINUS_EXE) - ->args('site:create', $site_name, $site_name, 'drupal-composer-managed'); - if ( !empty( $options['org'] ) ) { + ->args( + 'site:create', + $site_name, + $site_name, + sprintf('drupal-%d-composer-managed', $options['drupal_version']) + ); + if (!empty($options['org'])) { $toReturn->option('org', $options['org']); } $toReturn->run(); @@ -205,24 +280,24 @@ public function testCreateSite(string $site_name, array $options = ['org' => NUL * @param string $site_name */ public function waitForWorkflow(string $site_name, string $env = 'dev') { - $this->output()->write('Checking workflow status', true); + $this->output()->write('Checking workflow status', TRUE); exec( "terminus workflow:info:status $site_name.$env", $info ); - $info = $this->cleanUpInfo( $info ); - $this->output()->write( $info['workflow'], true ); + $info = $this->cleanUpInfo($info); + $this->output()->write($info['workflow'], TRUE); // Wait for workflow to finish only if it hasn't already. This prevents the workflow:wait command from unnecessarily running for 260 seconds when there's no workflow in progress. - if ( $info['status'] !== 'succeeded' ) { - $this->output()->write('Waiting for platform', true); + if ($info['status'] !== 'succeeded') { + $this->output()->write('Waiting for platform', TRUE); exec( - "terminus build:workflow:wait --max=260 $site_name.$env", - $finished, - $status - ); + "terminus build:workflow:wait --max=260 $site_name.$env", + $finished, + $status + ); } if ($this->output()->isVerbose()) { @@ -232,30 +307,32 @@ public function waitForWorkflow(string $site_name, string $env = 'dev') { } /** - * Takes the output from a workflow:info:status command and converts it into a human-readable and easily parseable array. + * Takes the output from a workflow:info:status command and converts it into + * a human-readable and easily parseable array. * - * @param array $info Raw output from 'terminus workflow:info:status' + * @param array $info + * Raw output from 'terminus workflow:info:status' * * @return array An array of workflow status info. */ - private function cleanUpInfo( array $info ) : array { + private function cleanUpInfo(array $info): array { // Clean up the workflow status data and assign values to an array so it's easier to check. foreach ($info as $line => $value) { - $ln = array_values( array_filter( explode( " ", trim( $value ) ) ) ); + $ln = array_values(array_filter(explode(" ", trim($value)))); // Skip lines with only one value. This filters out the ASCII dividers output by the command. - if ( count( $ln ) > 1 ) { - if ( in_array( $ln[0], [ 'Started At', 'Finished At' ] ) ) { - $ln[0] = trim( str_replace( 'At', '', $ln[0] ) ); + if (count($ln) > 1) { + if (in_array($ln[0], ['Started At', 'Finished At'])) { + $ln[0] = trim(str_replace('At', '', $ln[0])); // Convert times to unix timestamps for easier use later. - $ln[1] = strtotime( $ln[1] ); + $ln[1] = strtotime($ln[1]); } - $info[ str_replace( ' ', '-', strtolower( $ln[0] ) ) ] = trim( $ln[1] ); + $info[str_replace(' ', '-', strtolower($ln[0]))] = trim($ln[1]); } // Remove the processed line. - unset( $info[ $line ] ); + unset($info[$line]); } return $info; @@ -285,7 +362,11 @@ public function setSiteSearch(string $site_name, $value = 'enable') { * @param string $connection * The connection mode to set (git/sftp). */ - public function testConnectionGit(string $site_name, string $env = 'dev', string $connection = 'git') { + public function testConnectionGit( + string $site_name, + string $env = 'dev', + string $connection = 'git' + ) { $this->taskExec('terminus') ->args('connection:set', $site_name . '.' . $env, $connection) ->run(); @@ -343,106 +424,6 @@ public function testAllowPlugins(string $site_name, int $drupal_version) { } } - /** - * Upgrade given site to Drupal 10. - * - * @param string $site_name - * The machine name of the site to downgrade. - */ - public function testUpgradeToDrupal10(string $site_name) { - $site_folder = $this->getSiteFolder($site_name); - chdir($site_folder); - - // Remove composer lock. - $this->taskExec('rm') - ->args('composer.lock') - ->run(); - - $this->taskExec('composer') - ->args( - 'config', - 'minimum-stability', - 'dev' - ) - ->run(); - - $this->taskExec('composer') - ->args( - 'config', - 'platform.php', - '8.1' - ) - ->run(); - - $this->taskExec('composer') - ->args( - 'require', - '--no-update', - 'drupal/core-recommended:^10', - 'drupal/core-project-message:^10', - 'drupal/core-composer-scaffold:^10', - 'pantheon-systems/drupal-integrations:^10', - 'mglaman/composer-drupal-lenient' - ) - ->run(); - - $this->taskExec('composer') - ->args( - 'require', - '--no-update', - '--dev', - 'drupal/core-dev:^10' - ) - ->run(); - - $this->taskExec('composer') - ->args('update') - ->run(); - - $this->taskExec('composer') - ->args( - 'config', - '--merge', - '--json', - 'extra.drupal-lenient.allowed-list', - '["drupal/search_api_pantheon"]' - ) - ->run(); - return ResultData::EXITCODE_OK; - } - - /** - * Downgrade given site to Drupal 8. - * - * @param string $site_name - * The machine name of the site to downgrade. - */ - public function testDowngradeToDrupal8(string $site_name) { - $site_folder = $this->getSiteFolder($site_name); - chdir($site_folder); - - // Remove composer lock. - $this->taskExec('rm') - ->args('composer.lock') - ->run(); - - - $this->taskExec('composer') - ->args( - 'require', - '--no-update', - '-W', - 'drupal/core-recommended:^8', - 'pantheon-systems/drupal-integrations:^8' - ) - ->run(); - - $this->taskExec('composer') - ->args('update') - ->run(); - return ResultData::EXITCODE_OK; - } - /** * Composer require the Solr related modules. * @@ -451,7 +432,10 @@ public function testDowngradeToDrupal8(string $site_name) { * @param string $constraint * The constraint to use for the search_api_pantheon module. */ - public function testRequireSolr(string $site_name, string $constraint = '^8') { + public function testRequireSolr( + string $site_name, + string $constraint = '^8' + ) { $site_folder = $this->getSiteFolder($site_name); chdir($site_folder); // Always test again latest version of search_api_solr. @@ -491,7 +475,10 @@ protected function getSiteFolder(string $site_name) { * @param string $commit_msg * The commit message to use. */ - public function testGitPush(string $site_name, string $commit_msg = 'Changes committed from demo script.') { + public function testGitPush( + string $site_name, + string $commit_msg = 'Changes committed from demo script.' + ) { $site_folder = $this->getSiteFolder($site_name); chdir($site_folder); try { @@ -530,13 +517,24 @@ public function testGitPush(string $site_name, string $commit_msg = 'Changes com * @param string $profile * The Drupal profile to use during site installation. */ - public function testSiteInstall(string $site_name, string $env = 'dev', string $profile = 'demo_umami') { + public function testSiteInstall( + string $site_name, + string $env = 'dev', + string $profile = 'demo_umami' + ) { $this->taskExec(static::$TERMINUS_EXE) - ->args('drush', $site_name . '.' . $env, '--', 'site:install', $profile, '-y') + ->args( + 'drush', + $site_name . '.' . $env, + '--', + 'site:install', + $profile, + '-y' + ) ->options([ 'account-name' => 'admin', - 'site-name' => $site_name, - 'locale' => 'en', + 'site-name' => $site_name, + 'locale' => 'en', ]) ->run(); $this->waitForWorkflow($site_name); @@ -554,55 +552,56 @@ public function testSiteInstall(string $site_name, string $env = 'dev', string $ public function testModuleEnable(string $site_name, string $env = 'dev') { $this->taskExec(static::$TERMINUS_EXE) ->args( - 'drush', - $site_name . '.' . $env, - 'cr' - ) + 'drush', + $site_name . '.' . $env, + 'cr' + ) ->run(); $this->taskExec(static::$TERMINUS_EXE) ->args( - 'drush', - $site_name . '.' . $env, - 'pm-uninstall', - 'search', - ) + 'drush', + $site_name . '.' . $env, + 'pm-uninstall', + 'search', + ) ->run(); $this->waitForWorkflow($site_name); $this->taskExec(static::$TERMINUS_EXE) ->args( - 'drush', - $site_name . '.' . $env, - '--', - 'pm-enable', - '--yes', - 'search_api_pantheon', - 'search_api_pantheon_admin', - 'search_api_solr_admin' - ) + 'drush', + $site_name . '.' . $env, + '--', + 'pm-enable', + '--yes', + 'search_api_pantheon', + 'search_api_pantheon_admin', + 'search_api_solr_admin' + ) ->run(); $this->taskExec(static::$TERMINUS_EXE) ->args( - 'drush', - $site_name . '.' . $env, - 'cr' - ) + 'drush', + $site_name . '.' . $env, + 'cr' + ) ->run(); } + /** - * Run through various diagnostics to ensure that Solr8 is enabled and working. + * Run through various diagnostics to ensure that Solr8 is enabled and + * working and an index has been created. * * @param string $site_name * The machine name of the site to run the diagnostics on. * @param string $env * The environment to run the diagnostics on. */ - public function testSolrEnabled( string $site_name, string $env = 'dev' ) { - + public function testSolrEnabled(string $site_name, string $env = 'dev') { try { // Attempt to ping the Pantheon Solr server. - $this->output()->write('Attempting to ping the Solr server...', true); - $ping = $this->taskExec( static::$TERMINUS_EXE ) + $this->output()->write('Attempting to ping the Solr server...', TRUE); + $ping = $this->taskExec(static::$TERMINUS_EXE) ->args( 'drush', "$site_name.$env", @@ -611,33 +610,50 @@ public function testSolrEnabled( string $site_name, string $env = 'dev' ) { ) ->run(); - if ( $ping instanceof Result && ! $ping->wasSuccessful() ) { - \Kint::dump( $ping ); - throw new \Exception( 'An error occurred attempting to ping Solr server' ); - } + if ($ping instanceof Result && !$ping->wasSuccessful()) { + \Kint::dump($ping); + throw new \Exception( + 'An error occurred attempting to ping Solr server' + ); + } - // Check that Solr8 is enabled. - $this->output()->write('Checking for Solr8 search API server...', true); - exec( - "terminus remote:drush $site_name.$env -- search-api-server-list | grep pantheon_solr8", - $server_list + // Check that Solr8 is enabled. + $this->output()->write('Checking for Solr8 search API server...', TRUE); + exec( + "terminus remote:drush $site_name.$env -- search-api-server-list --format=json | " . STATUS_JQ_FILTER, + $server_list, + ); + if (empty($server_list)) { + \Kint::dump($server_list); + throw new \Exception( + 'No Servers Available. The default server was not imported when the module was enabled.' + ); + } + if (stripos($server_list, 'enabled') === FALSE) { + \Kint::dump($server_list); + throw new \Exception( + 'An error occurred checking that Solr8 was enabled: ' . print_r( + $server_list, + TRUE + ) ); + } - if ( stripos( $server_list[0], 'enabled' ) === false ) { - \Kint::dump( $server_list ); - throw new \Exception( 'An error occurred checking that Solr8 was enable.d' ); - } } catch (\Exception $e) { + $this->output()->write($e->getMessage()); return ResultData::EXITCODE_ERROR; + } + catch (\Throwable $t) { $this->output()->write($t->getMessage()); return ResultData::EXITCODE_ERROR; } + $this->output()->write('👍👍👍 Solr8 is enabled and working.', TRUE); return ResultData::EXITCODE_OK; } @@ -649,23 +665,25 @@ public function testSolrEnabled( string $site_name, string $env = 'dev' ) { * @param string $env * The environment to run the diagnostics on. */ - public function testSolrDiagnose( string $site_name, string $env = 'dev' ) { + public function testSolrDiagnose(string $site_name, string $env = 'dev') { try { // Run a diagnose command to make sure everything is okay. - $this->output()->write('Running search-api-pantheon:diagnose...', true); - $diagnose = $this->taskExec( static::$TERMINUS_EXE ) + $this->output()->write('Running search-api-pantheon:diagnose...', TRUE); + $diagnose = $this->taskExec(static::$TERMINUS_EXE) ->args( - 'drush', - "$site_name.$env", - '--', - 'search-api-pantheon:diagnose', - '-v' + 'drush', + "$site_name.$env", + '--', + 'search-api-pantheon:diagnose', + '-v' ) ->run(); - if ( $diagnose instanceof Result && ! $diagnose->wasSuccessful() ) { - \Kint::dump( $diagnose ); - throw new \Exception( 'An error occurred while running Solr search diagnostics.' ); + if ($diagnose instanceof Result && !$diagnose->wasSuccessful()) { + \Kint::dump($diagnose); + throw new \Exception( + 'An error occurred while running Solr search diagnostics.' + ); } } catch (\Exception $e) { @@ -685,10 +703,10 @@ public function testSolrDiagnose( string $site_name, string $env = 'dev' ) { */ public function demoLoginBrowser(string $site_name, string $env = 'dev') { exec( - 'terminus drush ' . $site_name . '.' . $env . ' -- uli admin', - $finished, - $status - ); + 'terminus drush ' . $site_name . '.' . $env . ' -- uli admin', + $finished, + $status + ); $finished = trim(join('', $finished)); $this->output()->writeln($finished); $this->_exec('open ' . $finished); @@ -701,15 +719,15 @@ protected function say($text, string $step_id = 'narration') { $now = new \DateTime(); $filename = 'narration-' . - $now->diff($this->started)->format('%I-%S-%F') . '-' . $step_id . '.m4a'; + $now->diff($this->started)->format('%I-%S-%F') . '-' . $step_id . '.m4a'; $this->output->writeln('/Users/Shared/' . $filename); return (new Process([ - '/usr/bin/say', - '--voice=Daniel', - "--output-file={$filename}", - '--file-format=m4af', - $text, - ], '/Users/Shared')) + '/usr/bin/say', + '--voice=Daniel', + "--output-file={$filename}", + '--file-format=m4af', + $text, + ], '/Users/Shared')) ->enableOutput() ->setTty(TRUE); } @@ -724,7 +742,11 @@ protected function say($text, string $step_id = 'narration') { */ protected function siteInfo(string $site_name) { try { - exec(static::$TERMINUS_EXE . ' site:info --format=json ' . $site_name, $output, $status); + exec( + static::$TERMINUS_EXE . ' site:info --format=json ' . $site_name, + $output, + $status + ); if (!empty($output)) { $result = json_decode(join("", $output), TRUE, 512, JSON_THROW_ON_ERROR); return $result; @@ -748,8 +770,9 @@ public function testPhpVersion(string $site_name, int $drupal_version) { $pantheon_yml_contents = Yaml::parseFile($site_folder . '/pantheon.yml'); if ($drupal_version === 10) { $pantheon_yml_contents['php_version'] = 8.2; - } else { - $pantheon_yml_contents['php_version'] = 8.1; + } + else { + $pantheon_yml_contents['php_version'] = 8.3; } $pantheon_yml_contents = Yaml::dump($pantheon_yml_contents); file_put_contents($site_folder . '/pantheon.yml', $pantheon_yml_contents); @@ -780,70 +803,25 @@ public function testEnvSolr(string $site_name) { * The environment to create the index in. */ public function testSolrIndexCreate(string $site_name, string $env = 'dev') { - $result = $this->taskExec( static::$TERMINUS_EXE ) - ->args( - 'drush', - "$site_name.$env", - '--', - 'cim', - '--partial', - '--source=modules/contrib/search_api_pantheon/.ci/config', - '-y' - ) - ->run(); - if (!$result->wasSuccessful()) { - exit(1); - } - // Index new solr. - $result = $this->taskExec( static::$TERMINUS_EXE ) - ->args( - 'drush', - "$site_name.$env", - '--', - 'sapi-i' - ) - ->run(); - if (!$result->wasSuccessful()) { - exit(1); - } - } - public function testPantheonSolrReload(string $site_name, string $env = 'dev') { - $result = $this->taskExec( static::$TERMINUS_EXE ) - ->args( - 'drush', - "$site_name.$env", - '--', - 'search-api-pantheon:reloadSchema', - ) - ->run(); - if (!$result->wasSuccessful()) { - exit(1); - } - } - - public function testSolrReload(string $site_name, string $env = 'dev') { - $result = $this->taskExec( static::$TERMINUS_EXE ) - ->args( - 'drush', - "$site_name.$env", - '--', - 'search-api-solr:reload', - 'pantheon_solr8' - ) - ->run(); - if (!$result->wasSuccessful()) { - exit(1); - } + // Index new solr. + $result = $this->taskExec(static::$TERMINUS_EXE) + ->args( + 'drush', + "$site_name.$env", + '--', + 'sapi-i' + ) + ->run(); + if (!$result->wasSuccessful()) { + exit(1); + } } - - - - /** - * Use search-api-pantheon:select command to ensure both Drupal index and the actual Solr index have the same amount of items. + * Use search-api-pantheon:select command to ensure both Drupal index and the + * actual Solr index have the same amount of items. * * @param string $site_name * The machine name of the site to run the tests on. @@ -851,51 +829,53 @@ public function testSolrReload(string $site_name, string $env = 'dev') { * The environment to run the tests on. */ public function testSolrSelect(string $site_name, string $env = 'dev') { - $sapi_s = new Process([ - static::$TERMINUS_EXE, - 'drush', - "$site_name.$env", - '--', - 'sapi-s', - '--field=Indexed', - ]); - $total_indexed = 0; - $sapi_s->run(); - if ($sapi_s->isSuccessful()) { - $result = $sapi_s->getOutput(); - $result_parts = explode("\n", $result); - foreach ($result_parts as $part) { - if (is_numeric(trim($part))) { - $total_indexed = trim($part); - } + $sapi_s = new Process([ + static::$TERMINUS_EXE, + 'drush', + "$site_name.$env", + '--', + 'sapi-s', + '--field=Indexed', + ]); + $total_indexed = 0; + $sapi_s->run(); + if ($sapi_s->isSuccessful()) { + $result = $sapi_s->getOutput(); + $result_parts = explode("\n", $result); + foreach ($result_parts as $part) { + if (is_numeric(trim($part))) { + $total_indexed = trim($part); } } + } - $saps = new Process([ - static::$TERMINUS_EXE, - 'drush', - "$site_name.$env", - '--', - 'saps', - '*:*' - ]); - $num_found = 0; - $saps->run(); - if ($saps->isSuccessful()) { - $result = $saps->getOutput(); - $result_parts = explode("\n", $result); - foreach ($result_parts as $part) { - if (strpos($part, 'numFound') !== FALSE) { - $num_found = trim(str_replace('"numFound":', '', $part), ' ,'); - break; - } + $saps = new Process([ + static::$TERMINUS_EXE, + 'drush', + "$site_name.$env", + '--', + 'saps', + '*:*', + ]); + $num_found = 0; + $saps->run(); + if ($saps->isSuccessful()) { + $result = $saps->getOutput(); + $result_parts = explode("\n", $result); + foreach ($result_parts as $part) { + if (strpos($part, 'numFound') !== FALSE) { + $num_found = trim(str_replace('"numFound":', '', $part), ' ,'); + break; } } + } - if ($total_indexed && $num_found && $total_indexed != $num_found) { - $this->output->writeln('Solr indexing error. Total indexed: ' . $total_indexed . ' but found: ' . $num_found); - exit(1); - } + if ($total_indexed && $num_found && $total_indexed != $num_found) { + $this->output->writeln( + 'Solr indexing error. Total indexed: ' . $total_indexed . ' but found: ' . $num_found + ); + exit(1); + } } } diff --git a/composer.json b/composer.json index 58039df4..5690c5b6 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "preferred-install": "dist", "sort-packages": true, "platform": { - "php": "8.0" + "php": "8.1" }, "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true @@ -37,20 +37,21 @@ } }, "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-curl": "*", "ext-json": "*", "ext-zip": "*", "drupal/search_api_solr": "^4.3", - "guzzlehttp/guzzle": "^6.5.7|^7.5", - "http-interop/http-factory-guzzle": "^1.0", - "kint-php/kint": "^4.1|^5", + "guzzlehttp/guzzle": "^7.5", + "guzzlehttp/psr7": "^2.7", + "kint-php/kint": "^5|^6", + "php-http/guzzle7-adapter": "^1.1", "psr/event-dispatcher": "^1.0", - "symfony/finder": "^4.4|^5|^6", - "symfony/yaml": "^4.4|^5|^6" + "symfony/finder": "^4.4|^5|^6|^7", + "symfony/yaml": "^4.4|^5|^6|^7" }, "require-dev": { - "consolidation/robo": "^3.0", + "consolidation/robo": "^3 || ^4 || ^5", "czproject/git-php": "^4.0", "drupal/coder": "@stable", "phpunit/phpunit": "@stable", @@ -70,7 +71,7 @@ ], "code:fix": [ "vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer", - "vendor/bin/phpcbf . --ignore=RoboFile.php,vendor src modules" + "vendor/bin/phpcbf . --ignore=vendor src modules" ], "code:lint": [ "vendor/bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer", diff --git a/config/optional/search_api_index.content_index.yml b/config/install/search_api.index.primary.yml similarity index 63% rename from config/optional/search_api_index.content_index.yml rename to config/install/search_api.index.primary.yml index 95e331f7..934ed0a2 100644 --- a/config/optional/search_api_index.content_index.yml +++ b/config/install/search_api.index.primary.yml @@ -2,29 +2,24 @@ langcode: en status: true dependencies: module: - - search_api_solr - - search_api - node - config: - - search_api.server.pantheon_solr8 + - search_api_solr third_party_settings: search_api_solr: finalize: false commit_before_finalize: false commit_after_finalize: false - multilingual: - limit_to_content_language: false - include_language_independent: true + debug_finalize: false highlighter: maxAnalyzedChars: 51200 fragmenter: gap + usePhraseHighlighter: true + highlightMultiTerm: true + preserveMulti: false regex: slop: 0.5 pattern: blank maxAnalyzedChars: 10000 - usePhraseHighlighter: true - highlightMultiTerm: true - preserveMulti: false highlight: mergeContiguous: false requireFieldMatch: false @@ -44,13 +39,21 @@ third_party_settings: term_modifiers: slop: 3 fuzzy: 1 + fuzzy_analyzer: true advanced: index_prefix: '' collection: '' timezone: '' -id: content_index -name: 'Basic Content Index' -description: 'An example index to get started with Solr 8 searching.' + multilingual: + limit_to_content_language: false + include_language_independent: true + use_language_undefined_as_fallback_language: false + specific_languages: + en: '0' + use_universal_collation: false +id: primary +name: primary +description: '' read_only: false field_settings: { } datasource_settings: @@ -64,13 +67,36 @@ datasource_settings: processor_settings: add_url: { } aggregated_field: { } + auto_aggregated_fulltext_field: { } + custom_value: { } + entity_type: { } + highlight: + weights: + postprocess_query: 0 + prefix: '' + suffix: '' + excerpt: true + excerpt_always: false + excerpt_length: 256 + exclude_fields: { } + highlight: always + highlight_partial: false language_with_fallback: { } rendered_item: { } - solr_date_range: { } + reverse_entity_references: { } + solr_boost_more_recent: + weights: + preprocess_query: 0 + boosts: { } + solr_date_range: + weights: + preprocess_index: 0 tracker_settings: default: indexing_order: fifo options: - index_directly: true cron_limit: 50 -server: pantheon_solr8 + delete_on_fail: true + index_directly: true + track_changes_in_references: true +server: pantheon_search diff --git a/config/install/search_api.server.pantheon_search.yml b/config/install/search_api.server.pantheon_search.yml new file mode 100644 index 00000000..9b2839b2 --- /dev/null +++ b/config/install/search_api.server.pantheon_search.yml @@ -0,0 +1,43 @@ +langcode: en +status: true +dependencies: + module: + - search_api_pantheon + - search_api_solr +id: pantheon_search +name: 'Pantheon Search' +description: 'Default search server for Pantheon Search.' +backend: search_api_solr +backend_config: + retrieve_data: false + highlight_data: false + site_hash: false + server_prefix: '' + domain: generic + environment: default + connector: pantheon + connector_config: + scheme: https + port: 443 + path: v1 + timeout: 5 + index_timeout: 5 + optimize_timeout: 10 + finalize_timeout: 30 + solr_version: '8' + http_method: AUTO + commit_within: 1000 + jmx: false + jts: false + solr_install_dir: '' + skip_schema_check: true + optimize: false + fallback_multiple: false + disabled_field_types: { } + disabled_caches: { } + disabled_request_handlers: + disabled_request_dispatchers: + rows: 10 + index_single_documents_fallback_count: 10 + index_empty_text_fields: false + suppress_missing_languages: false diff --git a/config/install/search_api.server.pantheon_solr8.yml b/config/install/search_api.server.pantheon_solr8.yml deleted file mode 100644 index dac34341..00000000 --- a/config/install/search_api.server.pantheon_solr8.yml +++ /dev/null @@ -1,50 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - search_api_solr.solr_request_handler.request_handler_autocomplete_default_7_0_0 - - search_api_solr.solr_request_handler.request_handler_elevate_default_7_0_0 - - search_api_solr.solr_request_handler.request_handler_extract_default_7_0_0 - - search_api_solr.solr_request_handler.request_handler_mlt_default_7_0_0 - - search_api_solr.solr_request_handler.request_handler_select_default_7_0_0 - - search_api_solr.solr_request_handler.request_handler_spell_default_7_0_0 - - search_api_solr.solr_request_handler.request_handler_suggest_default_7_0_0 - - search_api_solr.solr_request_handler.request_handler_tvrh_default_7_0_0 - module: - - search_api_pantheon - - search_api_solr -id: pantheon_solr8 -name: 'Pantheon Search' -description: '' -backend: search_api_solr -backend_config: - connector: pantheon - connector_config: - timeout: 5 - index_timeout: 5 - optimize_timeout: 10 - finalize_timeout: 30 - skip_schema_check: true - solr_version: '8' - http_method: AUTO - commit_within: 1000 - jmx: false - jts: false - solr_install_dir: '' - disabled_field_types: { } - disabled_caches: { } - disabled_request_handlers: - - request_handler_replicationslave_default_7_0_0 - - request_handler_replicationmaster_default_7_0_0 - disabled_request_dispatchers: - - request_dispatcher_httpcachingnever_default_7_0_0 - rows: 10 - index_single_documents_fallback_count: 10 - retrieve_data: false - highlight_data: false - fallback_multiple: false - server_prefix: '' - domain: generic - environment: default - optimize: false - site_hash: false diff --git a/config/schema/search_api_pantheon.connector.pantheon.schema.yml b/config/schema/search_api_pantheon.connector.pantheon.schema.yml deleted file mode 100644 index 122d171f..00000000 --- a/config/schema/search_api_pantheon.connector.pantheon.schema.yml +++ /dev/null @@ -1,3 +0,0 @@ -plugin.plugin_configuration.search_api_solr_connector.pantheon: - type: plugin.plugin_configuration.search_api_solr_connector.standard - label: 'Search API Solr Pantheon connector settings' diff --git a/drush.services.yml b/drush.services.yml index 2be3d265..eccdd7be 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -1,26 +1,26 @@ services: search_api_pantheon.drush_diagnose: class: \Drupal\search_api_pantheon\Commands\Diagnose - arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] + arguments: [ "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] tags: - { name: drush.command } search_api_pantheon.drush_test_index_and_query: class: \Drupal\search_api_pantheon\Commands\TestIndexAndQuery - arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] + arguments: [ "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] tags: - { name: drush.command } search_api_pantheon.drush_schema: class: \Drupal\search_api_pantheon\Commands\Schema - arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] + arguments: [ "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] tags: - { name: drush.command } search_api_pantheon.drush_query: class: \Drupal\search_api_pantheon\Commands\Query - arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] + arguments: [ "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ] tags: - { name: drush.command } search_api_pantheon.drush_reload: class: \Drupal\search_api_pantheon\Commands\Reload - arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] + arguments: [ "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ] tags: - { name: drush.command } diff --git a/modules/search_api_pantheon_admin/search_api_pantheon_admin.info.yml b/modules/search_api_pantheon_admin/search_api_pantheon_admin.info.yml index 55910169..91b07f4b 100644 --- a/modules/search_api_pantheon_admin/search_api_pantheon_admin.info.yml +++ b/modules/search_api_pantheon_admin/search_api_pantheon_admin.info.yml @@ -1,7 +1,7 @@ name: Search API Pantheon Admin type: module description: Administer a Pantheon Search server -core_version_requirement: ^9.4 || ^10 +core_version_requirement: ^10 || ^11 package: Search dependencies: - search_api_solr:search_api_solr diff --git a/modules/search_api_pantheon_examples/search_api_pantheon_examples.info.yml b/modules/search_api_pantheon_examples/search_api_pantheon_examples.info.yml index dbf6b77e..7d5d1e33 100644 --- a/modules/search_api_pantheon_examples/search_api_pantheon_examples.info.yml +++ b/modules/search_api_pantheon_examples/search_api_pantheon_examples.info.yml @@ -1,7 +1,7 @@ name: Search API Pantheon Examples type: module description: Contains some examples of things you could do with Search API Pantheon module. This module should not be enabled in prod. -core_version_requirement: ^9.4 || ^10 +core_version_requirement: ^10 || ^11 package: Search dependencies: - search_api_pantheon:search_api_pantheon diff --git a/.phpcs.xml b/phpcs.xml similarity index 100% rename from .phpcs.xml rename to phpcs.xml diff --git a/search_api_pantheon.info.yml b/search_api_pantheon.info.yml index 46e2f95a..6b4e328b 100644 --- a/search_api_pantheon.info.yml +++ b/search_api_pantheon.info.yml @@ -1,7 +1,7 @@ name: Search API Pantheon type: module description: Search API + Solr + Pantheon integration -core_version_requirement: ^9.4 || ^10 +core_version_requirement: ^10 || ^11 package: Search dependencies: - search_api_solr:search_api_solr diff --git a/src/Commands/Diagnose.php b/src/Commands/Diagnose.php index 1ec37214..37424a46 100644 --- a/src/Commands/Diagnose.php +++ b/src/Commands/Diagnose.php @@ -2,7 +2,6 @@ namespace Drupal\search_api_pantheon\Commands; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\search_api_pantheon\Services\Endpoint; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient; @@ -31,8 +30,6 @@ class Diagnose extends DrushCommands { /** * Class Constructor. * - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory - * Injected by container. * @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle * Injected by container. * @param \Drupal\search_api_pantheon\Services\Endpoint $endpoint @@ -41,12 +38,10 @@ class Diagnose extends DrushCommands { * Injected by container. */ public function __construct( - LoggerChannelFactoryInterface $loggerChannelFactory, PantheonGuzzle $pantheonGuzzle, Endpoint $endpoint, SolariumClient $solariumClient ) { - $this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); $this->pantheonGuzzle = $pantheonGuzzle; $this->endpoint = $endpoint; $this->solr = $solariumClient; diff --git a/src/Commands/Query.php b/src/Commands/Query.php index f246c8f0..2ca97677 100644 --- a/src/Commands/Query.php +++ b/src/Commands/Query.php @@ -2,7 +2,6 @@ namespace Drupal\search_api_pantheon\Commands; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\search_api_pantheon\Services\Endpoint; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient; @@ -30,8 +29,6 @@ class Query extends DrushCommands { /** * Class Constructor. * - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory - * Injected by container. * @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle * Injected by container. * @param \Drupal\search_api_pantheon\Services\Endpoint $endpoint @@ -40,12 +37,10 @@ class Query extends DrushCommands { * Injected by container. */ public function __construct( - LoggerChannelFactoryInterface $loggerChannelFactory, PantheonGuzzle $pantheonGuzzle, Endpoint $endpoint, SolariumClient $solariumClient ) { - $this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); $this->pantheonGuzzle = $pantheonGuzzle; $this->endpoint = $endpoint; $this->solr = $solariumClient; diff --git a/src/Commands/Reload.php b/src/Commands/Reload.php index 9b42b482..45070a78 100644 --- a/src/Commands/Reload.php +++ b/src/Commands/Reload.php @@ -2,8 +2,6 @@ namespace Drupal\search_api_pantheon\Commands; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; -use Drupal\Core\Logger\LoggerChannelTrait; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SchemaPoster; use Drush\Commands\DrushCommands; @@ -12,7 +10,6 @@ * Drush Search Api Pantheon Schema Commands. */ class Reload extends DrushCommands { - use LoggerChannelTrait; /** * Configured pantheon-solr-specific guzzle client. @@ -31,19 +28,15 @@ class Reload extends DrushCommands { /** * Class constructor. * - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory - * Injected by container. * @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle * Injected by container. * @param \Drupal\search_api_pantheon\Services\SchemaPoster $schemaPoster * Injected by Container. */ public function __construct( - LoggerChannelFactoryInterface $loggerChannelFactory, PantheonGuzzle $pantheonGuzzle, SchemaPoster $schemaPoster ) { - $this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); $this->pantheonGuzzle = $pantheonGuzzle; $this->schemaPoster = $schemaPoster; } diff --git a/src/Commands/Schema.php b/src/Commands/Schema.php index c43b37dc..85718826 100644 --- a/src/Commands/Schema.php +++ b/src/Commands/Schema.php @@ -2,8 +2,6 @@ namespace Drupal\search_api_pantheon\Commands; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; -use Drupal\Core\Logger\LoggerChannelTrait; use Drupal\search_api_pantheon\Plugin\SolrConnector\PantheonSolrConnector; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SchemaPoster; @@ -14,7 +12,6 @@ * Drush Search Api Pantheon Schema Commands. */ class Schema extends DrushCommands { - use LoggerChannelTrait; /** * Configured pantheon-solr-specific guzzle client. @@ -33,19 +30,15 @@ class Schema extends DrushCommands { /** * Class constructor. * - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory - * Injected by container. * @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle * Injected by container. * @param \Drupal\search_api_pantheon\Services\SchemaPoster $schemaPoster * Injected by Container. */ public function __construct( - LoggerChannelFactoryInterface $loggerChannelFactory, PantheonGuzzle $pantheonGuzzle, SchemaPoster $schemaPoster ) { - $this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); $this->pantheonGuzzle = $pantheonGuzzle; $this->schemaPoster = $schemaPoster; } diff --git a/src/Commands/TestIndexAndQuery.php b/src/Commands/TestIndexAndQuery.php index e0c23140..99b38a29 100644 --- a/src/Commands/TestIndexAndQuery.php +++ b/src/Commands/TestIndexAndQuery.php @@ -2,7 +2,6 @@ namespace Drupal\search_api_pantheon\Commands; -use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\search_api_pantheon\Services\Endpoint; use Drupal\search_api_pantheon\Services\PantheonGuzzle; use Drupal\search_api_pantheon\Services\SolariumClient; @@ -35,8 +34,6 @@ class TestIndexAndQuery extends DrushCommands { /** * Class Constructor. * - * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory - * Injected by container. * @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle * Injected by container. * @param \Drupal\search_api_pantheon\Services\Endpoint $endpoint @@ -45,12 +42,10 @@ class TestIndexAndQuery extends DrushCommands { * Injected by container. */ public function __construct( - LoggerChannelFactoryInterface $loggerChannelFactory, PantheonGuzzle $pantheonGuzzle, Endpoint $endpoint, SolariumClient $solariumClient ) { - $this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); $this->pantheonGuzzle = $pantheonGuzzle; $this->endpoint = $endpoint; $this->solr = $solariumClient; diff --git a/src/Services/PantheonGuzzle.php b/src/Services/PantheonGuzzle.php index 55e9b256..0d73b606 100644 --- a/src/Services/PantheonGuzzle.php +++ b/src/Services/PantheonGuzzle.php @@ -2,13 +2,12 @@ namespace Drupal\search_api_pantheon\Services; +use GuzzleHttp\Psr7\HttpFactory; use Drupal\search_api_pantheon\Traits\EndpointAwareTrait; use GuzzleHttp\Client; use GuzzleHttp\Handler\CurlHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; -use Http\Factory\Guzzle\RequestFactory; -use Http\Factory\Guzzle\StreamFactory; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -18,6 +17,7 @@ use Solarium\Core\Client\Adapter\Psr18Adapter; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Session\AccountProxyInterface; +use Solarium\Core\Client\Endpoint; /** * Pantheon-specific extension of the Guzzle http query class. @@ -40,7 +40,11 @@ class PantheonGuzzle extends Client implements /** * Class Constructor. */ - public function __construct(Endpoint $endpoint, LoggerChannelFactoryInterface $logger_factory, AccountProxyInterface $current_user) { + public function __construct( + Endpoint $endpoint, + LoggerChannelFactoryInterface $logger_factory, + AccountProxyInterface $current_user + ) { $stack = new HandlerStack(); $stack->setHandler(new CurlHandler()); $stack->push( @@ -135,20 +139,6 @@ public function getQueryResult( return (string) $response->getBody(); } - /** - * Get a PSR adapter interface based on this class. - * - * @return \Solarium\Core\Client\Adapter\AdapterInterface - * The interface in question. - */ - public function getPsr18Adapter(): AdapterInterface { - return new Psr18Adapter( - $this, - new RequestFactory(), - new StreamFactory() - ); - } - /** * Request Middleware Callback. * @@ -176,4 +166,19 @@ public function requestUriAlterForPantheonEnvironment(RequestInterface $request) return $request->withUri($uri); } + /** + * Get a PSR adapter interface based on this class. + * + * @return \Solarium\Core\Client\Adapter\AdapterInterface + * The interface in question. + */ + public function getAdapter(): AdapterInterface { + $factory = new HttpFactory(); + return new Psr18Adapter( + $this, + $factory, + $factory, + ); + } + } diff --git a/src/Services/SolariumClient.php b/src/Services/SolariumClient.php index 3afd20d2..038990a9 100644 --- a/src/Services/SolariumClient.php +++ b/src/Services/SolariumClient.php @@ -9,8 +9,7 @@ use Solarium\Core\Query\QueryInterface; use Solarium\Core\Query\Result\ResultInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; -use Drupal\search_api_pantheon\Solarium\EventDispatcher\Psr14Bridge; -use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Customized Solrium Client to send Guzzle debugging to log entries. @@ -21,18 +20,18 @@ class SolariumClient extends Client { /** * Class constructor. */ - public function __construct(PantheonGuzzle $guzzle, Endpoint $endpoint, LoggerChannelFactoryInterface $logger_factory, ContainerAwareEventDispatcher $event_dispatcher) { + public function __construct( + PantheonGuzzle $guzzle, + Endpoint $endpoint, + LoggerChannelFactoryInterface $logger_factory, + EventDispatcherInterface $event_dispatcher) { $drupal_major_parts = explode('.', \Drupal::VERSION); $drupal_major = reset($drupal_major_parts); - if ($drupal_major < 9) { - // Use the bridge only if Drupal 8. - $event_dispatcher = new Psr14Bridge($event_dispatcher); - } parent::__construct( - $guzzle->getPsr18Adapter(), - $event_dispatcher, - ['endpoint' => [$endpoint]] - ); + $guzzle->getAdapter(), + $event_dispatcher, + ['endpoint' => [$endpoint]], + ); $this->logger = $logger_factory->get('PantheonSolariumClient'); $this->setDefaultEndpoint($endpoint); }