Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
055aac10
Commit
055aac10
authored
Sep 09, 2014
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2332577
by Berdir: Remove EntityDatabaseStorage.
parent
e4750a75
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
7 additions
and
354 deletions
+7
-354
core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php
core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php
+0
-212
core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml
...eld_ui/tests/modules/field_ui_test/field_ui_test.info.yml
+1
-0
core/modules/field_ui/tests/modules/field_ui_test/src/Entity/FieldUITestNoBundle.php
.../modules/field_ui_test/src/Entity/FieldUITestNoBundle.php
+6
-12
core/modules/system/src/Tests/Entity/EntityApiInfoTest.php
core/modules/system/src/Tests/Entity/EntityApiInfoTest.php
+0
-53
core/modules/system/tests/modules/entity_cache_test/entity_cache_test.info.yml
...ests/modules/entity_cache_test/entity_cache_test.info.yml
+0
-8
core/modules/system/tests/modules/entity_cache_test/entity_cache_test.module
.../tests/modules/entity_cache_test/entity_cache_test.module
+0
-24
core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.info.yml
...che_test_dependency/entity_cache_test_dependency.info.yml
+0
-6
core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.module
...cache_test_dependency/entity_cache_test_dependency.module
+0
-14
core/modules/system/tests/modules/entity_cache_test_dependency/src/Entity/EntityCacheTest.php
...tity_cache_test_dependency/src/Entity/EntityCacheTest.php
+0
-25
No files found.
core/lib/Drupal/Core/Entity/EntityDatabaseStorage.php
deleted
100644 → 0
View file @
e4750a75
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityDatabaseStorage.
*/
namespace
Drupal\Core\Entity
;
use
Drupal\Component\Uuid\UuidInterface
;
use
Drupal\Core\Database\Connection
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Defines a base entity storage class.
*
* This class only supports bare, non-content entities.
*/
class
EntityDatabaseStorage
extends
EntityStorageBase
{
/**
* The UUID service.
*
* @var \Drupal\Component\Uuid\UuidInterface
*/
protected
$uuidService
;
/**
* Whether this entity type should use the static cache.
*
* @var boolean
*/
protected
$cache
;
/**
* Active database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected
$database
;
/**
* {@inheritdoc}
*/
public
static
function
createInstance
(
ContainerInterface
$container
,
EntityTypeInterface
$entity_type
)
{
return
new
static
(
$entity_type
,
$container
->
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'
;
}
}
core/modules/field_ui/tests/modules/field_ui_test/field_ui_test.info.yml
View file @
055aac10
...
...
@@ -7,3 +7,4 @@ core: 8.x
dependencies
:
-
field_ui
-
entity_test
core/modules/field_ui/tests/modules/field_ui_test/src/Entity/FieldUITestNoBundle.php
View file @
055aac10
...
...
@@ -7,27 +7,21 @@
namespace
Drupal\field_ui_test\Entity
;
use
Drupal\
Core
\Entity\Entity
;
use
Drupal\
entity_test
\
Entity\Entity
Test
;
/**
* Defines the test Field UI class.
*
* @EntityType(
* @
Content
EntityType(
* 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
{
}
core/modules/system/src/Tests/Entity/EntityApiInfoTest.php
deleted
100644 → 0
View file @
e4750a75
<?php
/**
* @file
* Definition of Drupal\system\Tests\Entity\EntityApiInfoTest.
*/
namespace
Drupal\system\Tests\Entity
;
use
Drupal\simpletest\WebTestBase
;
/**
* Makes sure entity info is accurately cached.
*
* @group Entity
*/
class
EntityApiInfoTest
extends
WebTestBase
{
/**
* Ensures entity info cache is updated after changes.
*/
function
testEntityInfoChanges
()
{
\
Drupal
::
moduleHandler
()
->
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.'
);
}
}
core/modules/system/tests/modules/entity_cache_test/entity_cache_test.info.yml
deleted
100644 → 0
View file @
e4750a75
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
core/modules/system/tests/modules/entity_cache_test/entity_cache_test.module
deleted
100644 → 0
View file @
e4750a75
<?php
/**
* @file
* Helper module for entity cache tests.
*/
/**
* Implements hook_modules_installed().
*
* This hook is called during \Drupal\Core\Extension\ModuleHandler::install()
* and since this hook implementation is invoked, we have to expect that this
* module and dependent modules have been properly installed already. So we
* expect to be able to retrieve the entity information that has been registered
* by the required dependency module.
*
* @see EntityApiInfoTest::testEntityInfoCacheModulesEnabled()
*/
function
entity_cache_test_modules_installed
(
$modules_enabled
)
{
$info
=
\
Drupal
::
entityManager
()
->
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
);
}
core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.info.yml
deleted
100644 → 0
View file @
e4750a75
name
:
'
Entity
cache
test
dependency'
type
:
module
description
:
'
Support
dependency
module
for
testing
entity
cache.'
package
:
Testing
version
:
VERSION
core
:
8.x
core/modules/system/tests/modules/entity_cache_test_dependency/entity_cache_test_dependency.module
deleted
100644 → 0
View file @
e4750a75
<?php
/**
* @file
* Helper module for entity cache tests.
*/
/**
* Implements hook_entity_type_alter().
*/
function
entity_cache_test_dependency_entity_type_alter
(
array
&
$entity_types
)
{
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types
[
'entity_cache_test'
]
->
set
(
'label'
,
\
Drupal
::
state
()
->
get
(
'entity_cache_test.label'
)
?:
'Entity Cache Test'
);
}
core/modules/system/tests/modules/entity_cache_test_dependency/src/Entity/EntityCacheTest.php
deleted
100644 → 0
View file @
e4750a75
<?php
/**
* @file
* Contains Drupal\entity_cache_test_dependency\Entity\EntityCacheTest.
*/
namespace
Drupal\entity_cache_test_dependency\Entity
;
use
Drupal\Core\Entity\Entity
;
/**
* Defines the EntityCacheTest class.
*
* @EntityType(
* id = "entity_cache_test",
* label = @Translation("Entity cache test"),
* handlers = {
* "storage" = "Drupal\Core\Entity\EntityDatabaseStorage",
* }
* )
*/
class
EntityCacheTest
extends
Entity
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment