Commit 1251cc35 authored by webchick's avatar webchick
Browse files

Issue #2284111 by alexpott, Berdir, damiankloip: Fixed Exceptions caught and...

Issue #2284111 by alexpott, Berdir, damiankloip: Fixed Exceptions caught and printed from index.php should not return a 200 status code.
parent 0b891207
...@@ -39,13 +39,6 @@ ...@@ -39,13 +39,6 @@
*/ */
class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements SqlEntityStorageInterface { class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements SqlEntityStorageInterface {
/**
* The storage field definitions for this entity type.
*
* @var \Drupal\Core\Field\FieldStorageDefinitionInterface[]
*/
protected $fieldStorageDefinitions;
/** /**
* The mapping of field columns to SQL tables. * The mapping of field columns to SQL tables.
* *
...@@ -129,6 +122,17 @@ public static function createInstance(ContainerInterface $container, EntityTypeI ...@@ -129,6 +122,17 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
); );
} }
/**
* Gets the base field definitions for a content entity type.
*
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
* The array of base field definitions for the entity type, keyed by field
* name.
*/
public function getFieldStorageDefinitions() {
return $this->entityManager->getBaseFieldDefinitions($this->entityTypeId);
}
/** /**
* Constructs a ContentEntityDatabaseStorage object. * Constructs a ContentEntityDatabaseStorage object.
* *
...@@ -144,7 +148,6 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa ...@@ -144,7 +148,6 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa
$this->database = $database; $this->database = $database;
$this->entityManager = $entity_manager; $this->entityManager = $entity_manager;
$this->fieldStorageDefinitions = $entity_manager->getBaseFieldDefinitions($entity_type->id());
// @todo Remove table names from the entity type definition in // @todo Remove table names from the entity type definition in
// https://drupal.org/node/2232465 // https://drupal.org/node/2232465
...@@ -236,7 +239,7 @@ protected function schemaHandler() { ...@@ -236,7 +239,7 @@ protected function schemaHandler() {
public function getTableMapping() { public function getTableMapping() {
if (!isset($this->tableMapping)) { if (!isset($this->tableMapping)) {
$definitions = array_filter($this->fieldStorageDefinitions, function (FieldDefinitionInterface $definition) { $definitions = array_filter($this->getFieldStorageDefinitions(), function (FieldDefinitionInterface $definition) {
// @todo Remove the check for FieldDefinitionInterface::isMultiple() when // @todo Remove the check for FieldDefinitionInterface::isMultiple() when
// multiple-value base fields are supported in // multiple-value base fields are supported in
// https://drupal.org/node/2248977. // https://drupal.org/node/2248977.
...@@ -834,10 +837,10 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam ...@@ -834,10 +837,10 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam
$table_mapping = $this->getTableMapping(); $table_mapping = $this->getTableMapping();
foreach ($table_mapping->getFieldNames($table_name) as $field_name) { foreach ($table_mapping->getFieldNames($table_name) as $field_name) {
if (empty($this->fieldStorageDefinitions[$field_name])) { if (empty($this->getFieldStorageDefinitions()[$field_name])) {
throw new EntityStorageException(String::format('Table mapping contains invalid field %field.', array('%field' => $field_name))); throw new EntityStorageException(String::format('Table mapping contains invalid field %field.', array('%field' => $field_name)));
} }
$definition = $this->fieldStorageDefinitions[$field_name]; $definition = $this->getFieldStorageDefinitions()[$field_name];
$columns = $table_mapping->getColumnNames($field_name); $columns = $table_mapping->getColumnNames($field_name);
foreach ($columns as $column_name => $schema_name) { foreach ($columns as $column_name => $schema_name) {
......
...@@ -1048,7 +1048,7 @@ protected function setUpEntityStorage() { ...@@ -1048,7 +1048,7 @@ protected function setUpEntityStorage() {
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->entityManager->expects($this->once()) $this->entityManager->expects($this->any())
->method('getBaseFieldDefinitions') ->method('getBaseFieldDefinitions')
->will($this->returnValue($this->fieldDefinitions)); ->will($this->returnValue($this->fieldDefinitions));
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
$rebuild_path = $GLOBALS['base_url'] . '/rebuild.php'; $rebuild_path = $GLOBALS['base_url'] . '/rebuild.php';
$message .= " or run the <a href=\"$rebuild_path\">rebuild script</a>"; $message .= " or run the <a href=\"$rebuild_path\">rebuild script</a>";
} }
// Set the response code manually. Otherwise, this response will default to a
// 200.
http_response_code(500);
print $message; print $message;
throw $e; throw $e;
} }
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