From 264ef11a48fd9fdef7fad9835271a5156794e610 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 17 Jul 2024 09:54:31 +0200 Subject: [PATCH] Add support for Symfony 7 and Jackalope 2 (#684) * Upgrade to Symfony 7 * Fix jackalope 2 compatibility * Allow installation of jms serializer bundel 5 * Test Symfony 7 branch * Test support for PHP 8.4 * Apply suggestions from code review * Fix lint commands * Upgrade some actions * Fix code style and change CI --- .github/workflows/test-application.yaml | 33 ++++++++++++++----- Command/ArticleExportCommand.php | 9 +++-- Command/ArticleImportCommand.php | 9 +++-- Command/ReindexCommand.php | 11 +++++-- DependencyInjection/Configuration.php | 2 +- .../ArticleContentQueryBuilderTest.php | 4 ++- composer.json | 26 +++++++-------- 7 files changed, 61 insertions(+), 33 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 6db92ac7..fa5fbcc0 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -83,9 +83,22 @@ jobs: ELASTICSEARCH_HOST: '127.0.0.1:9200' - php-version: '8.3' - elasticsearch-version: '7.11.1' - elasticsearch-package-constraint: '~7.11.0' - phpcr-transport: jackrabbit + elasticsearch-version: '7.17.2' + elasticsearch-package-constraint: '~7.17.0' + phpcr-transport: doctrinedbal + dependency-versions: 'highest' + php-extensions: 'ctype, iconv, mysql, imagick' + tools: 'composer:v2' + phpstan: false + env: + SYMFONY_DEPRECATIONS_HELPER: weak + ELASTICSEARCH_HOST: '127.0.0.1:9200' + + - php-version: '8.4' + composer-options: '--ignore-platform-reqs' + elasticsearch-version: '7.17.2' + elasticsearch-package-constraint: '~7.17.0' + phpcr-transport: doctrinedbal dependency-versions: 'highest' php-extensions: 'ctype, iconv, mysql, imagick' tools: 'composer:v2' @@ -126,7 +139,7 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -136,14 +149,16 @@ jobs: tools: ${{ matrix.tools }} coverage: none - - name: Remove not required tooling - run: composer remove php-cs-fixer/shim "*phpstan*" --dev --no-interaction --no-update + - name: Remove Lint Tools + # These tools are not required to run tests, so we are removing them to improve dependency resolving and + # testing lowest versions. + run: composer remove "*php-cs-fixer*" "*phpstan*" "*rector*" --dev --no-update - name: Require elasticsearch dependency run: composer require --dev elasticsearch/elasticsearch:"${{ matrix.elasticsearch-package-constraint }}" --no-interaction --no-update - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: ${{matrix.dependency-versions}} composer-options: ${{ matrix.composer-options }} @@ -165,7 +180,7 @@ jobs: steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -179,7 +194,7 @@ jobs: run: composer require --dev elasticsearch/elasticsearch:"~7.11.0" --no-interaction --no-update - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: ${{matrix.dependency-versions}} composer-options: ${{ matrix.composer-options }} diff --git a/Command/ArticleExportCommand.php b/Command/ArticleExportCommand.php index 10a30ed8..7c838155 100644 --- a/Command/ArticleExportCommand.php +++ b/Command/ArticleExportCommand.php @@ -21,6 +21,9 @@ class ArticleExportCommand extends Command { + /** + * @var string + */ protected static $defaultName = 'sulu:article:export'; /** @@ -30,12 +33,12 @@ class ArticleExportCommand extends Command public function __construct(ArticleExportInterface $articleExporter) { - parent::__construct(); + parent::__construct(static::$defaultName); $this->articleExporter = $articleExporter; } - protected function configure() + protected function configure(): void { $this->addArgument('target', InputArgument::REQUIRED, 'export.xliff') ->addArgument('locale', InputArgument::REQUIRED) @@ -43,7 +46,7 @@ protected function configure() ->setDescription('Export article translations from given language into xliff file for translating into a new language.'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $target = $input->getArgument('target'); if (0 === !\strpos($target, '/')) { diff --git a/Command/ArticleImportCommand.php b/Command/ArticleImportCommand.php index 6275a675..f0eb8a28 100644 --- a/Command/ArticleImportCommand.php +++ b/Command/ArticleImportCommand.php @@ -25,6 +25,9 @@ class ArticleImportCommand extends Command { + /** + * @var string + */ protected static $defaultName = 'sulu:article:import'; /** @@ -39,13 +42,13 @@ class ArticleImportCommand extends Command public function __construct(ArticleImportInterface $articleImporter, ?LoggerInterface $logger = null) { - parent::__construct(); + parent::__construct(static::$defaultName); $this->articleImporter = $articleImporter; $this->logger = $logger ?: new NullLogger(); } - protected function configure() + protected function configure(): void { $this->addArgument('file', InputArgument::REQUIRED, 'export.xliff') ->addArgument('locale', InputArgument::REQUIRED) @@ -55,7 +58,7 @@ protected function configure() ->setDescription('Import article translations from xliff file into a specific language.'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $filePath = $input->getArgument('file'); if (0 === !\strpos($filePath, '/')) { diff --git a/Command/ReindexCommand.php b/Command/ReindexCommand.php index 67598f61..ca15552a 100644 --- a/Command/ReindexCommand.php +++ b/Command/ReindexCommand.php @@ -30,6 +30,11 @@ */ class ReindexCommand extends Command { + /** + * @var string + */ + protected static $defaultName = 'sulu:article:reindex'; + /** * @var WebspaceManagerInterface */ @@ -68,7 +73,7 @@ public function __construct( IndexerInterface $liveIndexer, string $suluContext ) { - parent::__construct('sulu:article:reindex'); + parent::__construct(static::$defaultName); $this->webspaceManager = $webspaceManager; $this->propertyEncoder = $propertyEncoder; $this->documentManager = $documentManager; @@ -77,7 +82,7 @@ public function __construct( $this->suluContext = $suluContext; } - public function configure() + public function configure(): void { $this->setDescription('Rebuild elastic-search index for articles'); $this->setHelp('This command will load all articles and index them to elastic-search indexes.'); @@ -85,7 +90,7 @@ public function configure() $this->addOption('clear', null, InputOption::VALUE_NONE, 'Clear all articles of index before reindex'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $startTime = \microtime(true); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index efd5a5b2..3704c1ab 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -21,7 +21,7 @@ */ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('sulu_article'); $rootNode = $treeBuilder->getRootNode(); diff --git a/Tests/Functional/Infrastructure/Sulu/Content/ArticleContentQueryBuilderTest.php b/Tests/Functional/Infrastructure/Sulu/Content/ArticleContentQueryBuilderTest.php index c8ffdce0..713aa07f 100644 --- a/Tests/Functional/Infrastructure/Sulu/Content/ArticleContentQueryBuilderTest.php +++ b/Tests/Functional/Infrastructure/Sulu/Content/ArticleContentQueryBuilderTest.php @@ -413,7 +413,9 @@ private function save( if (!$isShadow) { /* @var ArticleDocument $document */ try { - $document = $this->documentManager->find($uuid, $locale, ['load_ghost_content' => false]); + $document = $uuid + ? $this->documentManager->find($uuid, $locale, ['load_ghost_content' => false]) + : $this->documentManager->create('article'); } catch (DocumentNotFoundException $e) { $document = $this->documentManager->create('article'); } diff --git a/composer.json b/composer.json index a5348685..b435df70 100644 --- a/composer.json +++ b/composer.json @@ -21,23 +21,23 @@ "php": "^7.3 || ^8.0", "ext-json": "*", "elasticsearch/elasticsearch": "^5.0 || ^6.0 || ^7.0", - "handcraftedinthealps/elasticsearch-bundle": "^5.2.6.4", + "handcraftedinthealps/elasticsearch-bundle": "^5.2.6.4 || ^5.2.6.4@dev", "handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1 || ^6.2.0.1 || ^7.2.0.1", "jms/serializer": "^3.3", - "jms/serializer-bundle": "^3.3 || ^4.0", + "jms/serializer-bundle": "^3.3 || ^4.0 || ^5.0", "sulu/sulu": "~2.4.13 || ^2.5.9@dev", - "symfony/config": "^4.3 || ^5.0 || ^6.0", - "symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0", - "symfony/http-foundation": "^4.3 || ^5.0 || ^6.0", - "symfony/http-kernel": "^4.3 || ^5.0 || ^6.0", + "symfony/config": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/http-foundation": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/http-kernel": "^4.3 || ^5.0 || ^6.0 || ^7.0", "symfony-cmf/slugifier-api": "^1.0 || ^2.0", "twig/twig": "^1.41 || ^2.0 || ^3.0" }, "require-dev": { "doctrine/data-fixtures": "^1.1", "handcraftedinthealps/zendsearch": "^2.0", - "jackalope/jackalope-doctrine-dbal": "^1.3.4", - "jackalope/jackalope-jackrabbit": "^1.3", + "jackalope/jackalope-doctrine-dbal": "^1.3.4 || ^2.0", + "jackalope/jackalope-jackrabbit": "^1.3 || ^2.0", "jangregor/phpstan-prophecy": "^1.0", "massive/build-bundle": "^0.3 || ^0.4 || ^0.5", "php-cs-fixer/shim": "^3.0", @@ -51,12 +51,12 @@ "phpunit/phpunit": "^8.2", "sulu/automation-bundle": "^2.0 || ^2.1@dev", "sulu/headless-bundle": "^0.8 || ^0.9 || ^0.10@dev", - "symfony/browser-kit": "^4.3 || ^5.0 || ^6.0", - "symfony/dotenv": "^4.3 || ^5.0 || ^6.0", - "symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0", + "symfony/browser-kit": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/dotenv": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0 || ^7.0", "symfony/monolog-bundle": "^3.1", - "symfony/security-bundle": "^4.3 || ^5.0 || ^6.0", - "symfony/stopwatch": "^4.3 || ^5.0 || ^6.0" + "symfony/security-bundle": "^4.3 || ^5.0 || ^6.0 || ^7.0", + "symfony/stopwatch": "^4.3 || ^5.0 || ^6.0 || ^7.0" }, "conflict": { "guzzlehttp/ringphp": "<1.1.1",