Skip to content
Snippets Groups Projects
Verified Commit 4e42a4f9 authored by Dave Long's avatar Dave Long
Browse files

Issue #3506931 by mondrake, brandonlira, adwivedi008, daffie, charlliequadros,...

Issue #3506931 by mondrake, brandonlira, adwivedi008, daffie, charlliequadros, smustgrave: Deprecate passing $root to \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl
parent 0ed12ae5
Branches
Tags
3 merge requests!5423Draft: Resolve #3329907 "Test2",!3478Issue #3337882: Deleted menus are not removed from content type config,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #487738 passed with warnings
Pipeline: drupal

#487745

    Pipeline: drupal

    #487743

      Pipeline: drupal

      #487741

        ...@@ -1315,8 +1315,8 @@ public function __sleep(): array { ...@@ -1315,8 +1315,8 @@ public function __sleep(): array {
        * @param string $url * @param string $url
        * The URL. * The URL.
        * @param string $root * @param string $root
        * The root directory of the Drupal installation. Some database drivers, * (deprecated) The root directory of the Drupal installation. Some
        * like for example SQLite, need this information. * database drivers, like for example SQLite, need this information.
        * *
        * @return array * @return array
        * The connection options. * The connection options.
        ...@@ -1332,6 +1332,10 @@ public function __sleep(): array { ...@@ -1332,6 +1332,10 @@ public function __sleep(): array {
        * @see \Drupal\Core\Database\Database::convertDbUrlToConnectionInfo() * @see \Drupal\Core\Database\Database::convertDbUrlToConnectionInfo()
        */ */
        public static function createConnectionOptionsFromUrl($url, $root) { public static function createConnectionOptionsFromUrl($url, $root) {
        if ($root !== NULL) {
        @trigger_error("Passing the \$root value to " . __METHOD__ . "() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3511287", E_USER_DEPRECATED);
        }
        $url_components = parse_url($url); $url_components = parse_url($url);
        if (!isset($url_components['scheme'], $url_components['host'], $url_components['path'])) { if (!isset($url_components['scheme'], $url_components['host'], $url_components['path'])) {
        throw new \InvalidArgumentException("The database connection URL '$url' is invalid. The minimum requirement is: 'driver://host/database'"); throw new \InvalidArgumentException("The database connection URL '$url' is invalid. The minimum requirement is: 'driver://host/database'");
        ......
        ...@@ -559,7 +559,7 @@ public static function convertDbUrlToConnectionInfo($url, $root, ?bool $include_ ...@@ -559,7 +559,7 @@ public static function convertDbUrlToConnectionInfo($url, $root, ?bool $include_
        $additional_class_loader->register(TRUE); $additional_class_loader->register(TRUE);
        $options = $connection_class::createConnectionOptionsFromUrl($url, $root); $options = $connection_class::createConnectionOptionsFromUrl($url, NULL);
        // Add the necessary information to autoload code. // Add the necessary information to autoload code.
        // @see \Drupal\Core\Site\Settings::initialize() // @see \Drupal\Core\Site\Settings::initialize()
        ......
        ...@@ -442,7 +442,10 @@ public function getFullQualifiedTableName($table) { ...@@ -442,7 +442,10 @@ public function getFullQualifiedTableName($table) {
        * {@inheritdoc} * {@inheritdoc}
        */ */
        public static function createConnectionOptionsFromUrl($url, $root) { public static function createConnectionOptionsFromUrl($url, $root) {
        $database = parent::createConnectionOptionsFromUrl($url, $root); if ($root !== NULL) {
        @trigger_error("Passing the \$root value to " . __METHOD__ . "() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3511287", E_USER_DEPRECATED);
        }
        $database = parent::createConnectionOptionsFromUrl($url, NULL);
        // A SQLite database path with two leading slashes indicates a system path. // A SQLite database path with two leading slashes indicates a system path.
        // Otherwise the path is relative to the Drupal root. // Otherwise the path is relative to the Drupal root.
        ......
        ...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
        use Drupal\sqlite\Driver\Database\sqlite\Connection; use Drupal\sqlite\Driver\Database\sqlite\Connection;
        use Drupal\Tests\Core\Database\Stub\StubPDO; use Drupal\Tests\Core\Database\Stub\StubPDO;
        use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
        use PHPUnit\Framework\Attributes\IgnoreDeprecations;
        /** /**
        * @coversDefaultClass \Drupal\sqlite\Driver\Database\sqlite\Connection * @coversDefaultClass \Drupal\sqlite\Driver\Database\sqlite\Connection
        ...@@ -24,9 +25,8 @@ class ConnectionTest extends UnitTestCase { ...@@ -24,9 +25,8 @@ class ConnectionTest extends UnitTestCase {
        * Expected connection option. * Expected connection option.
        */ */
        public function testCreateConnectionOptionsFromUrl(string $url, string $expected): void { public function testCreateConnectionOptionsFromUrl(string $url, string $expected): void {
        $root = dirname(__DIR__, 8);
        $sqlite_connection = new Connection($this->createMock(StubPDO::class), []); $sqlite_connection = new Connection($this->createMock(StubPDO::class), []);
        $database = $sqlite_connection->createConnectionOptionsFromUrl($url, $root); $database = $sqlite_connection->createConnectionOptionsFromUrl($url, NULL);
        $this->assertEquals('sqlite', $database['driver']); $this->assertEquals('sqlite', $database['driver']);
        $this->assertEquals($expected, $database['database']); $this->assertEquals($expected, $database['database']);
        } }
        ...@@ -47,4 +47,17 @@ public static function providerCreateConnectionOptionsFromUrl(): array { ...@@ -47,4 +47,17 @@ public static function providerCreateConnectionOptionsFromUrl(): array {
        ]; ];
        } }
        /**
        * Confirms deprecation of the $root argument.
        */
        #[IgnoreDeprecations]
        public function testDeprecationOfRootInConnectionOptionsFromUrl(): void {
        $this->expectDeprecation('Passing the $root value to Drupal\sqlite\Driver\Database\sqlite\Connection::createConnectionOptionsFromUrl() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3511287');
        $root = dirname(__DIR__, 8);
        $sqlite_connection = new Connection($this->createMock(StubPDO::class), []);
        $database = $sqlite_connection->createConnectionOptionsFromUrl('sqlite://localhost/tmp/test', $root);
        $this->assertEquals('sqlite', $database['driver']);
        $this->assertEquals('tmp/test', $database['database']);
        }
        } }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment