summaryrefslogtreecommitdiffstats
path: root/core/lib
diff options
context:
space:
mode:
Diffstat (limited to 'core/lib')
-rw-r--r--core/lib/Drupal/Core/Config/Entity/Query/Query.php1
-rw-r--r--core/lib/Drupal/Core/Entity/Query/QueryBase.php22
-rw-r--r--core/lib/Drupal/Core/Entity/Query/QueryInterface.php33
-rw-r--r--core/lib/Drupal/Core/Entity/Query/Sql/Query.php14
-rw-r--r--core/lib/Drupal/Core/Entity/Query/Sql/Tables.php11
5 files changed, 42 insertions, 39 deletions
diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php
index b8660aa..2ad4db5 100644
--- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php
+++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php
@@ -8,7 +8,6 @@
namespace Drupal\Core\Config\Entity\Query;
use Drupal\Core\Config\ConfigFactoryInterface;
-use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryBase;
use Drupal\Core\Entity\Query\QueryInterface;
diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
index 4465efd..6f3d6aa 100644
--- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php
+++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
@@ -8,7 +8,6 @@
namespace Drupal\Core\Entity\Query;
use Drupal\Core\Database\Query\PagerSelectExtender;
-use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
/**
@@ -110,12 +109,9 @@ abstract class QueryBase implements QueryInterface {
/**
* Flag indicating whether to query the current revision or all revisions.
*
- * Can be either EntityStorageInterface::FIELD_LOAD_CURRENT or
- * EntityStorageInterface::FIELD_LOAD_REVISION.
- *
- * @var string
+ * @var bool
*/
- protected $age = EntityStorageInterface::FIELD_LOAD_CURRENT;
+ protected $allRevisions = FALSE;
/**
* The query pager data.
@@ -257,10 +253,18 @@ abstract class QueryBase implements QueryInterface {
}
/**
- * Implements \Drupal\Core\Entity\Query\QueryInterface::age().
+ * {@inheritdoc}
+ */
+ public function currentRevision() {
+ $this->allRevisions = FALSE;
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
*/
- public function age($age = EntityStorageInterface::FIELD_LOAD_CURRENT) {
- $this->age = $age;
+ public function allRevisions() {
+ $this->allRevisions = TRUE;
return $this;
}
diff --git a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
index 0fad28c..2ddbd5d 100644
--- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
+++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
@@ -7,7 +7,6 @@
namespace Drupal\Core\Entity\Query;
-use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Database\Query\AlterableInterface;
/**
@@ -166,24 +165,6 @@ interface QueryInterface extends AlterableInterface {
public function accessCheck($access_check = TRUE);
/**
- * Queries the current or every revision.
- *
- * Note that this only affects field conditions. Property conditions always
- * apply to the current revision.
- * @TODO: Once revision tables have been cleaned up, revisit this.
- *
- * @param $age
- * - EntityStorageInterface::FIELD_LOAD_CURRENT (default): Query
- * the most recent revisions only,
- * - EntityStorageInterface::FIELD_LOAD_REVISION: Query all
- * revisions.
- *
- * @return \Drupal\Core\Entity\Query\QueryInterface
- * The called object.
- */
- public function age($age = EntityStorageInterface::FIELD_LOAD_CURRENT);
-
- /**
* Execute the query.
*
* @return int|array
@@ -244,4 +225,18 @@ interface QueryInterface extends AlterableInterface {
*/
public function orConditionGroup();
+ /**
+ * Queries the current revision.
+ *
+ * @return $this
+ */
+ public function currentRevision();
+
+ /**
+ * Queries all the revisions.
+ *
+ * @return $this
+ */
+ public function allRevisions();
+
}
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
index cf8eb39..6269617 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
@@ -9,7 +9,6 @@ namespace Drupal\Core\Entity\Query\Sql;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\SelectInterface;
-use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryBase;
use Drupal\Core\Entity\Query\QueryException;
@@ -100,8 +99,15 @@ class Query extends QueryBase implements QueryInterface {
* Returns the called object.
*/
protected function prepare() {
- if (!$base_table = $this->entityType->getBaseTable()) {
- throw new QueryException("No base table, invalid query.");
+ if ($this->allRevisions) {
+ if (!$base_table = $this->entityType->getRevisionTable()) {
+ throw new QueryException("No revision table for " . $this->entityTypeId . ", invalid query.");
+ }
+ }
+ else {
+ if (!$base_table = $this->entityType->getBaseTable()) {
+ throw new QueryException("No base table for " . $this->entityTypeId . ", invalid query.");
+ }
}
$simple_query = TRUE;
if ($this->entityType->getDataTable()) {
@@ -146,7 +152,7 @@ class Query extends QueryBase implements QueryInterface {
}
// This now contains first the table containing entity properties and
// last the entity base table. They might be the same.
- $this->sqlQuery->addMetaData('age', $this->age);
+ $this->sqlQuery->addMetaData('all_revisions', $this->allRevisions);
$this->sqlQuery->addMetaData('simple_query', $simple_query);
return $this;
}
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
index 6e1ecf1..31925b4 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php
@@ -8,7 +8,6 @@
namespace Drupal\Core\Entity\Query\Sql;
use Drupal\Core\Database\Query\SelectInterface;
-use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
@@ -68,7 +67,7 @@ class Tables implements TablesInterface {
*/
public function addField($field, $type, $langcode) {
$entity_type_id = $this->sqlQuery->getMetaData('entity_type');
- $age = $this->sqlQuery->getMetaData('age');
+ $all_revisions = $this->sqlQuery->getMetaData('all_revisions');
// This variable ensures grouping works correctly. For example:
// ->condition('tags', 2, '>')
// ->condition('tags', 20, '<')
@@ -89,7 +88,7 @@ class Tables implements TablesInterface {
for ($key = 0; $key <= $count; $key ++) {
// If there is revision support and only the current revision is being
// queried then use the revision id. Otherwise, the entity id will do.
- if (($revision_key = $entity_type->getKey('revision')) && $age == EntityStorageInterface::FIELD_LOAD_CURRENT) {
+ if (($revision_key = $entity_type->getKey('revision')) && $all_revisions) {
// This contains the relevant SQL field to be used when joining entity
// tables.
$entity_id_field = $revision_key;
@@ -158,11 +157,11 @@ class Tables implements TablesInterface {
// finds the property first. The data table is preferred, which is why
// it gets added before the base table.
$entity_tables = array();
- if ($data_table = $entity_type->getDataTable()) {
+ if ($data_table = $all_revisions ? $entity_type->getRevisionDataTable() : $entity_type->getDataTable()) {
$this->sqlQuery->addMetaData('simple_query', FALSE);
$entity_tables[$data_table] = $this->getTableMapping($data_table, $entity_type_id);
}
- $entity_base_table = $entity_type->getBaseTable();
+ $entity_base_table = $all_revisions ? $entity_type->getRevisionTable() : $entity_type->getBaseTable();
$entity_tables[$entity_base_table] = $this->getTableMapping($entity_base_table, $entity_type_id);
$sql_column = $specifier;
@@ -265,7 +264,7 @@ class Tables implements TablesInterface {
$entity_type_id = $this->sqlQuery->getMetaData('entity_type');
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = $this->entityManager->getStorage($entity_type_id)->getTableMapping();
- $table = $this->sqlQuery->getMetaData('age') == EntityStorageInterface::FIELD_LOAD_CURRENT ? $table_mapping->getDedicatedDataTableName($field) : $table_mapping->getDedicatedRevisionTableName($field);
+ $table = !$this->sqlQuery->getMetaData('all_revisions') ? $table_mapping->getDedicatedDataTableName($field) : $table_mapping->getDedicatedRevisionTableName($field);
if ($field->getCardinality() != 1) {
$this->sqlQuery->addMetaData('simple_query', FALSE);
}