Commit 53c4c3c2 authored by catch's avatar catch

Issue #2993577 by mondrake, voleger, andypost: Properly deprecate...

Issue #2993577 by mondrake, voleger, andypost: Properly deprecate db_add_field, db_drop_field, db_field_names
parent 5cbcd6d3
...@@ -607,6 +607,7 @@ function db_create_table($name, $table) { ...@@ -607,6 +607,7 @@ function db_create_table($name, $table) {
* @see \Drupal\Core\Database\Schema::fieldNames() * @see \Drupal\Core\Database\Schema::fieldNames()
*/ */
function db_field_names($fields) { function db_field_names($fields) {
@trigger_error('db_field_names() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldNames() on it. For example, $injected_database->schema()->fieldNames($fields). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
return Database::getConnection()->schema()->fieldNames($fields); return Database::getConnection()->schema()->fieldNames($fields);
} }
...@@ -764,6 +765,7 @@ function db_drop_table($table) { ...@@ -764,6 +765,7 @@ function db_drop_table($table) {
* @see \Drupal\Core\Database\Schema::changeField() * @see \Drupal\Core\Database\Schema::changeField()
*/ */
function db_add_field($table, $field, $spec, $keys_new = []) { function db_add_field($table, $field, $spec, $keys_new = []) {
@trigger_error('db_add_field() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addField() on it. For example, $injected_database->schema()->addField($table, $field, $spec, $keys_new). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new); return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new);
} }
...@@ -787,6 +789,7 @@ function db_add_field($table, $field, $spec, $keys_new = []) { ...@@ -787,6 +789,7 @@ function db_add_field($table, $field, $spec, $keys_new = []) {
* @see \Drupal\Core\Database\Schema::dropField() * @see \Drupal\Core\Database\Schema::dropField()
*/ */
function db_drop_field($table, $field) { function db_drop_field($table, $field) {
@trigger_error('db_drop_field() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropField() on it. For example, $injected_database->schema()->dropField($table, $field). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
return Database::getConnection()->schema()->dropField($table, $field); return Database::getConnection()->schema()->dropField($table, $field);
} }
......
...@@ -78,4 +78,40 @@ public function testDbClose() { ...@@ -78,4 +78,40 @@ public function testDbClose() {
$this->assertFalse(Database::isActiveConnection(), 'Database connection is not active'); $this->assertFalse(Database::isActiveConnection(), 'Database connection is not active');
} }
/**
* Tests deprecation of the db_add_field() function.
*
* @expectedDeprecation db_add_field() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addField() on it. For example, $injected_database->schema()->addField($table, $field, $spec, $keys_new). See https://www.drupal.org/node/2993033
*/
public function testDbAddField() {
$this->assertFalse($this->connection->schema()->fieldExists('test', 'anint'));
db_add_field('test', 'anint', [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Added int column.',
]);
$this->assertTrue($this->connection->schema()->fieldExists('test', 'anint'));
}
/**
* Tests deprecation of the db_drop_field() function.
*
* @expectedDeprecation db_drop_field() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropField() on it. For example, $injected_database->schema()->dropField($table, $field). See https://www.drupal.org/node/2993033
*/
public function testDbDropField() {
$this->assertTrue($this->connection->schema()->fieldExists('test', 'age'));
$this->assertTrue(db_drop_field('test', 'age'));
$this->assertFalse($this->connection->schema()->fieldExists('test', 'age'));
}
/**
* Tests deprecation of the db_field_names() function.
*
* @expectedDeprecation db_field_names() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldNames() on it. For example, $injected_database->schema()->fieldNames($fields). See https://www.drupal.org/node/2993033
*/
public function testDbFieldNames() {
$this->assertSame(['test_field'], db_field_names(['test_field']));
}
} }
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