summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-07-08 08:38:33 (GMT)
committerAlex Pott2015-07-08 08:38:33 (GMT)
commit49f5b153a0c5d26cf55f82e912c893ed65ab677f (patch)
treed92ba9affc660679cd4b6cb4fca286d030cbffb2
parentd404b260052789f5dc7c09545e9ba3e9ee0b2be0 (diff)
Issue #2527816 by jhedstrom, pfrenssen, chx, catch: Logic error in SqlContentEntityStorage::countFieldData() attempts to drop `name` column
-rw-r--r--core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php12
-rw-r--r--core/modules/field/src/Tests/FieldDataCountTest.php24
2 files changed, 32 insertions, 4 deletions
diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
index 1942f6d..28a5afa 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
@@ -1623,9 +1623,11 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
$or->isNotNull($table_mapping->getFieldColumnName($storage_definition, $property_name));
}
$query->condition($or);
- $query
- ->fields('t', array($this->idKey))
- ->distinct(TRUE);
+ if (!$as_bool) {
+ $query
+ ->fields('t', array($this->idKey))
+ ->distinct(TRUE);
+ }
}
// @todo Find a way to count field data also for fields having custom
@@ -1635,7 +1637,9 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
// If we are performing the query just to check if the field has data
// limit the number of rows.
if ($as_bool) {
- $query->range(0, 1);
+ $query
+ ->range(0, 1)
+ ->addExpression('1');
}
else {
// Otherwise count the number of rows.
diff --git a/core/modules/field/src/Tests/FieldDataCountTest.php b/core/modules/field/src/Tests/FieldDataCountTest.php
index ebf0591..aef5e7e 100644
--- a/core/modules/field/src/Tests/FieldDataCountTest.php
+++ b/core/modules/field/src/Tests/FieldDataCountTest.php
@@ -30,6 +30,11 @@ class FieldDataCountTest extends FieldUnitTestBase {
protected $storageRev;
/**
+ * @var \Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface
+ */
+ protected $storageUser;
+
+ /**
* {@inheritdoc}
*/
protected function setUp() {
@@ -37,6 +42,7 @@ class FieldDataCountTest extends FieldUnitTestBase {
$this->installEntitySchema('entity_test_rev');
$this->storage = \Drupal::entityManager()->getStorage('entity_test');
$this->storageRev = \Drupal::entityManager()->getStorage('entity_test_rev');
+ $this->storageUser = \Drupal::entityManager()->getStorage('user');
}
/**
@@ -136,4 +142,22 @@ class FieldDataCountTest extends FieldUnitTestBase {
$this->assertEqual(count($entity->{$this->fieldTestData->field_name_2}), $cardinality, format_string('Revision %revision_id: expected number of values.', array('%revision_id' => $first_revision)));
}
+ /**
+ * Verify that we can count a table that contains an entry with index 0.
+ */
+ public function testCountWithIndex0() {
+ // Create an entry for the anonymous user, who has user ID 0.
+ $user = $this->storageUser
+ ->create(array(
+ 'uid' => 0,
+ 'name' => 'anonymous',
+ 'mail' => NULL,
+ 'status' => FALSE,
+ ));
+ $user->save();
+
+ $storage = $user->getFieldDefinition('name')->getFieldStorageDefinition();
+ $this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
+ }
+
}