Skip to content

Commit

Permalink
[CMS-1125] Drupal 10 compatibility (#152)
Browse files Browse the repository at this point in the history
* Re-add changes from #147.

* Update drupal-versions matrix and use latest upstream.

* Try to make tests pass.

* Attempt D10 upgrade.

* Attempt D10 upgrade fixes.

* Expand symfony/finder requirement.

* Add composer-drupal-lenient to allow plugins section.

* Set php version to 8.1.

* Upgrade php version earlier and make submodules d10 compatible.

* Port changes from #148.

* Get dev version of search_api_solr for D10.

* Always test again latest version of search_api_solr.

* Try testing in 8.1.

* Fix indentation error in Robofile.
  • Loading branch information
kporras07 authored Nov 22, 2022
1 parent eb43485 commit c749cc2
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
build_test:
strategy:
matrix:
drupal-version: [ 9, 8 ]
drupal-version: [ 9, 10 ]
fail-fast: false
runs-on: ubuntu-latest
container:
image: quay.io/pantheon-public/build-tools-ci:8.x-php7.4
image: quay.io/pantheon-public/build-tools-ci:8.x-php8.1
options: --user root
name: Build and test (Drupal ${{ matrix.drupal-version }})
env:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Search API Pantheon version 8.0 (for solr 8 & Drupal 8/9)
# Search API Pantheon version 8.0 (for solr 8 & Drupal 9/10)

[![Search API Pantheon](https://github.com/pantheon-systems/search_api_pantheon/actions/workflows/ci.yml/badge.svg?branch=8.x)](https://github.com/pantheon-systems/search_api_pantheon/actions/workflows/ci.yml)
[![Limited Availability](https://img.shields.io/badge/Pantheon-Limited_Availability-yellow?logo=pantheon&color=FFDC28)](https://pantheon.io/docs/oss-support-levels#limited-availability)
Expand All @@ -10,7 +10,7 @@

This module is for you if you meet the following requirements:

* Using Drupal 8.8/9.2+
* Using Drupal 9.4/10

* Hosting the Drupal site on Pantheon's platform

Expand Down Expand Up @@ -49,7 +49,7 @@ Composer is the way you should be managing your drupal module requirements. This

- [Search API Solr](https://www.drupal.org/project/search_api_solr). Search API Solr makes search API work with Apache Solr. Composer will manage which version.

- [Guzzle](https://docs.guzzlephp.org/en/stable/). Guzzle version 6 is standard with Drupal Core `8.x | 9.x` (read 8.x OR 9.x).
- [Guzzle](https://docs.guzzlephp.org/en/stable/). Guzzle version 6 is standard with Drupal Core `9.x | 10.x` (read 9.x OR 10.x).

## Install

Expand Down Expand Up @@ -233,4 +233,4 @@ with the concept usage in a Solr context:


* `drush search-api-pantheon:force-cleanup` (`sapfc`) This command will delete all of the contents for the given
Solr server (no matter if hash or index_id have changed).
Solr server (no matter if hash or index_id have changed).
141 changes: 120 additions & 21 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ public function testFull(int $drupal_version = 9, string $site_name = NULL) {
$this->testCreateSite($site_name, $options);
$this->testConnectionGit($site_name, 'dev', 'git');
$this->testCloneSite($site_name);
$this->testAllowPlugins($site_name);
$this->testAllowPlugins($site_name, $drupal_version);
$this->testPhpVersion($site_name);

// If received Drupal 8, downgrade the recently created site to Drupal 8.
if ($drupal_version === 8) {
$this->testDowngradeToDrupal8($site_name);
// 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.
Expand Down Expand Up @@ -180,7 +182,7 @@ public function testCreateSite(string $site_name, array $options = ['org' => NUL
if (empty($site_info)) {
$home = $_SERVER['HOME'];
$toReturn = $this->taskExec(static::$TERMINUS_EXE)
->args('site:create', $site_name, $site_name, 'drupal9');
->args('site:create', $site_name, $site_name, 'drupal-composer-managed');
if ( !empty( $options['org'] ) ) {
$toReturn->option('org', $options['org']);
}
Expand Down Expand Up @@ -308,26 +310,101 @@ public function testCloneSite(string $site_name) {
*
* @param string $site_name
* The machine name of the site to add the allow plugins section to.
* @param int $drupal_version
* The major version of Drupal to use.
*/
public function testAllowPlugins(string $site_name) {
$site_folder = $this->getSiteFolder($site_name);
chdir($site_folder);
public function testAllowPlugins(string $site_name, int $drupal_version) {
$plugins = [
'composer/installers',
'drupal/core-composer-scaffold',
'cweagans/composer-patches',
'drupal/core-project-message',
];
if ($drupal_version === 10) {
$plugins[] = 'phpstan/extension-installer';
// @todo Remove once all of the modules have been correctly upgraded.
$plugins[] = 'mglaman/composer-drupal-lenient';
}
if (count($plugins)) {
$site_folder = $this->getSiteFolder($site_name);
chdir($site_folder);

foreach ($plugins as $plugin_name) {
$this->taskExec('composer')
->args(
'config',
'--no-interaction',
'allow-plugins.' . $plugin_name,
'true'
)
->run();
}
}
}

/**
* 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();

foreach ($plugins as $plugin_name) {
$this->taskExec('composer')
$this->taskExec('composer')
->args('update')
->run();

$this->taskExec('composer')
->args(
'config',
'--no-interaction',
'allow-plugins.' . $plugin_name,
'true'
'--merge',
'--json',
'extra.drupal-lenient.allowed-list',
'["drupal/search_api_pantheon"]'
)
->run();
}
return ResultData::EXITCODE_OK;
}

/**
Expand Down Expand Up @@ -373,11 +450,18 @@ public function testDowngradeToDrupal8(string $site_name) {
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.
$this->taskExec('composer')
->args(
'require',
'pantheon-systems/search_api_pantheon ' . $constraint,
)
'require',
'drupal/search_api_solr:dev-4.x',
)
->run();
$this->taskExec('composer')
->args(
'require',
'pantheon-systems/search_api_pantheon ' . $constraint,
)
->run();
return ResultData::EXITCODE_OK;
}
Expand Down Expand Up @@ -648,6 +732,21 @@ protected function siteInfo(string $site_name) {
return NULL;
}

/**
* Set correct PHP version for the given site.
*
* @param string $site_name
* The machine name of the site to set the Solr version for.
*/
public function testPhpVersion(string $site_name) {
$site_folder = $this->getSiteFolder($site_name);
$pantheon_yml_contents = Yaml::parseFile($site_folder . '/pantheon.yml');
$pantheon_yml_contents['php_version'] = 8.1;
$pantheon_yml_contents = Yaml::dump($pantheon_yml_contents);
file_put_contents($site_folder . '/pantheon.yml', $pantheon_yml_contents);
$this->output->writeln($pantheon_yml_contents);
}

/**
* Set correct Solr version for the given site.
*
Expand Down Expand Up @@ -679,7 +778,7 @@ public function testSolrIndexCreate(string $site_name, string $env = 'dev') {
'--',
'cim',
'--partial',
'--source=modules/composer/search_api_pantheon/.ci/config',
'--source=modules/contrib/search_api_pantheon/.ci/config',
'-y'
)
->run();
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@
"ext-json": "*",
"ext-zip": "*",
"drupal/search_api_solr": "^4.2",
"guzzlehttp/guzzle": "^6.5.2",
"guzzlehttp/guzzle": "^6.5.2|^7.4",
"http-interop/http-factory-guzzle": "^1.0",
"kint-php/kint": "^4.1",
"php-http/guzzle6-adapter": "^2.0",
"psr/event-dispatcher": "^1.0",
"symfony/finder": "^4|^5"
"symfony/finder": "^4.4|^5|^6"
},
"require-dev": {
"consolidation/robo": "^3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Search API Pantheon Admin
type: module
description: Administer a Pantheon Search server
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9.4 || ^10
package: Search
dependencies:
- search_api_solr:search_api_solr
Original file line number Diff line number Diff line change
@@ -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: ^8.8 || ^9
core_version_requirement: ^9.4 || ^10
package: Search
dependencies:
- search_api_pantheon:search_api_pantheon
2 changes: 1 addition & 1 deletion search_api_pantheon.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Search API Pantheon
type: module
description: Search API + Solr + Pantheon integration
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9.4 || ^10
package: Search
dependencies:
- search_api_solr:search_api_solr
6 changes: 1 addition & 5 deletions src/Plugin/SolrConnector/PantheonSolrConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase;
use Drupal\search_api_solr\SolrConnectorInterface;
use Drupal\search_api_pantheon\Services\Endpoint as PantheonEndpoint;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Solarium\Client as SolariumClient;
use Solarium\Core\Client\Endpoint;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -31,9 +29,7 @@
class PantheonSolrConnector extends SolrConnectorPluginBase implements
SolrConnectorInterface,
PluginFormInterface,
ContainerFactoryPluginInterface,
LoggerAwareInterface {
use LoggerAwareTrait;
ContainerFactoryPluginInterface {

/**
* @var object|null
Expand Down
2 changes: 1 addition & 1 deletion src/Solarium/EventDispatcher/EventProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Drupal\search_api_pantheon\Solarium\EventDispatcher;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* A proxy for events defined by symfony contracts to be used with older Drupal.
Expand Down
2 changes: 1 addition & 1 deletion src/Solarium/EventDispatcher/Psr14Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* A helper to decorate the legacy EventDispatcherInterface::dispatch().
Expand Down

0 comments on commit c749cc2

Please sign in to comment.