From 4e042b723ab99660a8df59b4a0aba672743a3f83 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Wed, 8 May 2024 13:36:45 +0200 Subject: [PATCH] refactor(drupal9): Drop Drupal 9 support (#1396) --- .github/workflows/testing.yml | 13 ++++-------- .../graphql_composable.info.yml | 2 +- .../graphql_example/graphql_examples.info.yml | 2 +- graphql.info.yml | 2 +- src/GraphQL/Execution/Executor.php | 21 ++++++++----------- src/GraphQL/Utility/FileUpload.php | 8 +++---- src/Routing/QueryRouteEnhancer.php | 4 +--- .../DataProducer/EntityDefinitionTest.php | 4 ++-- .../DataProducer/EntityReferenceTest.php | 4 ++-- 9 files changed, 25 insertions(+), 35 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 96292c8d9..12de0748a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,18 +13,13 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.3', '7.4', '8.0', '8.1'] - # Keep testing Drupal 9 untill 6 months after it got unsupported, so - # untill May 1st 2024. - drupal-core: ['9.5.x'] + php-versions: ['8.1', '8.2'] + drupal-core: ['10.2.x'] phpstan: ['0'] include: - # Extra runs to also test on latest Drupal 10. + # Extra run to test older supported Drupal 10.1.x. - php-versions: '8.1' - drupal-core: '10.2.x' - phpstan: '0' - - php-versions: '8.2' - drupal-core: '10.2.x' + drupal-core: '10.1.x' phpstan: '0' # We only need to run PHPStan once on the latest PHP version. - php-versions: '8.3' diff --git a/examples/graphql_composable/graphql_composable.info.yml b/examples/graphql_composable/graphql_composable.info.yml index b11094325..92ebd73cd 100644 --- a/examples/graphql_composable/graphql_composable.info.yml +++ b/examples/graphql_composable/graphql_composable.info.yml @@ -5,4 +5,4 @@ package: GraphQL dependencies: - graphql:graphql - node:node -core_version_requirement: ^9.3 || ^10 +core_version_requirement: ^10.1 diff --git a/examples/graphql_example/graphql_examples.info.yml b/examples/graphql_example/graphql_examples.info.yml index c11a6fe90..57bb865b3 100644 --- a/examples/graphql_example/graphql_examples.info.yml +++ b/examples/graphql_example/graphql_examples.info.yml @@ -5,4 +5,4 @@ package: GraphQL dependencies: - graphql:graphql - node:node -core_version_requirement: ^9.3 || ^10 +core_version_requirement: ^10.1 diff --git a/graphql.info.yml b/graphql.info.yml index 67f16324a..c8cc6d095 100644 --- a/graphql.info.yml +++ b/graphql.info.yml @@ -3,6 +3,6 @@ type: module description: 'Base module for integrating GraphQL with Drupal.' package: GraphQL configure: graphql.config_page -core_version_requirement: ^9.3 || ^10 +core_version_requirement: ^10.1 dependencies: - typed_data:typed_data diff --git a/src/GraphQL/Execution/Executor.php b/src/GraphQL/Execution/Executor.php index b8ed3a6cb..03fdd8b30 100644 --- a/src/GraphQL/Execution/Executor.php +++ b/src/GraphQL/Execution/Executor.php @@ -2,6 +2,7 @@ namespace Drupal\graphql\GraphQL\Execution; +use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheBackendInterface; @@ -22,7 +23,6 @@ use GraphQL\Utils\AST; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\RequestStack; /** * Executes GraphQL queries with cache lookup. @@ -51,11 +51,9 @@ class Executor implements ExecutorImplementation { protected $contextsManager; /** - * The request stack. - * - * @var \Symfony\Component\HttpFoundation\RequestStack + * The date/time service. */ - protected $requestStack; + protected TimeInterface $time; /** * The event dispatcher. @@ -127,8 +125,8 @@ class Executor implements ExecutorImplementation { * The cache contexts manager service. * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend * The cache backend for caching query results. - * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack - * The request stack. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The date/time service. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher * The event dispatcher. * @param \GraphQL\Executor\Promise\PromiseAdapter $adapter @@ -143,7 +141,7 @@ class Executor implements ExecutorImplementation { public function __construct( CacheContextsManager $contextsManager, CacheBackendInterface $cacheBackend, - RequestStack $requestStack, + TimeInterface $time, EventDispatcherInterface $dispatcher, PromiseAdapter $adapter, Schema $schema, @@ -156,7 +154,7 @@ public function __construct( ) { $this->contextsManager = $contextsManager; $this->cacheBackend = $cacheBackend; - $this->requestStack = $requestStack; + $this->time = $time; $this->dispatcher = $dispatcher; $this->adapter = $adapter; @@ -198,7 +196,7 @@ public static function create( return new static( $container->get('cache_contexts_manager'), $container->get('cache.graphql.results'), - $container->get('request_stack'), + $container->get('datetime.time'), $container->get('event_dispatcher'), $adapter, $schema, @@ -444,8 +442,7 @@ protected function cacheWrite($prefix, CacheableExecutionResult $result) { * @see \Drupal\Core\Cache\CacheBackendInterface::set() */ protected function maxAgeToExpire($maxAge) { - // @todo Can be removed when D9 support is dropped. - $time = $this->requestStack->getMainRequest()->server->get('REQUEST_TIME'); + $time = $this->time->getRequestTime(); return ($maxAge === Cache::PERMANENT) ? Cache::PERMANENT : (int) $time + $maxAge; } diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index 46c2f34c7..562eb622c 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -193,8 +193,8 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi switch ($uploaded_file->getError()) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: - // @todo Drupal 9 compatibility, needs to be converted to ByteSizeMarkup - // later. + // @todo Drupal 10.1 compatibility, needs to be converted to + // ByteSizeMarkup later. // @phpstan-ignore-next-line $maxUploadSize = format_size($this->getMaxUploadSize($settings)); $response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [ @@ -271,7 +271,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi $file->setSize(@filesize($temp_file_path)); // Validate against file_validate() first with the temporary path. - // @todo Drupal 9 compatibility, needs to be converted to file validate + // @todo Drupal 10.1 compatibility, needs to be converted to file validate // service later. // @phpstan-ignore-next-line $errors = file_validate($file, $validators); @@ -505,7 +505,7 @@ protected function prepareFilename(string $filename, array &$validators): string /** @var \Drupal\file\FileInterface $file */ $file = $this->fileStorage->create([]); $file->setFilename($filename); - // @todo Drupal 9 compatibility, needs to be converted to file + // @todo Drupal 10.1 compatibility, needs to be converted to file // validator service later. // @phpstan-ignore-next-line $passes_validation = empty(file_validate_extensions($file, $validators['file_validate_extensions'][0])); diff --git a/src/Routing/QueryRouteEnhancer.php b/src/Routing/QueryRouteEnhancer.php index ca2daa5df..079f90e49 100644 --- a/src/Routing/QueryRouteEnhancer.php +++ b/src/Routing/QueryRouteEnhancer.php @@ -136,9 +136,7 @@ protected function assertValidPostRequestHeaders(Request $request) : void { // Allow other origins as configured in the CORS policy. if (!empty($this->corsOptions['enabled'])) { $cors_service = new CorsService($this->corsOptions); - // Drupal 9 compatibility, method name has changed in Drupal 10. - // @phpstan-ignore-next-line - if ($cors_service->isActualRequestAllowed($request)) { + if ($cors_service->isOriginAllowed($request)) { return; } } diff --git a/tests/src/Kernel/DataProducer/EntityDefinitionTest.php b/tests/src/Kernel/DataProducer/EntityDefinitionTest.php index 18fba53f1..033cfbb8c 100644 --- a/tests/src/Kernel/DataProducer/EntityDefinitionTest.php +++ b/tests/src/Kernel/DataProducer/EntityDefinitionTest.php @@ -497,8 +497,8 @@ enum FieldTypes { ]) ); - // @todo Different description between Drupal 9 and 10, can be removed when - // Drupal 9 support is dropped. + // @todo Different description between Drupal 10.1 and 10.2, can be removed + // when Drupal 10.1 support is dropped. $this->fullDefinitionResult['entityDefinition']['fields'][11]['description'] = $this->container->get('entity_field.manager')->getBaseFieldDefinitions('node')['created']->getDescription(); } diff --git a/tests/src/Kernel/DataProducer/EntityReferenceTest.php b/tests/src/Kernel/DataProducer/EntityReferenceTest.php index b64d2d897..bb3a8cc40 100644 --- a/tests/src/Kernel/DataProducer/EntityReferenceTest.php +++ b/tests/src/Kernel/DataProducer/EntityReferenceTest.php @@ -7,8 +7,8 @@ use Drupal\node\Entity\NodeType; use Drupal\Tests\graphql\Kernel\GraphQLTestBase; -// @todo Drupal 9 compatibility: use the deprecated trait for Drupal 9. -if (strpos(\Drupal::VERSION, '9') === 0) { +// @todo Drupal 10.1 compatibility: use the deprecated trait for Drupal 10.1. +if (strpos(\Drupal::VERSION, '10.1') === 0) { /** * Helper trait for compatibility with Drupal 9.