From f2a864008be28c70fb0df51d2faaefeabcc85c3c Mon Sep 17 00:00:00 2001 From: mondrake Date: Fri, 21 Jul 2023 10:26:32 +0200 Subject: [PATCH] Fix for #3217531 Deprecate usage of Connection::getDriverClass for some classes (#329) --- .github/workflows/pr.yml | 182 +++++++++++------------- src/Driver/Database/dbal/Connection.php | 80 ++++++++--- 2 files changed, 145 insertions(+), 117 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 3edd9461..10e06cf4 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -5,102 +5,92 @@ on: branches: [ master ] env: - DRUDBAL_DRUPAL_VERSION: "11.x" - DRUDBAL_DRUPAL_PROFILE: "standard" - SIMPLETEST_BASE_URL: "http://localhost:8080" - PHPUNIT_SKIP_CLASS: '[ - "Drupal\\KernelTests\\Core\\Cache\\ApcuBackendTest", - "Drupal\\Tests\\file\\Functional\\FileAddPermissionsUpdateTest" - ]' + DRUDBAL_DRUPAL_VERSION: "11.x" + DRUDBAL_DRUPAL_PROFILE: "standard" + SIMPLETEST_BASE_URL: "http://localhost:8080" + PHPUNIT_SKIP_CLASS: '[ + "Drupal\\KernelTests\\Core\\Cache\\ApcuBackendTest", + "Drupal\\Tests\\file\\Functional\\FileAddPermissionsUpdateTest" + ]' jobs: - ################################# - - oracle-oci8: - name: "Oracle on Oci8" - runs-on: ubuntu-20.04 - env: - DRUDBAL_ENV: "dbal/oci8" - DBAL_URL: "oci8://DRUDBAL:ORACLE@0.0.0.0:1521/XE" - SIMPLETEST_DB: "dbal://DRUDBAL:ORACLE@0.0.0.0:1521/XE?module=drudbal&dbal_driver=oci8#dru" - - services: - oracle: - image: gvenzl/oracle-xe:slim-faststart - env: - ORACLE_PASSWORD: oracle - ports: - - "1521:1521" - options: >- - --health-cmd healthcheck.sh - --health-interval 20s - --health-timeout 10s - --health-retries 10 - - strategy: - fail-fast: false - matrix: - php-version: - - "8.2" - test-args: - - "--group Database" - # - "--group Entity" - # - "--group Cache,Config" - # - "--group field,Field" - # - "--group file" - # - "--group views" - - steps: - - name: Install PHP - uses: "shivammathur/setup-php@v2" - with: - php-version: "${{ matrix.php-version }}" - coverage: "none" - extensions: "oci8" - ini-values: "zend.assertions=1" - - - name: Checkout Drupal - run: git clone --depth=5 --branch=$DRUDBAL_DRUPAL_VERSION http://git.drupal.org/project/drupal.git . - - - name: Checkout DruDbal - uses: actions/checkout@v3 - with: - path: drudbal_staging - - - name: Patch Drupal - run: ./drudbal_staging/tests/github/drupal_patch.sh - - - name: Install Composer dependencies - run: | - composer install --no-progress --ansi - composer config --no-plugins allow-plugins.composer/package-versions-deprecated true - - - name: Composer require DruDbal from local staging - run: | - git -C drudbal_staging checkout -b test-run-branch - composer config repositories.test-run '{"type": "path", "url": "drudbal_staging", "options": {"symlink": false}}' - composer require "mondrake/drudbal:dev-test-run-branch" --no-progress --ansi - - - name: Create Oracle schema - run: | - cp modules/contrib/drudbal/tests/github/install_* . - php install_oracle.php - - - name: Install Drupal - continue-on-error: true - run: | - vendor/bin/drush site-install standard --db-url=$SIMPLETEST_DB -y - vendor/bin/drush runserver localhost:8080 --default-server=localhost:8080 & - sleep 5s - - - name: Report installation - continue-on-error: true - run: | - php install_report.php - vendor/bin/drush core:status - vendor/bin/drush core:requirements - vendor/bin/drush pml --type=module --no-core - - - name: Run test ${{ matrix.test-args }} - run: vendor/bin/phpunit -c core --color=always ${{ matrix.test-args }} +################################# + + mysql-pdo: + name: "MySql" + runs-on: ubuntu-latest + env: + DRUDBAL_ENV: "dbal/mysql" + DBAL_URL: "mysql://root:@0.0.0.0:3306/drudbal" + SIMPLETEST_DB: "dbal://root:@0.0.0.0:3306/drudbal?module=drudbal&dbal_driver=pdo_mysql" + + strategy: + fail-fast: false + matrix: + php-version: + - "8.2" + test-args: + - "--group Database" +# - "--group Entity" +# - "--group Cache,Config" +# - "--group field,Field" +# - "--group file" +# - "--group views" + + services: + mysql: + image: "mysql:5.7" + options: >- + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes + -e MYSQL_DATABASE=drudbal + ports: + - "3306:3306" + + steps: + - name: Install PHP + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "none" + extensions: "pdo_mysql" + ini-values: "zend.assertions=1" + + - name: Checkout Drupal + run: git clone --depth=5 --branch=$DRUDBAL_DRUPAL_VERSION http://git.drupal.org/project/drupal.git . + + - name: Checkout DruDbal + uses: actions/checkout@v3 + with: + path: drudbal_staging + + - name: Patch Drupal + run: ./drudbal_staging/tests/github/drupal_patch.sh + + - name: Install Composer dependencies + run: | + composer install --no-progress --ansi + composer config --no-plugins allow-plugins.composer/package-versions-deprecated true + + - name: Composer require DruDbal from local staging + run: | + git -C drudbal_staging checkout -b test-run-branch + composer config repositories.test-run '{"type": "path", "url": "drudbal_staging", "options": {"symlink": false}}' + composer require "mondrake/drudbal:dev-test-run-branch" --no-progress --ansi + + - name: Install Drupal + run: | + cp modules/contrib/drudbal/tests/github/install_* . + vendor/bin/drush site-install standard --db-url=$SIMPLETEST_DB -y + vendor/bin/drush runserver localhost:8080 --default-server=localhost:8080 & + sleep 1s + + - name: Report installation + run: | + php install_report.php + vendor/bin/drush core:status + vendor/bin/drush core:requirements + vendor/bin/drush pml --type=module --no-core + + - name: Run test ${{ matrix.test-args }} + run: vendor/bin/phpunit -c core --color=always ${{ matrix.test-args }} diff --git a/src/Driver/Database/dbal/Connection.php b/src/Driver/Database/dbal/Connection.php index 7bb65410..e2421ac0 100644 --- a/src/Driver/Database/dbal/Connection.php +++ b/src/Driver/Database/dbal/Connection.php @@ -2,12 +2,11 @@ namespace Drupal\drudbal\Driver\Database\dbal; -use Drupal\Core\Utility\Error; use Composer\InstalledVersions; use Doctrine\DBAL\Connection as DbalConnection; use Doctrine\DBAL\ConnectionException as DbalConnectionException; -use Doctrine\DBAL\Exception as DbalException; use Doctrine\DBAL\DriverManager as DbalDriverManager; +use Doctrine\DBAL\Exception as DbalException; use Doctrine\DBAL\Exception\DriverException as DbalDriverException; use Doctrine\DBAL\ExpandArrayParameters; use Doctrine\DBAL\Platforms\AbstractPlatform as DbalAbstractPlatform; @@ -19,11 +18,14 @@ use Drupal\Core\Database\Database; use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Database\DatabaseNotFoundException; +use Drupal\Core\Database\Query\Condition; use Drupal\Core\Database\StatementInterface; +use Drupal\Core\Database\Transaction; use Drupal\Core\Database\TransactionCommitFailedException; use Drupal\Core\Database\TransactionNameNonUniqueException; use Drupal\Core\Database\TransactionNoActiveException; use Drupal\Core\Database\TransactionOutOfOrderException; +use Drupal\Core\Utility\Error; use Drupal\drudbal\Driver\Database\dbal\DbalExtension\DbalExtensionInterface; use Drupal\drudbal\Driver\Database\dbal\DbalExtension\MysqliExtension; use Drupal\drudbal\Driver\Database\dbal\DbalExtension\Oci8Extension; @@ -186,25 +188,6 @@ public function lastInsertId(?string $name = NULL): string { return (string) $this->getDbalConnection()->lastInsertId($name); } - /** - * {@inheritdoc} - */ - public function exceptionHandler() { - return new ExceptionHandler($this); - } - - /** - * {@inheritdoc} - */ - public function schema(): Schema { - if (!isset($this->schema)) { - $this->schema = new Schema($this); - } - $schema = $this->schema; - assert($schema instanceof Schema); - return $schema; - } - /** * {@inheritdoc} */ @@ -700,4 +683,59 @@ public function query($query, array $args = [], $options = []) { return parent::query($query, $args, $options); } + public function exceptionHandler() { + return new ExceptionHandler($this); + } + + public function select($table, $alias = NULL, array $options = []) { + return new Select($this, $table, $alias, $options); + } + + public function insert($table, array $options = []) { + return new Insert($this, $table, $options); + } + + public function merge($table, array $options = []) { + return new Merge($this, $table, $options); + } + + public function upsert($table, array $options = []) { + return new Upsert($this, $table, $options); + } + + public function update($table, array $options = []) { + return new Update($this, $table, $options); + } + + public function delete($table, array $options = []) { + return new Delete($this, $table, $options); + } + + public function truncate($table, array $options = []) { + return new Truncate($this, $table, $options); + } + + public function schema(): Schema { + if (!isset($this->schema)) { + $this->schema = new Schema($this); + } + $schema = $this->schema; + assert($schema instanceof Schema); + return $schema; + } + + /** + * @todo remove in D11 + */ + public function condition($conjunction) { + return new Condition($conjunction); + } + + /** + * @todo remove in D11 + */ + public function startTransaction($name = '') { + return new Transaction($this, $name); + } + }