From 055aac105d8e7fa6720f1ae289aba4054de37633 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 9 Sep 2014 14:27:04 +0100 Subject: [PATCH] Issue #2332577 by Berdir: Remove EntityDatabaseStorage. --- .../Core/Entity/EntityDatabaseStorage.php | 212 ------------------ .../field_ui_test/field_ui_test.info.yml | 1 + .../src/Entity/FieldUITestNoBundle.php | 18 +- .../src/Tests/Entity/EntityApiInfoTest.php | 53 ----- .../entity_cache_test.info.yml | 8 - .../entity_cache_test.module | 24 -- .../entity_cache_test_dependency.info.yml | 6 - .../entity_cache_test_dependency.module | 14 -- .../src/Entity/EntityCacheTest.php | 25 --- 9 files changed, 7 insertions(+), 354 deletions(-) delete mode 100644 core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php delete mode 100644 core/modules/system/src/Tests/Entity/EntityApiInfoTest.php delete mode 100644 core/modules/system/tests/modules/entity_cache_test/entity_cache_test.info.yml delete mode 100644 core/modules/system/tests/modules/entity_cache_test/entity_cache_test.module delete mode 100644 core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.info.yml delete mode 100644 core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.module delete mode 100644 core/modules/system/tests/modules/entity_cache_test_dependency/src/Entity/EntityCacheTest.php diff --git a/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php deleted file mode 100644 index b55736d8e92..00000000000 --- a/core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php +++ /dev/null @@ -1,212 +0,0 @@ -get('database'), - $container->get('uuid') - ); - } - - /** - * Constructs a EntityDatabaseStorage object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Database\Connection $database - * The database connection to be used. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_service - * The UUID service. - */ - public function __construct(EntityTypeInterface $entity_type, Connection $database, UuidInterface $uuid_service) { - parent::__construct($entity_type); - - $this->database = $database; - $this->uuidService = $uuid_service; - - // Check if the entity type supports UUIDs. - $this->uuidKey = $this->entityType->getKey('uuid'); - } - - /** - * {@inheritdoc} - */ - protected function doLoadMultiple(array $ids = NULL) { - // Build and execute the query. - $records = $this - ->buildQuery($ids) - ->execute() - ->fetchAllAssoc($this->idKey, \PDO::FETCH_ASSOC); - - return $this->mapFromStorageRecords($records); - } - - /** - * {@inheritdoc} - */ - public function loadRevision($revision_id) { - throw new \Exception('Database storage does not support revisions.'); - } - - /** - * {@inheritdoc} - */ - public function deleteRevision($revision_id) { - throw new \Exception('Database storage does not support revisions.'); - } - - /** - * Builds the query to load the entity. - * - * @param array|null $ids - * An array of entity IDs, or NULL to load all entities. - * - * @return \Drupal\Core\Database\Query\Select - * A SelectQuery object for loading the entity. - */ - protected function buildQuery($ids) { - $query = $this->database->select($this->entityType->getBaseTable(), 'base'); - - $query->addTag($this->entityTypeId . '_load_multiple'); - - // Add fields from the {entity} table. - $entity_fields = drupal_schema_fields_sql($this->entityType->getBaseTable()); - $query->fields('base', $entity_fields); - - if ($ids) { - $query->condition("base.{$this->idKey}", $ids, 'IN'); - } - - return $query; - } - - /** - * {@inheritdoc} - */ - public function delete(array $entities) { - if (!$entities) { - // If no IDs or invalid IDs were passed, do nothing. - return; - } - $transaction = $this->database->startTransaction(); - - try { - parent::delete($entities); - - // Ignore replica server temporarily. - db_ignore_replica(); - } - catch (\Exception $e) { - $transaction->rollback(); - watchdog_exception($this->entityTypeId, $e); - throw new EntityStorageException($e->getMessage(), $e->getCode(), $e); - } - } - - /** - * {@inheritdoc} - */ - protected function doDelete($entities) { - $ids = array_keys($entities); - - $this->database->delete($this->entityType->getBaseTable()) - ->condition($this->idKey, $ids, 'IN') - ->execute(); - - // Reset the cache as soon as the changes have been applied. - $this->resetCache($ids); - } - - /** - * {@inheritdoc} - */ - public function save(EntityInterface $entity) { - $transaction = $this->database->startTransaction(); - try { - $return = parent::save($entity); - - // Ignore replica server temporarily. - db_ignore_replica(); - return $return; - } - catch (\Exception $e) { - $transaction->rollback(); - watchdog_exception($this->entityTypeId, $e); - throw new EntityStorageException($e->getMessage(), $e->getCode(), $e); - } - } - - /** - * {@inheritdoc} - */ - protected function doSave($id, EntityInterface $entity) { - if (!$entity->isNew()) { - $return = drupal_write_record($this->entityType->getBaseTable(), $entity, $this->idKey); - $this->resetCache(array($entity->id())); - } - else { - $return = drupal_write_record($this->entityType->getBaseTable(), $entity); - // Reset general caches, but keep caches specific to certain entities. - $this->resetCache(array()); - } - - return $return; - } - - /** - * {@inheritdoc} - */ - protected function has($id, EntityInterface $entity) { - return !$entity->isNew(); - } - - /** - * {@inheritdoc} - */ - public function getQueryServiceName() { - return 'entity.query.sql'; - } - -} diff --git a/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml index b57d967937c..9d7a5d13034 100644 --- a/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml +++ b/core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml @@ -7,3 +7,4 @@ core: 8.x dependencies: - field_ui + - entity_test diff --git a/core/modules/field_ui/tests/modules/field_ui_test/src/Entity/FieldUITestNoBundle.php b/core/modules/field_ui/tests/modules/field_ui_test/src/Entity/FieldUITestNoBundle.php index be182024437..e7b21137682 100644 --- a/core/modules/field_ui/tests/modules/field_ui_test/src/Entity/FieldUITestNoBundle.php +++ b/core/modules/field_ui/tests/modules/field_ui_test/src/Entity/FieldUITestNoBundle.php @@ -7,27 +7,21 @@ namespace Drupal\field_ui_test\Entity; -use Drupal\Core\Entity\Entity; +use Drupal\entity_test\Entity\EntityTest; /** * Defines the test Field UI class. * - * @EntityType( + * @ContentEntityType( * id = "field_ui_test_no_bundle", * label = @Translation("Test Field UI entity, no bundle"), - * handlers = { - * "storage" = "Drupal\Core\Entity\EntityDatabaseStorage" + * entity_keys = { + * "id" = "id", + * "uuid" = "uuid", * }, * fieldable = TRUE * ) */ -class FieldUITestNoBundle extends Entity { - - /** - * The entity ID. - * - * @var int - */ - public $id; +class FieldUITestNoBundle extends EntityTest { } diff --git a/core/modules/system/src/Tests/Entity/EntityApiInfoTest.php b/core/modules/system/src/Tests/Entity/EntityApiInfoTest.php deleted file mode 100644 index 8b48f9564c7..00000000000 --- a/core/modules/system/src/Tests/Entity/EntityApiInfoTest.php +++ /dev/null @@ -1,53 +0,0 @@ -install(array('entity_cache_test')); - $entity_types = \Drupal::entityManager()->getDefinitions(); - $this->assertTrue(isset($entity_types['entity_cache_test']), 'Test entity type found.'); - - // Change the label of the test entity type and make sure changes appear - // after flushing caches. - \Drupal::state()->set('entity_cache_test.label', 'New label.'); - $entity_type = \Drupal::entityManager()->getDefinition('entity_cache_test'); - $this->assertEqual($entity_type->getLabel(), 'Entity Cache Test', 'Original label appears in cached entity info.'); - $this->resetAll(); - $entity_type = \Drupal::entityManager()->getDefinition('entity_cache_test'); - $this->assertEqual($entity_type->getLabel(), 'New label.', 'New label appears in entity info.'); - - // Uninstall the providing module and make sure the entity type is gone. - $this->container->get('module_handler')->uninstall(array('entity_cache_test', 'entity_cache_test_dependency')); - $entity_types = \Drupal::entityManager()->getDefinitions(); - $this->assertFalse(isset($entity_types['entity_cache_test']), 'Entity type of the providing module is gone.'); - } - - /** - * Tests entity info cache after enabling a module with a dependency on an entity providing module. - * - * @see entity_cache_test_modules_enabled() - */ - function testEntityInfoCacheModulesEnabled() { - \Drupal::moduleHandler()->install(array('entity_cache_test')); - $entity_type = \Drupal::state()->get('entity_cache_test'); - $this->assertEqual($entity_type->getLabel(), 'Entity Cache Test', 'Entity info label is correct.'); - $this->assertEqual($entity_type->getStorageClass(), 'Drupal\Core\Entity\EntityDatabaseStorage', 'Entity handler class info is correct.'); - } -} diff --git a/core/modules/system/tests/modules/entity_cache_test/entity_cache_test.info.yml b/core/modules/system/tests/modules/entity_cache_test/entity_cache_test.info.yml deleted file mode 100644 index fa4c0fe528d..00000000000 --- a/core/modules/system/tests/modules/entity_cache_test/entity_cache_test.info.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: 'Entity cache test' -type: module -description: 'Support module for testing entity cache.' -package: Testing -version: VERSION -core: 8.x -dependencies: - - entity_cache_test_dependency diff --git a/core/modules/system/tests/modules/entity_cache_test/entity_cache_test.module b/core/modules/system/tests/modules/entity_cache_test/entity_cache_test.module deleted file mode 100644 index f91afde41fe..00000000000 --- a/core/modules/system/tests/modules/entity_cache_test/entity_cache_test.module +++ /dev/null @@ -1,24 +0,0 @@ -getDefinition('entity_cache_test'); - // Store the information in a system variable to analyze it later in the - // test case. - \Drupal::state()->set('entity_cache_test', $info); -} diff --git a/core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.info.yml b/core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.info.yml deleted file mode 100644 index 282fcb76979..00000000000 --- a/core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'Entity cache test dependency' -type: module -description: 'Support dependency module for testing entity cache.' -package: Testing -version: VERSION -core: 8.x diff --git a/core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.module b/core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.module deleted file mode 100644 index 7af346702bc..00000000000 --- a/core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.module +++ /dev/null @@ -1,14 +0,0 @@ -set('label', \Drupal::state()->get('entity_cache_test.label') ?: 'Entity Cache Test'); -} diff --git a/core/modules/system/tests/modules/entity_cache_test_dependency/src/Entity/EntityCacheTest.php b/core/modules/system/tests/modules/entity_cache_test_dependency/src/Entity/EntityCacheTest.php deleted file mode 100644 index 4c9c2438bf8..00000000000 --- a/core/modules/system/tests/modules/entity_cache_test_dependency/src/Entity/EntityCacheTest.php +++ /dev/null @@ -1,25 +0,0 @@ -