Issue #2999678 by andypost: Properly deprecate db_field_exists
parent
e3587aae73
commit
05f5a67660
|
@ -698,6 +698,7 @@ function db_table_exists($table) {
|
||||||
* @see \Drupal\Core\Database\Schema::fieldExists()
|
* @see \Drupal\Core\Database\Schema::fieldExists()
|
||||||
*/
|
*/
|
||||||
function db_field_exists($table, $field) {
|
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);
|
return Database::getConnection()->schema()->fieldExists($table, $field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Drupal\Tests\content_translation\Kernel;
|
namespace Drupal\Tests\content_translation\Kernel;
|
||||||
|
|
||||||
|
use Drupal\Core\Database\Database;
|
||||||
use Drupal\KernelTests\KernelTestBase;
|
use Drupal\KernelTests\KernelTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,9 +32,10 @@ class ContentTranslationSettingsApiTest extends KernelTestBase {
|
||||||
*/
|
*/
|
||||||
public function testSettingsApi() {
|
public function testSettingsApi() {
|
||||||
$this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
|
$this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
|
||||||
|
$schema = Database::getConnection()->schema();
|
||||||
$result =
|
$result =
|
||||||
db_field_exists('entity_test_mul_property_data', 'content_translation_source') &&
|
$schema->fieldExists('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_outdated');
|
||||||
$this->assertTrue($result, 'Schema updates correctly performed.');
|
$this->assertTrue($result, 'Schema updates correctly performed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,6 +236,15 @@ class DatabaseLegacyTest extends DatabaseTestBase {
|
||||||
$this->assertFalse($this->connection->schema()->fieldExists('test', 'age'));
|
$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.
|
* Tests deprecation of the db_field_names() function.
|
||||||
*
|
*
|
||||||
|
|
|
@ -42,11 +42,12 @@ class RegressionTest extends DatabaseTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the db_field_exists() function.
|
* Tests the \Drupal\Core\Database\Schema::fieldExists() method.
|
||||||
*/
|
*/
|
||||||
public function testDBFieldExists() {
|
public function testDBFieldExists() {
|
||||||
$this->assertSame(TRUE, db_field_exists('test', 'name'), 'Returns true for existent column.');
|
$schema = $this->connection->schema();
|
||||||
$this->assertSame(FALSE, db_field_exists('test', 'nosuchcolumn'), 'Returns false for nonexistent column.');
|
$this->assertSame(TRUE, $schema->fieldExists('test', 'name'), 'Returns true for existent column.');
|
||||||
|
$this->assertSame(FALSE, $schema->fieldExists('test', 'nosuchcolumn'), 'Returns false for nonexistent column.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue