Commit e7b2772c authored by David_Rothstein's avatar David_Rothstein

Issue #2278583 by nlisgo, Berdir, joshi.rohit100 | Fabianx: Fixed...

Issue #2278583 by nlisgo, Berdir, joshi.rohit100 | Fabianx: Fixed field_has_data looks at current data instead of revisioning data: this can lead to data loss.
parent 8cf521c6
Drupal 7.33, xxxx-xx-xx (development version)
-----------------------
- Fixed a bug in which field_has_data() did not return TRUE for fields that
only had data in older entity revisions, leading to loss of the field's data
when the field configuration was edited.
- Fixed a bug which caused the Ajax progress throbber to appear misaligned in
many situatons (minor styling change).
- Prevented the Bartik theme from lower-casing the "Permalink" link on
......
......@@ -936,14 +936,17 @@ function field_get_items($entity_type, $entity, $field_name, $langcode = NULL) {
*/
function field_has_data($field) {
$query = new EntityFieldQuery();
return (bool) $query
->fieldCondition($field)
$query = $query->fieldCondition($field)
->range(0, 1)
->count()
// Neutralize the 'entity_field_access' query tag added by
// field_sql_storage_field_storage_query(). The result cannot depend on the
// access grants of the current user.
->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT')
->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
return (bool) $query
->execute() || (bool) $query
->age(FIELD_LOAD_REVISION)
->execute();
}
......
......@@ -484,6 +484,66 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
$this->assertEqual($entity->{$this->field_name}[$langcode], $values, 'Insert: missing field results in default value saved');
}
/**
* Test field_has_data().
*/
function testFieldHasData() {
$entity_type = 'test_entity';
$langcode = LANGUAGE_NONE;
$field_name = 'field_1';
$field = array('field_name' => $field_name, 'type' => 'test_field');
$field = field_create_field($field);
$this->assertFalse(field_has_data($field), "No data should be detected.");
$instance = array(
'field_name' => $field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle'
);
$instance = field_create_instance($instance);
$table = _field_sql_storage_tablename($field);
$revision_table = _field_sql_storage_revision_tablename($field);
$columns = array('entity_type', 'entity_id', 'revision_id', 'delta', 'language', $field_name . '_value');
$eid = 0;
// Insert values into the field revision table.
$query = db_insert($revision_table)->fields($columns);
$query->values(array($entity_type, $eid, 0, 0, $langcode, 1));
$query->execute();
$this->assertTrue(field_has_data($field), "Revision data only should be detected.");
$field_name = 'field_2';
$field = array('field_name' => $field_name, 'type' => 'test_field');
$field = field_create_field($field);
$this->assertFalse(field_has_data($field), "No data should be detected.");
$instance = array(
'field_name' => $field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle'
);
$instance = field_create_instance($instance);
$table = _field_sql_storage_tablename($field);
$revision_table = _field_sql_storage_revision_tablename($field);
$columns = array('entity_type', 'entity_id', 'revision_id', 'delta', 'language', $field_name . '_value');
$eid = 1;
// Insert values into the field table.
$query = db_insert($table)->fields($columns);
$query->values(array($entity_type, $eid, 0, 0, $langcode, 1));
$query->execute();
$this->assertTrue(field_has_data($field), "Values only in field table should be detected.");
}
/**
* Test field_attach_delete().
*/
......
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