Commit a08c9696 authored by Dries's avatar Dries
Browse files

- Patch #728338 by sun, Crell: standardize on 'field' in function names. 'It...

- Patch #728338 by sun, Crell: standardize on 'field' in function names. 'It has to get worse before it can get better.'
parent 00ecc0a2
......@@ -2571,14 +2571,14 @@ function db_table_exists($table) {
*
* @param $table
* The name of the table in drupal (no prefixing).
* @param $name
* The name of the column.
* @param $field
* The name of the field.
*
* @return
* TRUE if the given column exists, otherwise FALSE.
*/
function db_column_exists($table, $column) {
return Database::getConnection()->schema()->columnExists($table, $column);
function db_field_exists($table, $field) {
return Database::getConnection()->schema()->fieldExists($table, $field);
}
/**
......
......@@ -289,7 +289,7 @@ public function addField($table, $field, $spec, $keys_new = array()) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add field %table.%field: table doesn't exist.", array('%field' => $field, '%table' => $table)));
}
if ($this->columnExists($table, $field)) {
if ($this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot add field %table.%field: field already exists.", array('%field' => $field, '%table' => $table)));
}
......@@ -316,7 +316,7 @@ public function addField($table, $field, $spec, $keys_new = array()) {
}
public function dropField($table, $field) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
return FALSE;
}
......@@ -325,7 +325,7 @@ public function dropField($table, $field) {
}
public function fieldSetDefault($table, $field, $default) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot set default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
......@@ -340,7 +340,7 @@ public function fieldSetDefault($table, $field, $default) {
}
public function fieldSetNoDefault($table, $field) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot remove default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
......@@ -415,10 +415,10 @@ public function dropIndex($table, $name) {
}
public function changeField($table, $field, $field_new, $spec, $keys_new = array()) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot change the definition of field %table.%name: field doesn't exist.", array('%table' => $table, '%name' => $field)));
}
if (($field != $field_new) && $this->columnExists($table, $field_new)) {
if (($field != $field_new) && $this->fieldExists($table, $field_new)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot rename field %table.%name to %name_new: target field already exists.", array('%table' => $table, '%name' => $field, '%name_new' => $field_new)));
}
......
......@@ -313,7 +313,7 @@ public function addField($table, $field, $spec, $new_keys = array()) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add field %table.%field: table doesn't exist.", array('%field' => $field, '%table' => $table)));
}
if ($this->columnExists($table, $field)) {
if ($this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot add field %table.%field: field already exists.", array('%field' => $field, '%table' => $table)));
}
......@@ -343,7 +343,7 @@ public function addField($table, $field, $spec, $new_keys = array()) {
}
public function dropField($table, $field) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
return FALSE;
}
......@@ -352,7 +352,7 @@ public function dropField($table, $field) {
}
public function fieldSetDefault($table, $field, $default) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot set default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
......@@ -367,7 +367,7 @@ public function fieldSetDefault($table, $field, $default) {
}
public function fieldSetNoDefault($table, $field) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot remove default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
......@@ -457,10 +457,10 @@ public function dropIndex($table, $name) {
}
public function changeField($table, $field, $field_new, $spec, $new_keys = array()) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot change the definition of field %table.%name: field doesn't exist.", array('%table' => $table, '%name' => $field)));
}
if (($field != $field_new) && $this->columnExists($table, $field_new)) {
if (($field != $field_new) && $this->fieldExists($table, $field_new)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot rename field %table.%name to %name_new: target field already exists.", array('%table' => $table, '%name' => $field, '%name_new' => $field_new)));
}
......
......@@ -252,7 +252,7 @@ public function findTables($table_expression) {
* @return
* TRUE if the given column exists, otherwise FALSE.
*/
public function columnExists($table, $column) {
public function fieldExists($table, $column) {
$condition = $this->buildTableNameCondition($this->connection->prefixTables('{' . $table . '}'));
$condition->condition('column_name', $column);
$condition->compile($this->connection, $this);
......
......@@ -19,7 +19,7 @@ public function tableExists($table) {
return (bool) $this->connection->query("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE '{" . $table . "}'", array(), array())->fetchField();
}
public function columnExists($table, $column) {
public function fieldExists($table, $column) {
$schema = $this->introspectSchema($table);
return !empty($schema['fields'][$column]);
}
......@@ -262,7 +262,7 @@ public function addField($table, $field, $spec, $keys_new = array()) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add field %table.%field: table doesn't exist.", array('%field' => $field, '%table' => $table)));
}
if ($this->columnExists($table, $field)) {
if ($this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot add field %table.%field: field already exists.", array('%field' => $field, '%table' => $table)));
}
......@@ -377,7 +377,7 @@ protected function introspectSchema($table) {
}
public function dropField($table, $field) {
if ($this->columnExists($table, $field)) {
if ($this->fieldExists($table, $field)) {
return FALSE;
}
......@@ -399,10 +399,10 @@ public function dropField($table, $field) {
}
public function changeField($table, $field, $field_new, $spec, $keys_new = array()) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot change the definition of field %table.%name: field doesn't exist.", array('%table' => $table, '%name' => $field)));
}
if (($field != $field_new) && $this->columnExists($table, $field_new)) {
if (($field != $field_new) && $this->fieldExists($table, $field_new)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot rename field %table.%name to %name_new: target field already exists.", array('%table' => $table, '%name' => $field, '%name_new' => $field_new)));
}
......@@ -499,7 +499,7 @@ public function dropPrimaryKey($table) {
}
public function fieldSetDefault($table, $field, $default) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot set default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
......@@ -509,7 +509,7 @@ public function fieldSetDefault($table, $field, $default) {
}
public function fieldSetNoDefault($table, $field) {
if (!$this->columnExists($table, $field)) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot remove default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
......
......@@ -2434,11 +2434,11 @@ class DatabaseRegressionTestCase extends DatabaseTestCase {
}
/**
* Test the db_column_exists() function.
* Test the db_field_exists() function.
*/
function testDBColumnExists() {
$this->assertIdentical(TRUE, db_column_exists('node', 'nid'), t('Returns true for existent column.'));
$this->assertIdentical(FALSE, db_column_exists('node', 'nosuchcolumn'), t('Returns false for nonexistent column.'));
function testDBFieldExists() {
$this->assertIdentical(TRUE, db_field_exists('node', 'nid'), t('Returns true for existent column.'));
$this->assertIdentical(FALSE, db_field_exists('node', 'nosuchcolumn'), t('Returns false for nonexistent column.'));
}
/**
......
......@@ -170,7 +170,7 @@ class SchemaTestCase extends DrupalWebTestCase {
// Finally, check each column and try to insert invalid values into them.
foreach($table_spec['fields'] as $column_name => $column_spec) {
$this->assertTrue(db_column_exists($table_name, $column_name), t('Unsigned @type column was created.', array('@type' => $column_spec['type'])));
$this->assertTrue(db_field_exists($table_name, $column_name), t('Unsigned @type column was created.', array('@type' => $column_spec['type'])));
$this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), t('Unsigned @type column rejected a negative value.', array('@type' => $column_spec['type'])));
}
}
......
......@@ -1549,7 +1549,7 @@ function system_update_6050() {
*/
function system_update_6051() {
if (!db_column_exists('users', 'signature_format')) {
if (!db_field_exists('users', 'signature_format')) {
// Set future text formats to FILTER_FORMAT_DEFAULT to ensure a safe default
// when incompatible modules insert into the users table. An actual format
......@@ -2230,7 +2230,7 @@ function system_update_7036() {
}
$insert->execute();
// Remove obsolete variable 'site_offline_message'. See
// Remove obsolete variable 'site_offline_message'. See
// update_fix_d7_requirements().
variable_del('site_offline_message');
}
......
......@@ -390,8 +390,8 @@ function user_update_7002(&$sandbox) {
$timezones = system_time_zones();
// Update this many per page load.
$count = 10000;
$contributed_date_module = db_column_exists('users', 'timezone_name');
$contributed_event_module = db_column_exists('users', 'timezone_id');
$contributed_date_module = db_field_exists('users', 'timezone_name');
$contributed_event_module = db_field_exists('users', 'timezone_id');
$results = db_query_range("SELECT uid FROM {users} ORDER BY uid", $sandbox['user_from'], $count);
foreach ($results as $account) {
......@@ -487,7 +487,7 @@ function user_update_7004(&$sandbox) {
if (!isset($sandbox['progress'])) {
// Check that the field hasn't been updated in an aborted run of this
// update.
if (!db_column_exists('users', 'picture_fid')) {
if (!db_field_exists('users', 'picture_fid')) {
// Add a new field for the fid.
db_add_field('users', 'picture_fid', $picture_field);
}
......@@ -566,7 +566,7 @@ function user_update_7006(&$sandbox) {
);
// Check that the field hasn't been updated in an aborted run of this
// update.
if (!db_column_exists('role_permission', 'module')) {
if (!db_field_exists('role_permission', 'module')) {
// Add a new field for the fid.
db_add_field('role_permission', 'module', $module_field);
}
......
Supports Markdown
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