Verified Commit db2875d5 authored by Dave Long's avatar Dave Long
Browse files

task: #3525077 Remove deprecated paths from the Database API & friends

By: mondrake
By: dcam
By: smustgrave
parent 648ed214
Loading
Loading
Loading
Loading
Loading
+0 −6
Changes for core/.deprecation-ignore.txt: 0 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -27,12 +27,6 @@
# Drupal 12.
%expectDeprecation\(\) is deprecated in drupal:11\.4\.0%
%ExpectDeprecationTrait is deprecated in drupal:11\.4\.0%
%The "Drupal\\Core\\Database\\Query\\Select::hasAllTags\(\)" method will require a new "string \.\.\. \$tags" argument in the next major version of its interface%
%The "Drupal\\Core\\Database\\Query\\Select::hasAnyTag\(\)" method will require a new "string \.\.\. \$tags" argument in the next major version of its interface%
%The "Drupal\\Core\\Database\\Query\\SelectExtender::hasAllTags\(\)" method will require a new "string \.\.\. \$tags" argument in the next major version of its interface%
%The "Drupal\\Core\\Database\\Query\\SelectExtender::hasAnyTag\(\)" method will require a new "string \.\.\. \$tags" argument in the next major version of its interface%
%The "Drupal\\Core\\Entity\\Query\\QueryBase::hasAllTags\(\)" method will require a new "string \.\.\. \$tags" argument in the next major version of its interface%
%The "Drupal\\Core\\Entity\\Query\\QueryBase::hasAnyTag\(\)" method will require a new "string \.\.\. \$tags" argument in the next major version of its interface%
%The "Drupal\\workspaces\\WorkspaceManager::setActiveWorkspace\(\)" method will require a new "bool \$persist" argument in the next major version of its interface%
%The "Drupal\\(?:Core\\(?:Action|Field|Condition)|(?:user|action_test|action_bulk_test|user_batch_action_test)\\Plugin\\Action)\\.*::execute\(\)" method will require a new "object\|null \$object" argument in the next major version of its interface "Drupal\\Core\\Executable\\ExecutableInterface"%
%The "(?:Drupal\\Core\\Layout\\LayoutPluginManagerInterface|Drupal\\Core\\Block\\BlockManager)::get(?:Sorted|Grouped)Definitions\(\)" method will require a new "string \$label_key" argument in the next major version of its interface "Drupal\\Component\\Plugin\\CategorizingPluginManagerInterface"%
+0 −12
Changes for core/.phpstan-baseline.php: 0 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -3775,18 +3775,6 @@
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/Schema.php',
];
$ignoreErrors[] = [
	'message' => '#^Cannot unset property Drupal\\\\Core\\\\Database\\\\Statement\\\\StatementBase\\:\\:\\$clientStatement because it might have hooks in a subclass\\.$#',
	'identifier' => 'unset.possiblyHookedProperty',
	'count' => 2,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/StatementPrefetchIterator.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\StatementPrefetchIterator\\:\\:fetchColumn\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/lib/Drupal/Core/Database/StatementPrefetchIterator.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Core\\\\Database\\\\Transaction\\:\\:name\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+3 −14
Changes for core/lib/Drupal/Core/Database/Connection.php: 3 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -432,9 +432,7 @@ public function getFullQualifiedTableName($table) {
   */
  public function prepareStatement(string $query, array $options, bool $allow_row_count = FALSE): StatementInterface {
    assert(!isset($options['return']), 'Passing "return" option to prepareStatement() has no effect. See https://www.drupal.org/node/3185520');
    if (isset($options['fetch']) && is_int($options['fetch'])) {
      @trigger_error("Passing the 'fetch' key as an integer to \$options in prepareStatement() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
    }
    assert(!isset($options['fetch']) || $options['fetch'] instanceof FetchAs || is_string($options['fetch']), 'The "fetch" option passed to prepareStatement() must contain a FetchAs enum case or a string. See https://www.drupal.org/node/3488338');

    try {
      $query = $this->preprocessStatement($query, $options);
@@ -653,9 +651,7 @@ public function query($query, array $args = [], $options = []) {
    assert(is_string($query), 'The \'$query\' argument to ' . __METHOD__ . '() must be a string');
    assert(!isset($options['return']), 'Passing "return" option to query() has no effect. See https://www.drupal.org/node/3185520');
    assert(!isset($options['target']), 'Passing "target" option to query() has no effect. See https://www.drupal.org/node/2993033');
    if (isset($options['fetch']) && is_int($options['fetch'])) {
      @trigger_error("Passing the 'fetch' key as an integer to \$options in query() is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use a case of \Drupal\Core\Database\Statement\FetchAs enum instead. See https://www.drupal.org/node/3488338", E_USER_DEPRECATED);
    }
    assert(!isset($options['fetch']) || $options['fetch'] instanceof FetchAs || is_string($options['fetch']), 'The "fetch" option passed to query() must contain a FetchAs enum case or a string. See https://www.drupal.org/node/3488338');

    // Use default values if not already set.
    $options += $this->defaultOptions();
@@ -1314,9 +1310,6 @@ public function __sleep(): array {
   *
   * @param string $url
   *   The URL.
   * @param string|null $root
   *   (deprecated) The root directory of the Drupal installation. Some
   *   database drivers, like for example SQLite, need this information.
   *
   * @return array
   *   The connection options.
@@ -1331,11 +1324,7 @@ public function __sleep(): array {
   *
   * @see \Drupal\Core\Database\Database::convertDbUrlToConnectionInfo()
   */
  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);
    }

  public static function createConnectionOptionsFromUrl($url) {
    $url_components = parse_url($url);
    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'");
+2 −13
Changes for core/lib/Drupal/Core/Database/Database.php: 2 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -497,8 +497,6 @@ public static function ignoreTarget($key, $target) {
   *
   * @param string $url
   *   The URL.
   * @param string|bool|null $root
   *   (deprecated) The root directory of the Drupal installation.
   * @param bool|null $include_test_drivers
   *   (optional) Whether to include test extensions. If FALSE, all 'tests'
   *   directories are excluded in the search. When NULL will be determined by
@@ -513,16 +511,7 @@ public static function ignoreTarget($key, $target) {
   * @throws \RuntimeException
   *   Exception thrown when a module provided database driver does not exist.
   */
  public static function convertDbUrlToConnectionInfo(string $url, $root = NULL, ?bool $include_test_drivers = NULL): array {
    if ($root !== NULL) {
      if (is_bool($root)) {
        $include_test_drivers = $root;
      }
      else {
        @trigger_error("Passing a string \$root value to " . __METHOD__ . "() is deprecated in drupal:11.3.0 and will be removed in drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3511287", E_USER_DEPRECATED);
      }
    }

  public static function convertDbUrlToConnectionInfo(string $url, ?bool $include_test_drivers = NULL): array {
    // Check that the URL is well formed, starting with 'scheme://', where
    // 'scheme' is a database driver name.
    if (preg_match('/^(.*):\/\//', $url, $matches) !== 1) {
@@ -570,7 +559,7 @@ public static function convertDbUrlToConnectionInfo(string $url, $root = NULL, ?

    $additional_class_loader->register(TRUE);

    $options = $connection_class::createConnectionOptionsFromUrl($url, NULL);
    $options = $connection_class::createConnectionOptionsFromUrl($url);

    // Add the necessary information to autoload code.
    // @see \Drupal\Core\Site\Settings::initialize()
+11 −46
Changes for core/lib/Drupal/Core/Database/FetchModeTrait.php: 11 added lines, 46 removed lines.
Original line number Diff line number Diff line
@@ -10,78 +10,43 @@
trait FetchModeTrait {

  /**
   * Map FETCH_* modes to their literal for inclusion in messages.
   *
   * @see https://github.com/php/php-src/blob/master/ext/pdo/php_pdo_driver.h#L65-L80
   */
  protected array $fetchModeLiterals = [
    \PDO::FETCH_DEFAULT => 'FETCH_DEFAULT',
    \PDO::FETCH_LAZY => 'FETCH_LAZY',
    \PDO::FETCH_ASSOC => 'FETCH_ASSOC',
    \PDO::FETCH_NUM => 'FETCH_NUM',
    \PDO::FETCH_BOTH => 'FETCH_BOTH',
    \PDO::FETCH_OBJ => 'FETCH_OBJ',
    \PDO::FETCH_BOUND => 'FETCH_BOUND',
    \PDO::FETCH_COLUMN => 'FETCH_COLUMN',
    \PDO::FETCH_CLASS => 'FETCH_CLASS',
    \PDO::FETCH_INTO => 'FETCH_INTO',
    \PDO::FETCH_FUNC => 'FETCH_FUNC',
    \PDO::FETCH_NAMED => 'FETCH_NAMED',
    \PDO::FETCH_KEY_PAIR => 'FETCH_KEY_PAIR',
    \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE => 'FETCH_CLASS | FETCH_CLASSTYPE',
    \PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE => 'FETCH_CLASS | FETCH_PROPS_LATE',
  ];

  /**
   * The fetch modes supported.
   */
  protected array $supportedFetchModes = [
    \PDO::FETCH_ASSOC,
    \PDO::FETCH_CLASS,
    \PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE,
    \PDO::FETCH_COLUMN,
    \PDO::FETCH_NUM,
    \PDO::FETCH_OBJ,
  ];

  /**
   * Converts a row of data in FETCH_ASSOC format to FETCH_NUM.
   * Converts a row of data in associative format to list.
   *
   * @param array $rowAssoc
   *   A row of data in FETCH_ASSOC format.
   *   A row of data in associative format.
   *
   * @return array
   *   The row in FETCH_NUM format.
   *   The row in list format.
   */
  protected function assocToNum(array $rowAssoc): array {
    return array_values($rowAssoc);
  }

  /**
   * Converts a row of data in FETCH_ASSOC format to FETCH_OBJ.
   * Converts a row of data in associative format to object.
   *
   * @param array $rowAssoc
   *   A row of data in FETCH_ASSOC format.
   *   A row of data in associative format.
   *
   * @return object
   *   The row in FETCH_OBJ format.
   *   The row in object format.
   */
  protected function assocToObj(array $rowAssoc): \stdClass {
    return (object) $rowAssoc;
  }

  /**
   * Converts a row of data in FETCH_ASSOC format to FETCH_CLASS.
   * Converts a row of data in associative format to classed object.
   *
   * @param array $rowAssoc
   *   A row of data in FETCH_ASSOC format.
   *   A row of data in associative format.
   * @param string $className
   *   Name of the created class.
   * @param array $constructorArguments
   *   Elements of this array are passed to the constructor.
   *
   * @return object
   *   The row in FETCH_CLASS format.
   *   The row in classed object format.
   */
  protected function assocToClass(array $rowAssoc, string $className, array $constructorArguments): object {
    $classObj = new $className(...$constructorArguments);
@@ -92,10 +57,10 @@ protected function assocToClass(array $rowAssoc, string $className, array $const
  }

  /**
   * Converts a row of data in FETCH_ASSOC format to FETCH_COLUMN.
   * Converts a row of data in associative format to column.
   *
   * @param array $rowAssoc
   *   A row of data in FETCH_ASSOC format.
   *   A row of data in associative format.
   * @param string[] $columnNames
   *   The list of the row columns.
   * @param int $columnIndex
Loading