Commit 2a4fa156 authored by catch's avatar catch

Issue #2999586 by interX, andypost, mondrake: Properly deprecate db_add_index

parent 061c632f
......@@ -972,7 +972,8 @@ function db_drop_unique_key($table, $name) {
* @see \Drupal\Core\Database\Schema::addIndex()
*/
function db_add_index($table, $name, $fields, array $spec) {
return Database::getConnection()->schema()->addIndex($table, $name, $fields, $spec);
@trigger_error('db_add_index() is deprecated in Drupal 8.0.x and will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
Database::getConnection()->schema()->addIndex($table, $name, $fields, $spec);
}
/**
......
......@@ -5,6 +5,8 @@
* Update hooks and schema definition for the update_test_schema module.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_schema().
*
......@@ -44,7 +46,7 @@ function update_test_schema_update_8001() {
];
// Add a column.
db_add_index('update_test_schema_table', 'test', ['a'], $table);
Database::getConnection()->schema()->addIndex('update_test_schema_table', 'test', ['a'], $table);
}
}
......@@ -426,4 +426,24 @@ public function testDbQueryRange() {
$this->assertSame(3, $count);
}
/**
* Tests deprecation of the db_add_index() function.
*
* @expectedDeprecation db_add_index() is deprecated in Drupal 8.0.x and will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033
*/
public function testDbAddIndex() {
$table_specification = [
'fields' => [
'age' => [
'description' => "The person's age",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
],
];
$this->assertNull(db_add_index('test', 'test', ['age'], $table_specification));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment