Commit 05f5a676 authored by catch's avatar catch

Issue #2999678 by andypost: Properly deprecate db_field_exists

parent e3587aae
......@@ -698,6 +698,7 @@ function db_table_exists($table) {
* @see \Drupal\Core\Database\Schema::fieldExists()
*/
function db_field_exists($table, $field) {
@trigger_error('db_field_exists() 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 fieldExists() on it. For example, $injected_database->schema()->fieldExists($table, $field). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
return Database::getConnection()->schema()->fieldExists($table, $field);
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\content_translation\Kernel;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;
/**
......@@ -31,9 +32,10 @@ protected function setUp() {
*/
public function testSettingsApi() {
$this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
$schema = Database::getConnection()->schema();
$result =
db_field_exists('entity_test_mul_property_data', 'content_translation_source') &&
db_field_exists('entity_test_mul_property_data', 'content_translation_outdated');
$schema->fieldExists('entity_test_mul_property_data', 'content_translation_source') &&
$schema->fieldExists('entity_test_mul_property_data', 'content_translation_outdated');
$this->assertTrue($result, 'Schema updates correctly performed.');
}
......
......@@ -236,6 +236,15 @@ public function testDbDropField() {
$this->assertFalse($this->connection->schema()->fieldExists('test', 'age'));
}
/**
* Tests deprecation of the db_field_exists() function.
*
* @expectedDeprecation db_field_exists() 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 fieldExists() on it. For example, $injected_database->schema()->fieldExists($table, $field). See https://www.drupal.org/node/2993033
*/
public function testDbFieldExists() {
$this->assertTrue(db_field_exists('test', 'age'));
}
/**
* Tests deprecation of the db_field_names() function.
*
......
......@@ -42,11 +42,12 @@ public function testDBTableExists() {
}
/**
* Tests the db_field_exists() function.
* Tests the \Drupal\Core\Database\Schema::fieldExists() method.
*/
public function testDBFieldExists() {
$this->assertSame(TRUE, db_field_exists('test', 'name'), 'Returns true for existent column.');
$this->assertSame(FALSE, db_field_exists('test', 'nosuchcolumn'), 'Returns false for nonexistent column.');
$schema = $this->connection->schema();
$this->assertSame(TRUE, $schema->fieldExists('test', 'name'), 'Returns true for existent column.');
$this->assertSame(FALSE, $schema->fieldExists('test', 'nosuchcolumn'), 'Returns false for nonexistent column.');
}
/**
......
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